1 // S5 v1.1 slides.js -- released into the Public Domain
2 // Modified for Docutils (http://docutils.sf.net) by David Goodger
4 // Please see http://www.meyerweb.com/eric/tools/s5/credits.html for
5 // information about all the wonderful and talented contributors to this code!
11 var slideIDs = new Array();
15 var defaultView = 'slideshow';
16 var controlVis = 'visible';
18 var isIE = navigator.appName == 'Microsoft Internet Explorer' ? 1 : 0;
19 var isOp = navigator.userAgent.indexOf('Opera') > -1 ? 1 : 0;
20 var isGe = navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('Safari') < 1 ? 1 : 0;
22 function hasClass(object, className) {
23 if (!object.className) return false;
24 return (object.className.search('(^|\\s)' + className + '(\\s|$)') != -1);
27 function hasValue(object, value) {
28 if (!object) return false;
29 return (object.search('(^|\\s)' + value + '(\\s|$)') != -1);
32 function removeClass(object,className) {
34 object.className = object.className.replace(new RegExp('(^|\\s)'+className+'(\\s|$)'), RegExp.$1+RegExp.$2);
37 function addClass(object,className) {
38 if (!object || hasClass(object, className)) return;
39 if (object.className) {
40 object.className += ' '+className;
42 object.className = className;
46 function GetElementsWithClassName(elementName,className) {
47 var allElements = document.getElementsByTagName(elementName);
48 var elemColl = new Array();
49 for (var i = 0; i< allElements.length; i++) {
50 if (hasClass(allElements[i], className)) {
51 elemColl[elemColl.length] = allElements[i];
57 function isParentOrSelf(element, id) {
58 if (element == null || element.nodeName=='BODY') return false;
59 else if (element.id == id) return true;
60 else return isParentOrSelf(element.parentNode, id);
63 function nodeValue(node) {
65 if (node.nodeType == 1) {
66 var children = node.childNodes;
67 for (var i = 0; i < children.length; ++i) {
68 result += nodeValue(children[i]);
71 else if (node.nodeType == 3) {
72 result = node.nodeValue;
77 function slideLabel() {
78 var slideColl = GetElementsWithClassName('*','slide');
79 var list = document.getElementById('jumplist');
80 smax = slideColl.length;
81 for (var n = 0; n < smax; n++) {
82 var obj = slideColl[n];
84 var did = 'slide' + n.toString();
85 if (obj.getAttribute('id')) {
86 slideIDs[n] = obj.getAttribute('id');
89 obj.setAttribute('id',did);
95 var menu = obj.firstChild;
96 if (!menu) continue; // to cope with empty slides
97 while (menu && menu.nodeType == 3) {
98 menu = menu.nextSibling;
100 if (!menu) continue; // to cope with slides with only text nodes
102 var menunodes = menu.childNodes;
103 for (var o = 0; o < menunodes.length; o++) {
104 otext += nodeValue(menunodes[o]);
106 list.options[list.length] = new Option(n + ' : ' + otext, n);
110 function currentSlide() {
114 if (document.getElementById) {
115 cs = document.getElementById('currentSlide');
116 footer_nodes = document.getElementById('footer').childNodes;
118 cs = document.currentSlide;
119 footer = document.footer.childNodes;
121 cs.innerHTML = '<span id="csHere">' + snum + '<\/span> ' +
122 '<span id="csSep">\/<\/span> ' +
123 '<span id="csTotal">' + (smax-1) + '<\/span>';
127 cs.style.visibility = vis;
128 for (var i = 0; i < footer_nodes.length; i++) {
129 if (footer_nodes[i].nodeType == 1) {
130 footer_nodes[i].style.visibility = vis;
136 if (document.getElementById('slideProj').disabled || step == 0) return;
137 var jl = document.getElementById('jumplist');
138 var cid = slideIDs[snum];
139 var ce = document.getElementById(cid);
140 if (incrementals[snum].length > 0) {
141 for (var i = 0; i < incrementals[snum].length; i++) {
142 removeClass(incrementals[snum][i], 'current');
143 removeClass(incrementals[snum][i], 'incremental');
149 if (snum > lmax) snum = lmax;
150 if (snum < 0) snum = 0;
152 snum = parseInt(jl.value);
153 var nid = slideIDs[snum];
154 var ne = document.getElementById(nid);
156 ne = document.getElementById(slideIDs[0]);
159 if (step < 0) {incpos = incrementals[snum].length} else {incpos = 0;}
160 if (incrementals[snum].length > 0 && incpos == 0) {
161 for (var i = 0; i < incrementals[snum].length; i++) {
162 if (hasClass(incrementals[snum][i], 'current'))
165 addClass(incrementals[snum][i], 'incremental');
168 if (incrementals[snum].length > 0 && incpos > 0)
169 addClass(incrementals[snum][incpos - 1], 'current');
170 ce.style.visibility = 'hidden';
171 ne.style.visibility = 'visible';
172 jl.selectedIndex = snum;
177 function goTo(target) {
178 if (target >= smax || target == snum) return;
182 function subgo(step) {
184 removeClass(incrementals[snum][incpos - 1],'current');
185 removeClass(incrementals[snum][incpos], 'incremental');
186 addClass(incrementals[snum][incpos],'current');
190 removeClass(incrementals[snum][incpos],'current');
191 addClass(incrementals[snum][incpos], 'incremental');
192 addClass(incrementals[snum][incpos - 1],'current');
197 var slideColl = GetElementsWithClassName('*','slide');
198 var slides = document.getElementById('slideProj');
199 var outline = document.getElementById('outlineStyle');
200 if (!slides.disabled) {
201 slides.disabled = true;
202 outline.disabled = false;
205 for (var n = 0; n < smax; n++) {
206 var slide = slideColl[n];
207 slide.style.visibility = 'visible';
210 slides.disabled = false;
211 outline.disabled = true;
214 for (var n = 0; n < smax; n++) {
215 var slide = slideColl[n];
216 slide.style.visibility = 'hidden';
218 slideColl[snum].style.visibility = 'visible';
222 function showHide(action) {
223 var obj = GetElementsWithClassName('*','hideme')[0];
225 case 's': obj.style.visibility = 'visible'; break;
226 case 'h': obj.style.visibility = 'hidden'; break;
228 if (obj.style.visibility != 'visible') {
229 obj.style.visibility = 'visible';
231 obj.style.visibility = 'hidden';
237 // 'keys' code adapted from MozPoint (http://mozpoint.mozdev.org/)
241 key.which = key.keyCode;
243 if (key.which == 84) {
251 if (window.event && isParentOrSelf(window.event.srcElement, 'controls')) return;
252 if (key.target && isParentOrSelf(key.target, 'controls')) return;
253 if(number != undef) {
258 case 34: // page down
261 if(number != undef) {
263 } else if (!incrementals[snum] || incpos >= incrementals[snum].length) {
272 if(number != undef) {
274 } else if (!incrementals[snum] || incpos <= 0) {
290 if (key.which < 48 || key.which > 57) {
293 if (window.event && isParentOrSelf(window.event.srcElement, 'controls')) return;
294 if (key.target && isParentOrSelf(key.target, 'controls')) return;
295 number = (((number != undef) ? number : 0) * 10) + (key.which - 48);
301 function clicker(e) {
305 target = window.event.srcElement;
307 } else target = e.target;
308 if (target.href != null || hasValue(target.rel, 'external') || isParentOrSelf(target, 'controls') || isParentOrSelf(target,'embed') || isParentOrSelf(target, 'object')) return true;
309 if (!e.which || e.which == 1) {
310 if (!incrementals[snum] || incpos >= incrementals[snum].length) {
318 function findSlide(hash) {
319 var target = document.getElementById(hash);
321 for (var i = 0; i < slideIDs.length; i++) {
322 if (target.id == slideIDs[i]) return i;
328 function slideJump() {
329 if (window.location.hash == null || window.location.hash == '') {
333 if (window.location.hash == null) return;
335 dest = findSlide(window.location.hash.slice(1));
342 function fixLinks() {
343 var thisUri = window.location.href;
344 thisUri = thisUri.slice(0, thisUri.length - window.location.hash.length);
345 var aelements = document.getElementsByTagName('A');
346 for (var i = 0; i < aelements.length; i++) {
347 var a = aelements[i].href;
348 var slideID = a.match('\#.+');
349 if ((slideID) && (slideID[0].slice(0,1) == '#')) {
350 var dest = findSlide(slideID[0].slice(1));
352 if (aelements[i].addEventListener) {
353 aelements[i].addEventListener("click", new Function("e",
354 "if (document.getElementById('slideProj').disabled) return;" +
355 "go("+dest+" - snum); " +
356 "if (e.preventDefault) e.preventDefault();"), true);
357 } else if (aelements[i].attachEvent) {
358 aelements[i].attachEvent("onclick", new Function("",
359 "if (document.getElementById('slideProj').disabled) return;" +
360 "go("+dest+" - snum); " +
361 "event.returnValue = false;"));
368 function externalLinks() {
369 if (!document.getElementsByTagName) return;
370 var anchors = document.getElementsByTagName('a');
371 for (var i=0; i<anchors.length; i++) {
372 var anchor = anchors[i];
373 if (anchor.getAttribute('href') && hasValue(anchor.rel, 'external')) {
374 anchor.target = '_blank';
375 addClass(anchor,'external');
380 function createControls() {
381 var controlsDiv = document.getElementById("controls");
382 if (!controlsDiv) return;
383 var hider = ' onmouseover="showHide(\'s\');" onmouseout="showHide(\'h\');"';
384 var hideDiv, hideList = '';
385 if (controlVis == 'hidden') {
390 controlsDiv.innerHTML = '<form action="#" id="controlForm"' + hideDiv + '>' +
391 '<div id="navLinks">' +
392 '<a accesskey="t" id="toggle" href="javascript:toggle();">Ø<\/a>' +
393 '<a accesskey="z" id="prev" href="javascript:go(-1);">«<\/a>' +
394 '<a accesskey="x" id="next" href="javascript:go(1);">»<\/a>' +
395 '<div id="navList"' + hideList + '><select id="jumplist" onchange="go(\'j\');"><\/select><\/div>' +
397 if (controlVis == 'hidden') {
398 var hidden = document.getElementById('navLinks');
400 var hidden = document.getElementById('jumplist');
402 addClass(hidden,'hideme');
405 function fontScale() { // causes layout problems in FireFox that get fixed if browser's Reload is used; same may be true of other Gecko-based browsers
406 if (!s5mode) return false;
407 var vScale = 22; // both yield 32 (after rounding) at 1024x768
408 var hScale = 32; // perhaps should auto-calculate based on theme's declared value?
409 if (window.innerHeight) {
410 var vSize = window.innerHeight;
411 var hSize = window.innerWidth;
412 } else if (document.documentElement.clientHeight) {
413 var vSize = document.documentElement.clientHeight;
414 var hSize = document.documentElement.clientWidth;
415 } else if (document.body.clientHeight) {
416 var vSize = document.body.clientHeight;
417 var hSize = document.body.clientWidth;
419 var vSize = 700; // assuming 1024x768, minus chrome and such
420 var hSize = 1024; // these do not account for kiosk mode or Opera Show
422 var newSize = Math.min(Math.round(vSize/vScale),Math.round(hSize/hScale));
423 fontSize(newSize + 'px');
424 if (isGe) { // hack to counter incremental reflow bugs
425 var obj = document.getElementsByTagName('body')[0];
426 obj.style.display = 'none';
427 obj.style.display = 'block';
431 function fontSize(value) {
432 if (!(s5ss = document.getElementById('s5ss'))) {
434 document.getElementsByTagName('head')[0].appendChild(s5ss = document.createElement('style'));
435 s5ss.setAttribute('media','screen, projection');
436 s5ss.setAttribute('id','s5ss');
438 document.createStyleSheet();
439 document.s5ss = document.styleSheets[document.styleSheets.length - 1];
443 while (s5ss.lastChild) s5ss.removeChild(s5ss.lastChild);
444 s5ss.appendChild(document.createTextNode('body {font-size: ' + value + ' !important;}'));
446 document.s5ss.addRule('body','font-size: ' + value + ' !important;');
450 function notOperaFix() {
451 slideCSS = document.getElementById('slideProj').href;
452 var slides = document.getElementById('slideProj');
453 var outline = document.getElementById('outlineStyle');
454 slides.setAttribute('media','screen');
455 outline.disabled = true;
457 slides.setAttribute('href','null'); // Gecko fix
458 slides.setAttribute('href',slideCSS); // Gecko fix
460 if (isIE && document.styleSheets && document.styleSheets[0]) {
461 document.styleSheets[0].addRule('img', 'behavior: url(ui/default/iepngfix.htc)');
462 document.styleSheets[0].addRule('div', 'behavior: url(ui/default/iepngfix.htc)');
463 document.styleSheets[0].addRule('.slide', 'behavior: url(ui/default/iepngfix.htc)');
467 function getIncrementals(obj) {
468 var incrementals = new Array();
471 var children = obj.childNodes;
472 for (var i = 0; i < children.length; i++) {
473 var child = children[i];
474 if (hasClass(child, 'incremental')) {
475 if (child.nodeName == 'OL' || child.nodeName == 'UL') {
476 removeClass(child, 'incremental');
477 for (var j = 0; j < child.childNodes.length; j++) {
478 if (child.childNodes[j].nodeType == 1) {
479 addClass(child.childNodes[j], 'incremental');
483 incrementals[incrementals.length] = child;
484 removeClass(child,'incremental');
487 if (hasClass(child, 'show-first')) {
488 if (child.nodeName == 'OL' || child.nodeName == 'UL') {
489 removeClass(child, 'show-first');
490 if (child.childNodes[isGe].nodeType == 1) {
491 removeClass(child.childNodes[isGe], 'incremental');
494 incrementals[incrementals.length] = child;
497 incrementals = incrementals.concat(getIncrementals(child));
502 function createIncrementals() {
503 var incrementals = new Array();
504 for (var i = 0; i < smax; i++) {
505 incrementals[i] = getIncrementals(document.getElementById(slideIDs[i]));
510 function defaultCheck() {
511 var allMetas = document.getElementsByTagName('meta');
512 for (var i = 0; i< allMetas.length; i++) {
513 if (allMetas[i].name == 'defaultView') {
514 defaultView = allMetas[i].content;
516 if (allMetas[i].name == 'controlVis') {
517 controlVis = allMetas[i].content;
522 // Key trap fix, new function body for trap()
529 modifierKey = e.ctrlKey || e.altKey || e.metaKey;
534 return modifierKey || e.which == 0;
539 if (!isOp) createControls();
546 incrementals = createIncrementals();
548 if (defaultView == 'outline') {
551 document.onkeyup = keys;
552 document.onkeypress = trap;
553 document.onclick = clicker;
557 window.onload = startup;
558 window.onresize = function(){setTimeout('fontScale()', 50);}