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];
226
obj.style.visibility = 'visible';
230
//obj.style.visibility = 'hidden';
234
if (obj.style.visibility != 'visible') {
235
obj.style.visibility = 'visible';
237
//obj.style.visibility = 'hidden';
244
// 'keys' code adapted from MozPoint (http://mozpoint.mozdev.org/)
248
key.which = key.keyCode;
250
if (key.which == 84) {
258
if (window.event && isParentOrSelf(window.event.srcElement, 'controls')) return;
259
if (key.target && isParentOrSelf(key.target, 'controls')) return;
260
if(number != undef) {
265
case 34: // page down
268
if(number != undef) {
270
} else if (!incrementals[snum] || incpos >= incrementals[snum].length) {
279
if(number != undef) {
281
} else if (!incrementals[snum] || incpos <= 0) {
297
if (key.which < 48 || key.which > 57) {
300
if (window.event && isParentOrSelf(window.event.srcElement, 'controls')) return;
301
if (key.target && isParentOrSelf(key.target, 'controls')) return;
302
number = (((number != undef) ? number : 0) * 10) + (key.which - 48);
308
function clicker(e) {
312
target = window.event.srcElement;
314
} else target = e.target;
315
if (target.href != null || hasValue(target.rel, 'external') || isParentOrSelf(target, 'controls') || isParentOrSelf(target,'embed') || isParentOrSelf(target, 'object')) return true;
316
if (!e.which || e.which == 1) {
317
if (!incrementals[snum] || incpos >= incrementals[snum].length) {
325
function findSlide(hash) {
326
var target = document.getElementById(hash);
328
for (var i = 0; i < slideIDs.length; i++) {
329
if (target.id == slideIDs[i]) return i;
335
function slideJump() {
336
if (window.location.hash == null || window.location.hash == '') {
340
if (window.location.hash == null) return;
342
dest = findSlide(window.location.hash.slice(1));
349
function fixLinks() {
350
var thisUri = window.location.href;
351
thisUri = thisUri.slice(0, thisUri.length - window.location.hash.length);
352
var aelements = document.getElementsByTagName('A');
353
for (var i = 0; i < aelements.length; i++) {
354
var a = aelements[i].href;
355
var slideID = a.match('\#.+');
356
if ((slideID) && (slideID[0].slice(0,1) == '#')) {
357
var dest = findSlide(slideID[0].slice(1));
359
if (aelements[i].addEventListener) {
360
aelements[i].addEventListener("click", new Function("e",
361
"if (document.getElementById('slideProj').disabled) return;" +
362
"go("+dest+" - snum); " +
363
"if (e.preventDefault) e.preventDefault();"), true);
364
} else if (aelements[i].attachEvent) {
365
aelements[i].attachEvent("onclick", new Function("",
366
"if (document.getElementById('slideProj').disabled) return;" +
367
"go("+dest+" - snum); " +
368
"event.returnValue = false;"));
375
function externalLinks() {
376
if (!document.getElementsByTagName) return;
377
var anchors = document.getElementsByTagName('a');
378
for (var i=0; i<anchors.length; i++) {
379
var anchor = anchors[i];
380
if (anchor.getAttribute('href') && hasValue(anchor.rel, 'external')) {
381
anchor.target = '_blank';
382
addClass(anchor,'external');
387
function createControls() {
388
var controlsDiv = document.getElementById("controls");
389
if (!controlsDiv) return;
390
var hider = ' onmouseover="showHide(\'s\');" onmouseout="showHide(\'h\');"';
391
var hideDiv, hideList = '';
392
if (controlVis == 'hidden') {
397
controlsDiv.innerHTML = '<form action="#" id="controlForm"' + hideDiv + '>' +
398
'<div id="navLinks">' +
399
'<a accesskey="t" id="toggle" href="javascript:toggle();">Ø<\/a>' +
400
'<a accesskey="z" id="prev" href="javascript:go(-1);">«<\/a>' +
401
'<a accesskey="x" id="next" href="javascript:go(1);">»<\/a>' +
402
'<div id="navList"' + hideList + '><select id="jumplist" onchange="go(\'j\');"><\/select><\/div>' +
404
if (controlVis == 'hidden') {
405
var hidden = document.getElementById('navLinks');
407
var hidden = document.getElementById('jumplist');
409
addClass(hidden,'hideme');
412
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
413
if (!s5mode) return false;
414
var vScale = 22; // both yield 32 (after rounding) at 1024x768
415
var hScale = 32; // perhaps should auto-calculate based on theme's declared value?
416
if (window.innerHeight) {
417
var vSize = window.innerHeight;
418
var hSize = window.innerWidth;
419
} else if (document.documentElement.clientHeight) {
420
var vSize = document.documentElement.clientHeight;
421
var hSize = document.documentElement.clientWidth;
422
} else if (document.body.clientHeight) {
423
var vSize = document.body.clientHeight;
424
var hSize = document.body.clientWidth;
426
var vSize = 700; // assuming 1024x768, minus chrome and such
427
var hSize = 1024; // these do not account for kiosk mode or Opera Show
429
var newSize = Math.min(Math.round(vSize/vScale),Math.round(hSize/hScale));
430
fontSize(newSize + 'px');
431
if (isGe) { // hack to counter incremental reflow bugs
432
var obj = document.getElementsByTagName('body')[0];
433
obj.style.display = 'none';
434
obj.style.display = 'block';
438
function fontSize(value) {
439
if (!(s5ss = document.getElementById('s5ss'))) {
441
document.getElementsByTagName('head')[0].appendChild(s5ss = document.createElement('style'));
442
s5ss.setAttribute('media','screen, projection');
443
s5ss.setAttribute('id','s5ss');
445
document.createStyleSheet();
446
document.s5ss = document.styleSheets[document.styleSheets.length - 1];
450
while (s5ss.lastChild) s5ss.removeChild(s5ss.lastChild);
451
s5ss.appendChild(document.createTextNode('body {font-size: ' + value + ' !important;}'));
453
document.s5ss.addRule('body','font-size: ' + value + ' !important;');
457
function notOperaFix() {
458
slideCSS = document.getElementById('slideProj').href;
459
var slides = document.getElementById('slideProj');
460
var outline = document.getElementById('outlineStyle');
461
slides.setAttribute('media','screen');
462
outline.disabled = true;
464
slides.setAttribute('href','null'); // Gecko fix
465
slides.setAttribute('href',slideCSS); // Gecko fix
467
if (isIE && document.styleSheets && document.styleSheets[0]) {
468
document.styleSheets[0].addRule('img', 'behavior: url(ui/default/iepngfix.htc)');
469
document.styleSheets[0].addRule('div', 'behavior: url(ui/default/iepngfix.htc)');
470
document.styleSheets[0].addRule('.slide', 'behavior: url(ui/default/iepngfix.htc)');
474
function getIncrementals(obj) {
475
var incrementals = new Array();
478
var children = obj.childNodes;
479
for (var i = 0; i < children.length; i++) {
480
var child = children[i];
481
if (hasClass(child, 'incremental')) {
482
if (child.nodeName == 'OL' || child.nodeName == 'UL') {
483
removeClass(child, 'incremental');
484
for (var j = 0; j < child.childNodes.length; j++) {
485
if (child.childNodes[j].nodeType == 1) {
486
addClass(child.childNodes[j], 'incremental');
490
incrementals[incrementals.length] = child;
491
removeClass(child,'incremental');
494
if (hasClass(child, 'show-first')) {
495
if (child.nodeName == 'OL' || child.nodeName == 'UL') {
496
removeClass(child, 'show-first');
497
if (child.childNodes[isGe].nodeType == 1) {
498
removeClass(child.childNodes[isGe], 'incremental');
501
incrementals[incrementals.length] = child;
504
incrementals = incrementals.concat(getIncrementals(child));
509
function createIncrementals() {
510
var incrementals = new Array();
511
for (var i = 0; i < smax; i++) {
512
incrementals[i] = getIncrementals(document.getElementById(slideIDs[i]));
517
function defaultCheck() {
518
var allMetas = document.getElementsByTagName('meta');
519
for (var i = 0; i< allMetas.length; i++) {
520
if (allMetas[i].name == 'defaultView') {
521
defaultView = allMetas[i].content;
523
if (allMetas[i].name == 'controlVis') {
524
controlVis = allMetas[i].content;
529
// Key trap fix, new function body for trap()
536
modifierKey = e.ctrlKey || e.altKey || e.metaKey;
541
return modifierKey || e.which == 0;
546
if (!isOp) createControls();
553
incrementals = createIncrementals();
555
if (defaultView == 'outline') {
558
document.onkeyup = keys;
559
document.onkeypress = trap;
560
document.onclick = clicker;
564
window.onload = startup;
565
window.onresize = function(){setTimeout('fontScale()', 50);}