/* SoundManager 2 - project home utility JS */ (function() { 'use strict'; /* global window, document, navigator, soundManager */ var IS_CHRISTMAS = (document.domain.match(/schillmania.com/i) && new Date().getMonth() === 11) || window.location.toString().match(/christmas/i); var utils; function _id(sID) { return document.getElementById(sID); } function init() { var i; var o; var el; o = document.getElementById('main'); el = o.getElementsByTagName('dt'); for (i = el.length; i--;) { if ((i + 1) % 2 === 0) { utils.addClass(el[i], 'alt'); } } el = o.getElementsByTagName('dl'); for (i = el.length; i--;) { if ((i + 1) % 2 === 0) { utils.addClass(el[i], 'alt'); } } var newCSS; if (IS_CHRISTMAS) { // overflow-x: hidden hack for homepage during christmas light season (so explosion fragments don't cause horizontal scrollbars.) newCSS = document.body.className.split(' '); newCSS.push('has-lights'); document.body.className = newCSS.join(' '); } } // so dirty. window.init = init; function Utils() { var self = this; this.hasClass = function(o, cStr) { return (typeof (o.className) !== 'undefined' ? new RegExp('(^|\\s)' + cStr + '(\\s|$)').test(o.className) : false); }; this.addClass = function(o, cStr) { if (!o || !cStr) return; // safety net if (self.hasClass(o, cStr)) return; o.className = (o.className ? o.className + ' ' : '') + cStr; }; this.removeClass = function(o, cStr) { if (!o || !cStr) return; // safety net if (!self.hasClass(o, cStr)) return; o.className = o.className.replace(new RegExp('( ' + cStr + ')|(' + cStr + ')', 'g'), ''); }; this.toggleClass = function(o, cStr) { var m = (self.hasClass(o, cStr) ? self.removeClass : self.addClass); m(o, cStr); }; this.getElementsByClassName = function(className, tagNames, oParent) { var doc = (oParent || document); var matches = []; var i, j; var nodes = []; if (typeof (tagNames) !== 'undefined' && typeof (tagNames) !== 'string') { for (i = tagNames.length; i--;) { if (!nodes || !nodes[tagNames[i]]) { nodes[tagNames[i]] = doc.getElementsByTagName(tagNames[i]); } } } else if (tagNames) { nodes = doc.getElementsByTagName(tagNames); } else { nodes = doc.all || doc.getElementsByTagName('*'); } if (typeof (tagNames) !== 'string') { for (i = tagNames.length; i--;) { for (j = nodes[tagNames[i]].length; j--;) { if (self.hasClass(nodes[tagNames[i]][j], className)) { matches[matches.length] = nodes[tagNames[i]][j]; } } } } else { for (i = 0; i < nodes.length; i++) { if (self.hasClass(nodes[i], className)) { matches[matches.length] = nodes[i]; } } } return matches; }; this.findParent = function(o) { if (!o || !o.parentNode) return false; o = o.parentNode; if (o.nodeType === 2) { while (o && o.parentNode && o.parentNode.nodeType === 2) { o = o.parentNode; } } return o; }; this.getOffY = function(o) { // http://www.xs4all.nl/~ppk/js/findpos.html var curtop = 0; if (o.offsetParent) { while (o.offsetParent) { curtop += o.offsetTop; o = o.offsetParent; } } else if (o.y) curtop += o.y; return curtop; }; this.isChildOfClass = function(oChild, oClass) { if (!oChild || !oClass) return false; while (oChild.parentNode && !self.hasClass(oChild, oClass)) { oChild = self.findParent(oChild); } return (self.hasClass(oChild, oClass)); }; this.getParentByClassName = function(oChild, sParentClassName) { if (!oChild || !sParentClassName) return false; sParentClassName = sParentClassName.toLowerCase(); while (oChild.parentNode && !self.hasClass(oChild.parentNode, sParentClassName)) { oChild = self.findParent(oChild); } return (oChild.parentNode && self.hasClass(oChild.parentNode, sParentClassName) ? oChild.parentNode : null); }; } utils = new Utils(); var lastSelected = null; function resetFilter(o) { // reset everything var oParent = null; _id('filter-box').style.display = 'none'; utils.removeClass(_id('main'), 'filtered'); var blocks = utils.getElementsByClassName('f-block', ['div', 'dl'], _id('main')); for (var i = blocks.length; i--;) { blocks[i].style.display = 'block'; oParent = utils.getParentByClassName(blocks[i], 'columnar', _id('main')); if (oParent) oParent.style.display = 'block'; } if (lastSelected) utils.removeClass(lastSelected, 'active'); if (o) lastSelected = o; return false; } // so dirty. window.resetFilter = resetFilter; function setFilter(e, sFilterPrefix) { var o = e ? e.target || e.srcElement : window.event.srcElement; utils.addClass(_id('main'), 'filtered'); var oName = o.nodeName.toLowerCase(); if (oName === 'a') { var parent = utils.findParent(o); if (parent && parent.nodeName.toLowerCase() === 'li') { // normalize to LI instead. o = parent; oName = o.nodeName.toLowerCase(); } } var sClass = ''; var blocks = utils.getElementsByClassName('f-block', ['div', 'dl'], _id('main')); var oParents = utils.getElementsByClassName('columnar', 'div', _id('main')); var oParent = null; var matchingParents = []; var i; if (oName !== 'li' || o.className === 'ignore') { return; } var isClear = (lastSelected && lastSelected === o && utils.hasClass(lastSelected, 'active')); if (oName === 'li' && isClear) { if (typeof e.preventDefault !== 'undefined') { e.preventDefault(); } resetFilter(); return; } if (oName === 'li') { // from shortcuts/filter menu var innerText = (o.getElementsByTagName('a').length ? o.getElementsByTagName('a')[0].innerHTML : o.innerHTML); // get inner text (minus link, if one is there) sClass = sFilterPrefix + innerText.substr(0, innerText.indexOf('(') !== -1 ? innerText.indexOf('(') : 999).toLowerCase().replace(/\s+/i, '-'); var last = sClass.substr(sClass.length - 1); if (last === '-' || last === ' ') { sClass = sClass.substr(0, sClass.length - 1); // IE innerHTML trailing whitespace hack (?) } for (i = blocks.length; i--;) { oParent = utils.getParentByClassName(blocks[i], 'columnar', _id('main')); if (utils.hasClass(blocks[i], sClass)) { blocks[i].style.display = 'block'; if (oParent) { matchingParents.push(oParent); } } else { blocks[i].style.display = 'none'; } } for (i = oParents.length; i--;) { oParents[i].style.display = 'none'; } for (i = matchingParents.length; i--;) { matchingParents[i].style.display = 'block'; } _id('search-results').innerHTML = '

clear filter Content filter: ' + (sFilterPrefix === 'f-' ? 'soundManager.' : (sFilterPrefix === 's-' ? '[SMSound object].' : '')) + '' + o.innerHTML + '

'; _id('search-results').style.display = 'block'; _id('filter-box').style.display = 'block'; if (isClear) { _id('filter-box').style.paddingBottom = '0px'; _id('filter-box').style.display = 'none'; } else { _id('filter-box').style.paddingBottom = '0px'; if (!navigator.userAgent.match(/msie/i)) { _id('filter-box').style.paddingBottom = Math.max(0, (document.documentElement.scrollTop || window.scrollY) - utils.getOffY(_id('filter-box')) - parseInt(_id('filter-box').offsetHeight, 10) - 20) + 'px'; } _id('filter-box').style.display = 'block'; // if ((!document.documentElement.scrollTop && !window.scrollY)) _id('filter-box').style.display = 'none'; } if (lastSelected) { if (lastSelected === o) { utils.toggleClass(lastSelected, 'active'); } else { utils.removeClass(lastSelected, 'active'); utils.addClass(o, 'active'); } } else { utils.addClass(o, 'active'); } lastSelected = o; if (typeof e.preventDefault !== 'undefined') { e.preventDefault(); } } } // so dirty. window.setFilter = setFilter; function loadScript(sURL, onLoad) { var loadScriptHandler = function() { var rs = this.readyState; if (rs === 'loaded' || rs === 'complete') { this.onreadystatechange = null; this.onload = null; window.setTimeout(onLoad, 20); } }; function scriptOnload() { this.onreadystatechange = null; this.onload = null; window.setTimeout(onLoad, 20); } var oS = document.createElement('script'); oS.type = 'text/javascript'; if (onLoad) { oS.onreadystatechange = loadScriptHandler; oS.onload = scriptOnload; } oS.src = sURL; document.getElementsByTagName('head')[0].appendChild(oS); } function getLiveData() { // Attempt to fetch data from schillmania.com: "Get Satisfaction" topics, version updates etc. loadScript('http://www.schillmania.com/services/soundmanager2/info/?version=' + soundManager.versionNumber + '&rnd=' + parseInt(Math.random() * 1048576, 10)); } function doAltShortcuts() { /* var o = _id('shortcuts-list'); if (!o) { return false; } var oParents = []; var oLIs = o.getElementsByTagName('li'); var isIgnore = null; var offset = 0; for (var i=0; i usePeakData: true, // [Flash 9 only] whether or not to show peak data (left/right channel values) - nor noticable on CPU useWaveformData: false, // [Flash 9 only] show raw waveform data - WARNING: LIKELY VERY CPU-HEAVY useEQData: false, // [Flash 9 only] show EQ (frequency spectrum) data useFavIcon: false // try to apply peakData to address bar (Firefox + Opera) - performance note: appears to make Firefox 3 do some temporary, heavy disk access/swapping/garbage collection at first(?) - may be too heavy on CPU }; window.PP_CONFIG = PP_CONFIG; window.threeSixtyPlayer.config = { playNext: false, autoPlay: false, allowMultiple: true, loadRingColor: '#ccc', playRingColor: '#000', backgroundRingColor: '#eee', circleDiameter: 256, circleRadius: 128, scaleArcWidth: 1, animDuration: 500, animTransition: window.Animator.tx.bouncy, showHMSTime: true, useWaveformData: true, waveformDataColor: '#0099ff', waveformDataDownsample: 2, waveformDataOutside: false, waveformDataConstrain: false, waveformDataLineRatio: 0.73, useEQData: true, eqDataColor: '#339933', eqDataDownsample: 2, eqDataOutside: true, eqDataLineRatio: 0.69, usePeakData: true, peakDataColor: '#ff33ff', peakDataOutside: true, peakDataLineRatio: 0.5, useAmplifier: true }; if (navigator.platform.match(/win32/i) && navigator.userAgent.match(/firefox/i)) { // extra-special homepage case (you should never see this), prevent out-of-view SWF load failure WITH high performance AND flashblock AND SWF in a placed element soundManager.useHighPerformance = false; } soundManager.onready(function() { _id('sm2-support').style.display = 'none'; _id('sm2-support-warning').style.display = 'none'; if (soundManager.didFlashBlock) { soundManager.createSound({ id: 'success', url: 'demo/_mp3/mouseover.mp3' }).play(); } doChristmasLights(); var items; // 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 var _hasFlash; var hasPlugin = false, n = navigator, nP = n.plugins, obj, type, types, AX = window.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; // if using HTML5, show some additional format support info // written while watching The Big Lebowski for the Nth time. Donny, you're out of your element! var s = soundManager; if (s.useHTML5Audio && s.hasHTML5) { var liID = 'html5-support-li'; var oldLI = document.getElementById(liID); if (oldLI) { oldLI.parentNode.removeChild(oldLI); } // what lies. not an
  • at all. ;) var li = document.createElement('div'); li.id = liID; li.className = 'html5support'; var item; items = []; var needsFlash = false; for (item in s.audioFormats) { if (s.audioFormats.hasOwnProperty(item)) { needsFlash = (soundManager.filePattern.test('.' + item)); items.push('' + (s.html5[item] ? '<' : '') + item + (s.html5[item] ? '>' : '') + ''); } } li.innerHTML = [ 'This browser\'s <HTML5> vs. Flash support:

    ', items.join(''), '
    ', '', (soundManager.html5.mp3 || soundManager.html5.mp4 ? (_hasFlash && soundManager.preferFlash ? 'Preferring flash for MP3/MP4; try preferFlash=false for HTML5-only mode.' : (soundManager.html5Only ? 'HTML5-only mode.' + (!soundManager.canPlayMIME('audio/aac') ? ' Try preferFlash=true for MP4 support as needed.' : '') : '  Some flash required; allowing HTML5 to play MP3/MP4, as supported.' + '

    ')) : 'Flash is required for this browser to play MP3/MP4.'), '' ].join(''); _id('html5-audio-notes').appendChild(li); _id('without-html5').style.display = 'inline'; } else { _id('without-html5').style.display = 'none'; } checkBadSafari(); // check inline player / HTML 5 bits items = utils.getElementsByClassName('button-exclude', 'a', _id('inline-playlist')).concat(utils.getElementsByClassName('exclude', 'a', _id('graphic-playlist'))); for (var i = 0, j = items.length; i < j; i++) { if (!soundManager.canPlayLink(items[i])) { items[i].className += ' not-supported'; items[i].title += '. \n\nNOTE: ' + (soundManager.useHTML5Audio ? 'Format apparently not supported under this configuration or browser.' : 'SoundManager 2\'s HTML5 feature is not currently enabled. (Try turning it on, see +html5 link.)'); } } }); soundManager.ontimeout(function() { // failed to load if (navigator.userAgent.match(/msie 6/i)) { // we don't care. return; } var o = _id('sm2-support'); var o2 = _id('sm2-support-warning'); var smLoadFailWarning = '

    Oh snap!

    ' + (soundManager.hasHTML5 ? 'The flash portion of ' : '') + 'SoundManager 2 was unable to start. ' + (soundManager.useHTML5Audio ? (soundManager.hasHTML5 ? '

    Some HTML5 audio support is present, but flash is needed for MP3/MP4 support on this page.' : '

    No HTML5 support was found, so flash is required.') : '') + '

    All links to audio will degrade gracefully.

    If you have a flash blocker, try allowing the SWF to run - it may be visible below.

    ' + (soundManager.useAltURL ? 'Viewing offline? You may need to change a Flash security setting.' : 'Other possible causes: Missing .SWF, or no Flash?') + ' Not to worry, as guided help is provided.

    Troubleshooting

    '; var hatesFlash = (navigator.userAgent.match(/(ipad|iphone|ipod)/i)); if (soundManager.html5.mp3 && soundManager.html5.mp4) { // flash portion was blocked, but support exists. We'll "downgrade" to HTML5-only. soundManager._wD('Special homepage case: Flash appears to blocked, HTML5 support for MP3/MP4 exists; trying HTML5-only mode...'); soundManager.useHTML5Audio = true; soundManager.preferFlash = false; setTimeout(function() { soundManager.reboot(); soundManager.onready(function() { // for when things start up in HTML5-only mode... o.innerHTML = '

    Support note

    SoundManager 2 tried to start using HTML5 + Flash, but rebooted in HTML5-only mode as flash was blocked. Visualization demo features will not be shown in this mode. To enable flash, whitelist the blocked movie and reload this page.

    ' + (soundManager.useAltURL ? '

    Running offline? Flash may be blocked due to security restrictions; see troubleshooting for more.' : '') + '

    '; o.style.marginBottom = '1.5em'; o.style.display = 'block'; }); }, 1); return; } o.innerHTML = smLoadFailWarning; o2.innerHTML = '

    SoundManager 2 could not start. See below for details.

    '; if (hatesFlash || soundManager.getMoviePercent()) { // movie loaded at least somewhat, so don't show flashblock things _id('flashblocker').style.display = 'none'; if (hatesFlash) { // none of that here. _id('flash-offline').style.display = 'none'; } } o.style.marginBottom = '1.5em'; o.style.display = 'block'; o2.style.display = 'inline-block'; }); } // side note: If it's not december but you want to smash things, try #christmas=1 in the homepage URL. // --------- /home JS ------------ function startStuff() { if (navigator.userAgent.match(/safari/i)) { document.getElementsByTagName('html')[0].className = 'isSafari'; } doVersion(); ie6Sucks(); fixLinks(); getLiveData(); doAltShortcuts(); soundManager.onready(function() { if (window.turntables) { // require this for links to play on the turntable UI demo. window.turntables.config.requireCSS = 'turntable-include'; } }); } if (document.addEventListener) { document.addEventListener('DOMContentLoaded', startStuff, false); } else { window.onload = startStuff; } }());