Chris@0: // S5 v1.1 slides.js -- released into the Public Domain Chris@0: // Chris@0: // Please see http://www.meyerweb.com/eric/tools/s5/credits.html for information Chris@0: // about all the wonderful and talented contributors to this code! Chris@0: Chris@0: var undef; Chris@0: var slideCSS = ''; Chris@0: var snum = 0; Chris@0: var smax = 1; Chris@0: var incpos = 0; Chris@0: var number = undef; Chris@0: var s5mode = true; Chris@0: var defaultView = 'slideshow'; Chris@0: var controlVis = 'visible'; Chris@0: Chris@0: var isIE = navigator.appName == 'Microsoft Internet Explorer' ? 1 : 0; Chris@0: var isOp = navigator.userAgent.indexOf('Opera') > -1 ? 1 : 0; Chris@0: var isGe = navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('Safari') < 1 ? 1 : 0; Chris@0: Chris@0: function hasClass(object, className) { Chris@0: if (!object.className) return false; Chris@0: return (object.className.search('(^|\\s)' + className + '(\\s|$)') != -1); Chris@0: } Chris@0: Chris@0: function hasValue(object, value) { Chris@0: if (!object) return false; Chris@0: return (object.search('(^|\\s)' + value + '(\\s|$)') != -1); Chris@0: } Chris@0: Chris@0: function removeClass(object,className) { Chris@0: if (!object) return; Chris@0: object.className = object.className.replace(new RegExp('(^|\\s)'+className+'(\\s|$)'), RegExp.$1+RegExp.$2); Chris@0: } Chris@0: Chris@0: function addClass(object,className) { Chris@0: if (!object || hasClass(object, className)) return; Chris@0: if (object.className) { Chris@0: object.className += ' '+className; Chris@0: } else { Chris@0: object.className = className; Chris@0: } Chris@0: } Chris@0: Chris@0: function GetElementsWithClassName(elementName,className) { Chris@0: var allElements = document.getElementsByTagName(elementName); Chris@0: var elemColl = new Array(); Chris@0: for (var i = 0; i< allElements.length; i++) { Chris@0: if (hasClass(allElements[i], className)) { Chris@0: elemColl[elemColl.length] = allElements[i]; Chris@0: } Chris@0: } Chris@0: return elemColl; Chris@0: } Chris@0: Chris@0: function isParentOrSelf(element, id) { Chris@0: if (element == null || element.nodeName=='BODY') return false; Chris@0: else if (element.id == id) return true; Chris@0: else return isParentOrSelf(element.parentNode, id); Chris@0: } Chris@0: Chris@0: function nodeValue(node) { Chris@0: var result = ""; Chris@0: if (node.nodeType == 1) { Chris@0: var children = node.childNodes; Chris@0: for (var i = 0; i < children.length; ++i) { Chris@0: result += nodeValue(children[i]); Chris@0: } Chris@0: } Chris@0: else if (node.nodeType == 3) { Chris@0: result = node.nodeValue; Chris@0: } Chris@0: return(result); Chris@0: } Chris@0: Chris@0: function slideLabel() { Chris@0: var slideColl = GetElementsWithClassName('*','slide'); Chris@0: var list = document.getElementById('jumplist'); Chris@0: smax = slideColl.length; Chris@0: for (var n = 0; n < smax; n++) { Chris@0: var obj = slideColl[n]; Chris@0: Chris@0: var did = 'slide' + n.toString(); Chris@0: obj.setAttribute('id',did); Chris@0: if (isOp) continue; Chris@0: Chris@0: var otext = ''; Chris@0: var menu = obj.firstChild; Chris@0: if (!menu) continue; // to cope with empty slides Chris@0: while (menu && menu.nodeType == 3) { Chris@0: menu = menu.nextSibling; Chris@0: } Chris@0: if (!menu) continue; // to cope with slides with only text nodes Chris@0: Chris@0: var menunodes = menu.childNodes; Chris@0: for (var o = 0; o < menunodes.length; o++) { Chris@0: otext += nodeValue(menunodes[o]); Chris@0: } Chris@0: list.options[list.length] = new Option(n + ' : ' + otext, n); Chris@0: } Chris@0: } Chris@0: Chris@0: function currentSlide() { Chris@0: var cs; Chris@0: if (document.getElementById) { Chris@0: cs = document.getElementById('currentSlide'); Chris@0: } else { Chris@0: cs = document.currentSlide; Chris@0: } Chris@0: cs.innerHTML = '' + snum + '<\/span> ' + Chris@0: '\/<\/span> ' + Chris@0: '' + (smax-1) + '<\/span>'; Chris@0: if (snum == 0) { Chris@0: cs.style.visibility = 'hidden'; Chris@0: } else { Chris@0: cs.style.visibility = 'visible'; Chris@0: } Chris@0: } Chris@0: Chris@0: function go(step) { Chris@0: if (document.getElementById('slideProj').disabled || step == 0) return; Chris@0: var jl = document.getElementById('jumplist'); Chris@0: var cid = 'slide' + snum; Chris@0: var ce = document.getElementById(cid); Chris@0: if (incrementals[snum].length > 0) { Chris@0: for (var i = 0; i < incrementals[snum].length; i++) { Chris@0: removeClass(incrementals[snum][i], 'current'); Chris@0: removeClass(incrementals[snum][i], 'incremental'); Chris@0: } Chris@0: } Chris@0: if (step != 'j') { Chris@0: snum += step; Chris@0: lmax = smax - 1; Chris@0: if (snum > lmax) snum = lmax; Chris@0: if (snum < 0) snum = 0; Chris@0: } else Chris@0: snum = parseInt(jl.value); Chris@0: var nid = 'slide' + snum; Chris@0: var ne = document.getElementById(nid); Chris@0: if (!ne) { Chris@0: ne = document.getElementById('slide0'); Chris@0: snum = 0; Chris@0: } Chris@0: if (step < 0) {incpos = incrementals[snum].length} else {incpos = 0;} Chris@0: if (incrementals[snum].length > 0 && incpos == 0) { Chris@0: for (var i = 0; i < incrementals[snum].length; i++) { Chris@0: if (hasClass(incrementals[snum][i], 'current')) Chris@0: incpos = i + 1; Chris@0: else Chris@0: addClass(incrementals[snum][i], 'incremental'); Chris@0: } Chris@0: } Chris@0: if (incrementals[snum].length > 0 && incpos > 0) Chris@0: addClass(incrementals[snum][incpos - 1], 'current'); Chris@0: ce.style.visibility = 'hidden'; Chris@0: ne.style.visibility = 'visible'; Chris@0: jl.selectedIndex = snum; Chris@0: currentSlide(); Chris@0: number = 0; Chris@0: } Chris@0: Chris@0: function goTo(target) { Chris@0: if (target >= smax || target == snum) return; Chris@0: go(target - snum); Chris@0: } Chris@0: Chris@0: function subgo(step) { Chris@0: if (step > 0) { Chris@0: removeClass(incrementals[snum][incpos - 1],'current'); Chris@0: removeClass(incrementals[snum][incpos], 'incremental'); Chris@0: addClass(incrementals[snum][incpos],'current'); Chris@0: incpos++; Chris@0: } else { Chris@0: incpos--; Chris@0: removeClass(incrementals[snum][incpos],'current'); Chris@0: addClass(incrementals[snum][incpos], 'incremental'); Chris@0: addClass(incrementals[snum][incpos - 1],'current'); Chris@0: } Chris@0: } Chris@0: Chris@0: function toggle() { Chris@0: var slideColl = GetElementsWithClassName('*','slide'); Chris@0: var slides = document.getElementById('slideProj'); Chris@0: var outline = document.getElementById('outlineStyle'); Chris@0: if (!slides.disabled) { Chris@0: slides.disabled = true; Chris@0: outline.disabled = false; Chris@0: s5mode = false; Chris@0: fontSize('1em'); Chris@0: for (var n = 0; n < smax; n++) { Chris@0: var slide = slideColl[n]; Chris@0: slide.style.visibility = 'visible'; Chris@0: } Chris@0: } else { Chris@0: slides.disabled = false; Chris@0: outline.disabled = true; Chris@0: s5mode = true; Chris@0: fontScale(); Chris@0: for (var n = 0; n < smax; n++) { Chris@0: var slide = slideColl[n]; Chris@0: slide.style.visibility = 'hidden'; Chris@0: } Chris@0: slideColl[snum].style.visibility = 'visible'; Chris@0: } Chris@0: } Chris@0: Chris@0: function showHide(action) { Chris@0: var obj = GetElementsWithClassName('*','hideme')[0]; Chris@0: switch (action) { Chris@0: case 's': obj.style.visibility = 'visible'; break; Chris@0: case 'h': obj.style.visibility = 'hidden'; break; Chris@0: case 'k': Chris@0: if (obj.style.visibility != 'visible') { Chris@0: obj.style.visibility = 'visible'; Chris@0: } else { Chris@0: obj.style.visibility = 'hidden'; Chris@0: } Chris@0: break; Chris@0: } Chris@0: } Chris@0: Chris@0: // 'keys' code adapted from MozPoint (http://mozpoint.mozdev.org/) Chris@0: function keys(key) { Chris@0: if (!key) { Chris@0: key = event; Chris@0: key.which = key.keyCode; Chris@0: } Chris@0: if (key.which == 84) { Chris@0: toggle(); Chris@0: return; Chris@0: } Chris@0: if (s5mode) { Chris@0: switch (key.which) { Chris@0: case 10: // return Chris@0: case 13: // enter Chris@0: if (window.event && isParentOrSelf(window.event.srcElement, 'controls')) return; Chris@0: if (key.target && isParentOrSelf(key.target, 'controls')) return; Chris@0: if(number != undef) { Chris@0: goTo(number); Chris@0: break; Chris@0: } Chris@0: case 32: // spacebar Chris@0: case 34: // page down Chris@0: case 39: // rightkey Chris@0: case 40: // downkey Chris@0: if(number != undef) { Chris@0: go(number); Chris@0: } else if (!incrementals[snum] || incpos >= incrementals[snum].length) { Chris@0: go(1); Chris@0: } else { Chris@0: subgo(1); Chris@0: } Chris@0: break; Chris@0: case 33: // page up Chris@0: case 37: // leftkey Chris@0: case 38: // upkey Chris@0: if(number != undef) { Chris@0: go(-1 * number); Chris@0: } else if (!incrementals[snum] || incpos <= 0) { Chris@0: go(-1); Chris@0: } else { Chris@0: subgo(-1); Chris@0: } Chris@0: break; Chris@0: case 36: // home Chris@0: goTo(0); Chris@0: break; Chris@0: case 35: // end Chris@0: goTo(smax-1); Chris@0: break; Chris@0: case 67: // c Chris@0: showHide('k'); Chris@0: break; Chris@0: } Chris@0: if (key.which < 48 || key.which > 57) { Chris@0: number = undef; Chris@0: } else { Chris@0: if (window.event && isParentOrSelf(window.event.srcElement, 'controls')) return; Chris@0: if (key.target && isParentOrSelf(key.target, 'controls')) return; Chris@0: number = (((number != undef) ? number : 0) * 10) + (key.which - 48); Chris@0: } Chris@0: } Chris@0: return false; Chris@0: } Chris@0: Chris@0: function clicker(e) { Chris@0: number = undef; Chris@0: var target; Chris@0: if (window.event) { Chris@0: target = window.event.srcElement; Chris@0: e = window.event; Chris@0: } else target = e.target; Chris@0: if (target.getAttribute('href') != null || hasValue(target.rel, 'external') || isParentOrSelf(target, 'controls') || isParentOrSelf(target,'embed') || isParentOrSelf(target,'object')) return true; Chris@0: if (!e.which || e.which == 1) { Chris@0: if (!incrementals[snum] || incpos >= incrementals[snum].length) { Chris@0: go(1); Chris@0: } else { Chris@0: subgo(1); Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: function findSlide(hash) { Chris@0: var target = null; Chris@0: var slides = GetElementsWithClassName('*','slide'); Chris@0: for (var i = 0; i < slides.length; i++) { Chris@0: var targetSlide = slides[i]; Chris@0: if ( (targetSlide.name && targetSlide.name == hash) Chris@0: || (targetSlide.id && targetSlide.id == hash) ) { Chris@0: target = targetSlide; Chris@0: break; Chris@0: } Chris@0: } Chris@0: while(target != null && target.nodeName != 'BODY') { Chris@0: if (hasClass(target, 'slide')) { Chris@0: return parseInt(target.id.slice(5)); Chris@0: } Chris@0: target = target.parentNode; Chris@0: } Chris@0: return null; Chris@0: } Chris@0: Chris@0: function slideJump() { Chris@0: if (window.location.hash == null) return; Chris@0: var sregex = /^#slide(\d+)$/; Chris@0: var matches = sregex.exec(window.location.hash); Chris@0: var dest = null; Chris@0: if (matches != null) { Chris@0: dest = parseInt(matches[1]); Chris@0: } else { Chris@0: dest = findSlide(window.location.hash.slice(1)); Chris@0: } Chris@0: if (dest != null) Chris@0: go(dest - snum); Chris@0: } Chris@0: Chris@0: function fixLinks() { Chris@0: var thisUri = window.location.href; Chris@0: thisUri = thisUri.slice(0, thisUri.length - window.location.hash.length); Chris@0: var aelements = document.getElementsByTagName('A'); Chris@0: for (var i = 0; i < aelements.length; i++) { Chris@0: var a = aelements[i].href; Chris@0: var slideID = a.match('\#slide[0-9]{1,2}'); Chris@0: if ((slideID) && (slideID[0].slice(0,1) == '#')) { Chris@0: var dest = findSlide(slideID[0].slice(1)); Chris@0: if (dest != null) { Chris@0: if (aelements[i].addEventListener) { Chris@0: aelements[i].addEventListener("click", new Function("e", Chris@0: "if (document.getElementById('slideProj').disabled) return;" + Chris@0: "go("+dest+" - snum); " + Chris@0: "if (e.preventDefault) e.preventDefault();"), true); Chris@0: } else if (aelements[i].attachEvent) { Chris@0: aelements[i].attachEvent("onclick", new Function("", Chris@0: "if (document.getElementById('slideProj').disabled) return;" + Chris@0: "go("+dest+" - snum); " + Chris@0: "event.returnValue = false;")); Chris@0: } Chris@0: } Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: function externalLinks() { Chris@0: if (!document.getElementsByTagName) return; Chris@0: var anchors = document.getElementsByTagName('a'); Chris@0: for (var i=0; i' + Chris@0: '