for UAs without console object
// allow force of debug mode via URL
if (_s.debugURLParam.test(_wl)) {
_s.debugMode = true;
}
//
if (_id(_s.debugID)) {
return false;
}
var oD, oDebug, oTarget, oToggle, tmp;
if (_s.debugMode && !_id(_s.debugID) && (!_hasConsole || !_s.useConsole || !_s.consoleOnly)) {
oD = _doc.createElement('div');
oD.id = _s.debugID + '-toggle';
oToggle = {
'position': 'fixed',
'bottom': '0px',
'right': '0px',
'width': '1.2em',
'height': '1.2em',
'lineHeight': '1.2em',
'margin': '2px',
'textAlign': 'center',
'border': '1px solid #999',
'cursor': 'pointer',
'background': '#fff',
'color': '#333',
'zIndex': 10001
};
oD.appendChild(_doc.createTextNode('-'));
oD.onclick = _toggleDebug;
oD.title = 'Toggle SM2 debug console';
if (_ua.match(/msie 6/i)) {
oD.style.position = 'absolute';
oD.style.cursor = 'hand';
}
for (tmp in oToggle) {
if (oToggle.hasOwnProperty(tmp)) {
oD.style[tmp] = oToggle[tmp];
}
}
oDebug = _doc.createElement('div');
oDebug.id = _s.debugID;
oDebug.style.display = (_s.debugMode?'block':'none');
if (_s.debugMode && !_id(oD.id)) {
try {
oTarget = _getDocument();
oTarget.appendChild(oD);
} catch(e2) {
throw new Error(_str('domError')+' \n'+e2.toString());
}
oTarget.appendChild(oDebug);
}
}
oTarget = null;
//
};
_idCheck = this.getSoundById;
//
_wDS = function(o, errorLevel) {
if (!o) {
return '';
} else {
return _s._wD(_str(o), errorLevel);
}
};
// last-resort debugging option
if (_wl.indexOf('sm2-debug=alert') + 1 && _s.debugMode) {
_s._wD = function(sText) {window.alert(sText);};
}
_toggleDebug = function() {
var o = _id(_s.debugID),
oT = _id(_s.debugID + '-toggle');
if (!o) {
return false;
}
if (_debugOpen) {
// minimize
oT.innerHTML = '+';
o.style.display = 'none';
} else {
oT.innerHTML = '-';
o.style.display = 'block';
}
_debugOpen = !_debugOpen;
};
_debugTS = function(sEventType, bSuccess, sMessage) {
// troubleshooter debug hooks
if (typeof sm2Debugger !== 'undefined') {
try {
sm2Debugger.handleEvent(sEventType, bSuccess, sMessage);
} catch(e) {
// oh well
}
}
return true;
};
//
_getSWFCSS = function() {
var css = [];
if (_s.debugMode) {
css.push(_swfCSS.sm2Debug);
}
if (_s.debugFlash) {
css.push(_swfCSS.flashDebug);
}
if (_s.useHighPerformance) {
css.push(_swfCSS.highPerf);
}
return css.join(' ');
};
_flashBlockHandler = function() {
// *possible* flash block situation.
var name = _str('fbHandler'),
p = _s.getMoviePercent(),
css = _swfCSS,
error = {type:'FLASHBLOCK'};
if (_s.html5Only) {
return false;
}
if (!_s.ok()) {
if (_needsFlash) {
// make the movie more visible, so user can fix
_s.oMC.className = _getSWFCSS() + ' ' + css.swfDefault + ' ' + (p === null?css.swfTimedout:css.swfError);
_s._wD(name+': '+_str('fbTimeout')+(p?' ('+_str('fbLoaded')+')':''));
}
_s.didFlashBlock = true;
// fire onready(), complain lightly
_processOnEvents({type:'ontimeout', ignoreInit:true, error:error});
_catchError(error);
} else {
// SM2 loaded OK (or recovered)
//
if (_s.didFlashBlock) {
_s._wD(name+': Unblocked');
}
//
if (_s.oMC) {
_s.oMC.className = [_getSWFCSS(), css.swfDefault, css.swfLoaded + (_s.didFlashBlock?' '+css.swfUnblocked:'')].join(' ');
}
}
};
_addOnEvent = function(sType, oMethod, oScope) {
if (typeof _on_queue[sType] === 'undefined') {
_on_queue[sType] = [];
}
_on_queue[sType].push({
'method': oMethod,
'scope': (oScope || null),
'fired': false
});
};
_processOnEvents = function(oOptions) {
// assume onready, if unspecified
if (!oOptions) {
oOptions = {
type: 'onready'
};
}
if (!_didInit && oOptions && !oOptions.ignoreInit) {
// not ready yet.
return false;
}
if (oOptions.type === 'ontimeout' && _s.ok()) {
// invalid case
return false;
}
var status = {
success: (oOptions && oOptions.ignoreInit?_s.ok():!_disabled)
},
// queue specified by type, or none
srcQueue = (oOptions && oOptions.type?_on_queue[oOptions.type]||[]:[]),
queue = [], i, j,
args = [status],
canRetry = (_needsFlash && _s.useFlashBlock && !_s.ok());
if (oOptions.error) {
args[0].error = oOptions.error;
}
for (i = 0, j = srcQueue.length; i < j; i++) {
if (srcQueue[i].fired !== true) {
queue.push(srcQueue[i]);
}
}
if (queue.length) {
_s._wD(_sm + ': Firing ' + queue.length + ' '+oOptions.type+'() item' + (queue.length === 1?'':'s'));
for (i = 0, j = queue.length; i < j; i++) {
if (queue[i].scope) {
queue[i].method.apply(queue[i].scope, args);
} else {
queue[i].method.apply(this, args);
}
if (!canRetry) {
// flashblock case doesn't count here
queue[i].fired = true;
}
}
}
return true;
};
_initUserOnload = function() {
_win.setTimeout(function() {
if (_s.useFlashBlock) {
_flashBlockHandler();
}
_processOnEvents();
// call user-defined "onload", scoped to window
if (_s.onload instanceof Function) {
_wDS('onload', 1);
_s.onload.apply(_win);
_wDS('onloadOK', 1);
}
if (_s.waitForWindowLoad) {
_event.add(_win, 'load', _initUserOnload);
}
},1);
};
_detectFlash = function() {
// hat tip: Flash Detect library (BSD, (C) 2007) by Carl "DocYes" S. Yestrau - http://featureblend.com/javascript-flash-detection-library.html / http://featureblend.com/license.txt
if (_hasFlash !== undefined) {
// this work has already been done.
return _hasFlash;
}
var hasPlugin = false, n = navigator, nP = n.plugins, obj, type, types, AX = _win.ActiveXObject;
if (nP && nP.length) {
type = 'application/x-shockwave-flash';
types = n.mimeTypes;
if (types && types[type] && types[type].enabledPlugin && types[type].enabledPlugin.description) {
hasPlugin = true;
}
} else if (typeof AX !== 'undefined') {
try {
obj = new AX('ShockwaveFlash.ShockwaveFlash');
} catch(e) {
// oh well
}
hasPlugin = (!!obj);
}
_hasFlash = hasPlugin;
return hasPlugin;
};
_featureCheck = function() {
var needsFlash, item,
// iPhone <= 3.1 has broken HTML5 audio(), but firmware 3.2 (iPad) + iOS4 works.
isSpecial = (_is_iDevice && !!(_ua.match(/os (1|2|3_0|3_1)/i)));
if (isSpecial) {
// has Audio(), but is broken; let it load links directly.
_s.hasHTML5 = false;
// ignore flash case, however
_s.html5Only = true;
if (_s.oMC) {
_s.oMC.style.display = 'none';
}
return false;
}
if (_s.useHTML5Audio) {
if (!_s.html5 || !_s.html5.canPlayType) {
_s._wD('SoundManager: No HTML5 Audio() support detected.');
_s.hasHTML5 = false;
return true;
} else {
_s.hasHTML5 = true;
}
if (_isBadSafari) {
_s._wD(_smc+'Note: Buggy HTML5 Audio in Safari on this OS X release, see https://bugs.webkit.org/show_bug.cgi?id=32159 - '+(!_hasFlash?' would use flash fallback for MP3/MP4, but none detected.':'will use flash fallback for MP3/MP4, if available'),1);
if (_detectFlash()) {
return true;
}
}
} else {
// flash needed (or, HTML5 needs enabling.)
return true;
}
for (item in _s.audioFormats) {
if (_s.audioFormats.hasOwnProperty(item)) {
if ((_s.audioFormats[item].required && !_s.html5.canPlayType(_s.audioFormats[item].type)) || _s.flash[item] || _s.flash[_s.audioFormats[item].type]) {
// flash may be required, or preferred for this format
needsFlash = true;
}
}
}
// sanity check..
if (_s.ignoreFlash) {
needsFlash = false;
}
_s.html5Only = (_s.hasHTML5 && _s.useHTML5Audio && !needsFlash);
return (!_s.html5Only);
};
_parseURL = function(url) {
/**
* Internal: Finds and returns the first playable URL (or failing that, the first URL.)
* @param {string or array} url A single URL string, OR, an array of URL strings or {url:'/path/to/resource', type:'audio/mp3'} objects.
*/
var i, j, result = 0;
if (url instanceof Array) {
// find the first good one
for (i=0, j=url.length; i
= 0; i--) {
if (_s.sounds[_s.soundIDs[i]].isHTML5 && _s.sounds[_s.soundIDs[i]]._hasTimer) {
_s.sounds[_s.soundIDs[i]]._onTimer();
}
}
};
_catchError = function(options) {
options = (typeof options !== 'undefined' ? options : {});
if (_s.onerror instanceof Function) {
_s.onerror.apply(_win, [{type:(typeof options.type !== 'undefined' ? options.type : null)}]);
}
if (typeof options.fatal !== 'undefined' && options.fatal) {
_s.disable();
}
};
_badSafariFix = function() {
// special case: "bad" Safari (OS X 10.3 - 10.7) must fall back to flash for MP3/MP4
if (!_isBadSafari || !_detectFlash()) {
// doesn't apply
return false;
}
var aF = _s.audioFormats, i, item;
for (item in aF) {
if (aF.hasOwnProperty(item)) {
if (item === 'mp3' || item === 'mp4') {
_s._wD(_sm+': Using flash fallback for '+item+' format');
_s.html5[item] = false;
// assign result to related formats, too
if (aF[item] && aF[item].related) {
for (i = aF[item].related.length-1; i >= 0; i--) {
_s.html5[aF[item].related[i]] = false;
}
}
}
}
}
};
/**
* Pseudo-private flash/ExternalInterface methods
* ----------------------------------------------
*/
this._setSandboxType = function(sandboxType) {
//
var sb = _s.sandbox;
sb.type = sandboxType;
sb.description = sb.types[(typeof sb.types[sandboxType] !== 'undefined'?sandboxType:'unknown')];
_s._wD('Flash security sandbox type: ' + sb.type);
if (sb.type === 'localWithFile') {
sb.noRemote = true;
sb.noLocal = false;
_wDS('secNote', 2);
} else if (sb.type === 'localWithNetwork') {
sb.noRemote = false;
sb.noLocal = true;
} else if (sb.type === 'localTrusted') {
sb.noRemote = false;
sb.noLocal = false;
}
//
};
this._externalInterfaceOK = function(flashDate, swfVersion) {
// flash callback confirming flash loaded, EI working etc.
// flashDate = approx. timing/delay info for JS/flash bridge
// swfVersion: SWF build string
if (_s.swfLoaded) {
return false;
}
var e, eiTime = new Date().getTime();
_s._wD(_smc+'externalInterfaceOK()' + (flashDate?' (~' + (eiTime - flashDate) + ' ms)':''));
_debugTS('swf', true);
_debugTS('flashtojs', true);
_s.swfLoaded = true;
_tryInitOnFocus = false;
if (_isBadSafari) {
_badSafariFix();
}
// complain if JS + SWF build/version strings don't match, excluding +DEV builds
//
if (!swfVersion || swfVersion.replace(/\+dev/i,'') !== _s.versionNumber.replace(/\+dev/i, '')) {
e = _sm + ': Fatal: JavaScript file build "' + _s.versionNumber + '" does not match Flash SWF build "' + swfVersion + '" at ' + _s.url + '. Ensure both are up-to-date.';
// escape flash -> JS stack so this error fires in window.
setTimeout(function versionMismatch() {
throw new Error(e);
}, 0);
// exit, init will fail with timeout
return false;
}
//
if (_isIE) {
// IE needs a timeout OR delay until window.onload - may need TODO: investigating
setTimeout(_init, 100);
} else {
_init();
}
};
/**
* Private initialization helpers
* ------------------------------
*/
_createMovie = function(smID, smURL) {
if (_didAppend && _appendSuccess) {
// ignore if already succeeded
return false;
}
function _initMsg() {
_s._wD('-- SoundManager 2 ' + _s.version + (!_s.html5Only && _s.useHTML5Audio?(_s.hasHTML5?' + HTML5 audio':', no HTML5 audio support'):'') + (!_s.html5Only ? (_s.useHighPerformance?', high performance mode, ':', ') + (( _s.flashPollingInterval ? 'custom (' + _s.flashPollingInterval + 'ms)' : 'normal') + ' polling') + (_s.wmode?', wmode: ' + _s.wmode:'') + (_s.debugFlash?', flash debug mode':'') + (_s.useFlashBlock?', flashBlock mode':'') : '') + ' --', 1);
}
if (_s.html5Only) {
// 100% HTML5 mode
_setVersionInfo();
_initMsg();
_s.oMC = _id(_s.movieID);
_init();
// prevent multiple init attempts
_didAppend = true;
_appendSuccess = true;
return false;
}
// flash path
var remoteURL = (smURL || _s.url),
localURL = (_s.altURL || remoteURL),
swfTitle = 'JS/Flash audio component (SoundManager 2)',
oEmbed, oMovie, oTarget = _getDocument(), tmp, movieHTML, oEl, extraClass = _getSWFCSS(),
s, x, sClass, side = null, isRTL = null,
html = _doc.getElementsByTagName('html')[0];
isRTL = (html && html.dir && html.dir.match(/rtl/i));
smID = (typeof smID === 'undefined'?_s.id:smID);
function param(name, value) {
return '';
}
// safety check for legacy (change to Flash 9 URL)
_setVersionInfo();
_s.url = _normalizeMovieURL(_overHTTP?remoteURL:localURL);
smURL = _s.url;
_s.wmode = (!_s.wmode && _s.useHighPerformance ? 'transparent' : _s.wmode);
if (_s.wmode !== null && (_ua.match(/msie 8/i) || (!_isIE && !_s.useHighPerformance)) && navigator.platform.match(/win32|win64/i)) {
/**
* extra-special case: movie doesn't load until scrolled into view when using wmode = anything but 'window' here
* does not apply when using high performance (position:fixed means on-screen), OR infinite flash load timeout
* wmode breaks IE 8 on Vista + Win7 too in some cases, as of January 2011 (?)
*/
_wDS('spcWmode');
_s.wmode = null;
}
oEmbed = {
'name': smID,
'id': smID,
'src': smURL,
'quality': 'high',
'allowScriptAccess': _s.allowScriptAccess,
'bgcolor': _s.bgColor,
'pluginspage': _http+'www.macromedia.com/go/getflashplayer',
'title': swfTitle,
'type': 'application/x-shockwave-flash',
'wmode': _s.wmode,
// http://help.adobe.com/en_US/as3/mobile/WS4bebcd66a74275c36cfb8137124318eebc6-7ffd.html
'hasPriority': 'true'
};
if (side !== null) {
// don't specify width/height if null.
oEmbed.width = side;
oEmbed.height = side;
}
if (_s.debugFlash) {
oEmbed.FlashVars = 'debug=1';
}
if (!_s.wmode) {
// don't write empty attribute
delete oEmbed.wmode;
}
if (_isIE) {
// IE is "special".
oMovie = _doc.createElement('div');
movieHTML = [
''
].join('');
} else {
oMovie = _doc.createElement('embed');
for (tmp in oEmbed) {
if (oEmbed.hasOwnProperty(tmp)) {
oMovie.setAttribute(tmp, oEmbed[tmp]);
}
}
}
_initDebug();
extraClass = _getSWFCSS();
oTarget = _getDocument();
if (oTarget) {
_s.oMC = (_id(_s.movieID) || _doc.createElement('div'));
if (!_s.oMC.id) {
_s.oMC.id = _s.movieID;
_s.oMC.className = _swfCSS.swfDefault + ' ' + extraClass;
s = null;
oEl = null;
if (!_s.useFlashBlock) {
if (_s.useHighPerformance) {
// on-screen at all times
s = {
'position': 'fixed',
'width': '8px',
'height': '8px',
// >= 6px for flash to run fast, >= 8px to start up under Firefox/win32 in some cases. odd? yes.
'bottom': '0px',
'left': '0px',
'overflow': 'hidden'
};
} else {
// hide off-screen, lower priority
s = {
'position': 'absolute',
'width': '6px',
'height': '6px',
'top': '-9999px',
'left': '-9999px'
};
if (isRTL) {
s.left = Math.abs(parseInt(s.left,10))+'px';
}
}
}
if (_isWebkit) {
// soundcloud-reported render/crash fix, safari 5
_s.oMC.style.zIndex = 10000;
}
if (!_s.debugFlash) {
for (x in s) {
if (s.hasOwnProperty(x)) {
_s.oMC.style[x] = s[x];
}
}
}
try {
if (!_isIE) {
_s.oMC.appendChild(oMovie);
}
oTarget.appendChild(_s.oMC);
if (_isIE) {
oEl = _s.oMC.appendChild(_doc.createElement('div'));
oEl.className = _swfCSS.swfBox;
oEl.innerHTML = movieHTML;
}
_appendSuccess = true;
} catch(e) {
throw new Error(_str('domError')+' \n'+e.toString());
}
} else {
// SM2 container is already in the document (eg. flashblock use case)
sClass = _s.oMC.className;
_s.oMC.className = (sClass?sClass+' ':_swfCSS.swfDefault) + (extraClass?' '+extraClass:'');
_s.oMC.appendChild(oMovie);
if (_isIE) {
oEl = _s.oMC.appendChild(_doc.createElement('div'));
oEl.className = _swfCSS.swfBox;
oEl.innerHTML = movieHTML;
}
_appendSuccess = true;
}
}
_didAppend = true;
_initMsg();
_s._wD(_smc+'createMovie(): Trying to load ' + smURL + (!_overHTTP && _s.altURL?' (alternate URL)':''), 1);
return true;
};
_initMovie = function() {
if (_s.html5Only) {
_createMovie();
return false;
}
// attempt to get, or create, movie
// may already exist
if (_flash) {
return false;
}
// inline markup case
_flash = _s.getMovie(_s.id);
if (!_flash) {
if (!_oRemoved) {
// try to create
_createMovie(_s.id, _s.url);
} else {
// try to re-append removed movie after reboot()
if (!_isIE) {
_s.oMC.appendChild(_oRemoved);
} else {
_s.oMC.innerHTML = _oRemovedHTML;
}
_oRemoved = null;
_didAppend = true;
}
_flash = _s.getMovie(_s.id);
}
//
if (_flash) {
_wDS('waitEI');
}
//
if (_s.oninitmovie instanceof Function) {
setTimeout(_s.oninitmovie, 1);
}
return true;
};
_delayWaitForEI = function() {
setTimeout(_waitForEI, 1000);
};
_waitForEI = function() {
if (_waitingForEI) {
return false;
}
_waitingForEI = true;
_event.remove(_win, 'load', _delayWaitForEI);
if (_tryInitOnFocus && !_isFocused) {
// giant Safari 3.1 hack - assume mousemove = focus given lack of focus event
_wDS('waitFocus');
return false;
}
var p;
if (!_didInit) {
p = _s.getMoviePercent();
_s._wD(_str('waitImpatient', (p === 100?' (SWF loaded)':(p > 0?' (SWF ' + p + '% loaded)':''))));
}
setTimeout(function() {
p = _s.getMoviePercent();
//
if (!_didInit) {
_s._wD(_sm + ': No Flash response within expected time.\nLikely causes: ' + (p === 0?'Loading ' + _s.movieURL + ' may have failed (and/or Flash ' + _fV + '+ not present?), ':'') + 'Flash blocked or JS-Flash security error.' + (_s.debugFlash?' ' + _str('checkSWF'):''), 2);
if (!_overHTTP && p) {
_wDS('localFail', 2);
if (!_s.debugFlash) {
_wDS('tryDebug', 2);
}
}
if (p === 0) {
// if 0 (not null), probably a 404.
_s._wD(_str('swf404', _s.url));
}
_debugTS('flashtojs', false, ': Timed out' + _overHTTP?' (Check flash security or flash blockers)':' (No plugin/missing SWF?)');
}
//
// give up / time-out, depending
if (!_didInit && _okToDisable) {
if (p === null) {
// SWF failed. Maybe blocked.
if (_s.useFlashBlock || _s.flashLoadTimeout === 0) {
if (_s.useFlashBlock) {
_flashBlockHandler();
}
_wDS('waitForever');
} else {
// old SM2 behaviour, simply fail
_failSafely(true);
}
} else {
// flash loaded? Shouldn't be a blocking issue, then.
if (_s.flashLoadTimeout === 0) {
_wDS('waitForever');
} else {
_failSafely(true);
}
}
}
}, _s.flashLoadTimeout);
};
_handleFocus = function() {
function cleanup() {
_event.remove(_win, 'focus', _handleFocus);
_event.remove(_win, 'load', _handleFocus);
}
if (_isFocused || !_tryInitOnFocus) {
cleanup();
return true;
}
_okToDisable = true;
_isFocused = true;
_s._wD(_smc+'handleFocus()');
if (_isSafari && _tryInitOnFocus) {
_event.remove(_win, 'mousemove', _handleFocus);
}
// allow init to restart
_waitingForEI = false;
cleanup();
return true;
};
_showSupport = function() {
var item, tests = [];
if (_s.useHTML5Audio && _s.hasHTML5) {
for (item in _s.audioFormats) {
if (_s.audioFormats.hasOwnProperty(item)) {
tests.push(item + ': ' + _s.html5[item] + (!_s.html5[item] && _hasFlash && _s.flash[item] ? ' (using flash)' : (_s.preferFlash && _s.flash[item] && _hasFlash ? ' (preferring flash)': (!_s.html5[item] ? ' (' + (_s.audioFormats[item].required ? 'required, ':'') + 'and no flash support)' : ''))));
}
}
_s._wD('-- SoundManager 2: HTML5 support tests ('+_s.html5Test+'): '+tests.join(', ')+' --',1);
}
};
_initComplete = function(bNoDisable) {
if (_didInit) {
return false;
}
if (_s.html5Only) {
// all good.
_s._wD('-- SoundManager 2: loaded --');
_didInit = true;
_initUserOnload();
_debugTS('onload', true);
return true;
}
var wasTimeout = (_s.useFlashBlock && _s.flashLoadTimeout && !_s.getMoviePercent()),
error;
if (!wasTimeout) {
_didInit = true;
if (_disabled) {
error = {type: (!_hasFlash && _needsFlash ? 'NO_FLASH' : 'INIT_TIMEOUT')};
}
}
_s._wD('-- SoundManager 2 ' + (_disabled?'failed to load':'loaded') + ' (' + (_disabled?'security/load error':'OK') + ') --', 1);
if (_disabled || bNoDisable) {
if (_s.useFlashBlock && _s.oMC) {
_s.oMC.className = _getSWFCSS() + ' ' + (_s.getMoviePercent() === null?_swfCSS.swfTimedout:_swfCSS.swfError);
}
_processOnEvents({type:'ontimeout', error:error});
_debugTS('onload', false);
_catchError(error);
return false;
} else {
_debugTS('onload', true);
}
if (_s.waitForWindowLoad && !_windowLoaded) {
_wDS('waitOnload');
_event.add(_win, 'load', _initUserOnload);
return false;
} else {
//
if (_s.waitForWindowLoad && _windowLoaded) {
_wDS('docLoaded');
}
//
_initUserOnload();
}
return true;
};
_init = function() {
_wDS('init');
// called after onload()
if (_didInit) {
_wDS('didInit');
return false;
}
function _cleanup() {
_event.remove(_win, 'load', _s.beginDelayedInit);
}
if (_s.html5Only) {
if (!_didInit) {
// we don't need no steenking flash!
_cleanup();
_s.enabled = true;
_initComplete();
}
return true;
}
// flash path
_initMovie();
try {
_wDS('flashJS');
// attempt to talk to Flash
_flash._externalInterfaceTest(false);
// apply user-specified polling interval, OR, if "high performance" set, faster vs. default polling
// (determines frequency of whileloading/whileplaying callbacks, effectively driving UI framerates)
_setPolling(true, (_s.flashPollingInterval || (_s.useHighPerformance ? 10 : 50)));
if (!_s.debugMode) {
// stop the SWF from making debug output calls to JS
_flash._disableDebug();
}
_s.enabled = true;
_debugTS('jstoflash', true);
if (!_s.html5Only) {
// prevent browser from showing cached page state (or rather, restoring "suspended" page state) via back button, because flash may be dead
// http://www.webkit.org/blog/516/webkit-page-cache-ii-the-unload-event/
_event.add(_win, 'unload', _doNothing);
}
} catch(e) {
_s._wD('js/flash exception: ' + e.toString());
_debugTS('jstoflash', false);
_catchError({type:'JS_TO_FLASH_EXCEPTION', fatal:true});
// don't disable, for reboot()
_failSafely(true);
_initComplete();
return false;
}
_initComplete();
// disconnect events
_cleanup();
return true;
};
_domContentLoaded = function() {
if (_didDCLoaded) {
return false;
}
_didDCLoaded = true;
_initDebug();
/**
* Temporary feature: allow force of HTML5 via URL params: sm2-usehtml5audio=0 or 1
* Ditto for sm2-preferFlash, too.
*/
//
(function(){
var a = 'sm2-usehtml5audio=', l = _wl.toLowerCase(), b = null,
a2 = 'sm2-preferflash=', b2 = null, hasCon = (typeof console !== 'undefined' && typeof console.log !== 'undefined');
if (l.indexOf(a) !== -1) {
b = (l.charAt(l.indexOf(a)+a.length) === '1');
if (hasCon) {
console.log((b?'Enabling ':'Disabling ')+'useHTML5Audio via URL parameter');
}
_s.useHTML5Audio = b;
}
if (l.indexOf(a2) !== -1) {
b2 = (l.charAt(l.indexOf(a2)+a2.length) === '1');
if (hasCon) {
console.log((b2?'Enabling ':'Disabling ')+'preferFlash via URL parameter');
}
_s.preferFlash = b2;
}
}());
//
if (!_hasFlash && _s.hasHTML5) {
_s._wD('SoundManager: No Flash detected'+(!_s.useHTML5Audio?', enabling HTML5.':'. Trying HTML5-only mode.'));
_s.useHTML5Audio = true;
// make sure we aren't preferring flash, either
// TODO: preferFlash should not matter if flash is not installed. Currently, stuff breaks without the below tweak.
_s.preferFlash = false;
}
_testHTML5();
_s.html5.usingFlash = _featureCheck();
_needsFlash = _s.html5.usingFlash;
_showSupport();
if (!_hasFlash && _needsFlash) {
_s._wD('SoundManager: Fatal error: Flash is needed to play some required formats, but is not available.');
// TODO: Fatal here vs. timeout approach, etc.
// hack: fail sooner.
_s.flashLoadTimeout = 1;
}
if (_doc.removeEventListener) {
_doc.removeEventListener('DOMContentLoaded', _domContentLoaded, false);
}
_initMovie();
return true;
};
_domContentLoadedIE = function() {
if (_doc.readyState === 'complete') {
_domContentLoaded();
_doc.detachEvent('onreadystatechange', _domContentLoadedIE);
}
return true;
};
_winOnLoad = function() {
// catch edge case of _initComplete() firing after window.load()
_windowLoaded = true;
_event.remove(_win, 'load', _winOnLoad);
};
// sniff up-front
_detectFlash();
// focus and window load, init (primarily flash-driven)
_event.add(_win, 'focus', _handleFocus);
_event.add(_win, 'load', _handleFocus);
_event.add(_win, 'load', _delayWaitForEI);
_event.add(_win, 'load', _winOnLoad);
if (_isSafari && _tryInitOnFocus) {
// massive Safari 3.1 focus detection hack
_event.add(_win, 'mousemove', _handleFocus);
}
if (_doc.addEventListener) {
_doc.addEventListener('DOMContentLoaded', _domContentLoaded, false);
} else if (_doc.attachEvent) {
_doc.attachEvent('onreadystatechange', _domContentLoadedIE);
} else {
// no add/attachevent support - safe to assume no JS -> Flash either
_debugTS('onload', false);
_catchError({type:'NO_DOM2_EVENTS', fatal:true});
}
if (_doc.readyState === 'complete') {
// DOMReady has already happened.
setTimeout(_domContentLoaded,100);
}
} // SoundManager()
// SM2_DEFER details: http://www.schillmania.com/projects/soundmanager2/doc/getstarted/#lazy-loading
if (typeof SM2_DEFER === 'undefined' || !SM2_DEFER) {
soundManager = new SoundManager();
}
/**
* SoundManager public interfaces
* ------------------------------
*/
window.SoundManager = SoundManager; // constructor
window.soundManager = soundManager; // public API, flash callbacks etc.
}(window));