1 // S5 v1.1 slides.js -- released into the Public Domain
3 // Please see http://www.meyerweb.com/eric/tools/s5/credits.html for information
4 // about all the wonderful and talented contributors to this code!
13 var defaultView = 'slideshow';
14 var controlVis = 'visible';
16 var isIE = navigator.appName == 'Microsoft Internet Explorer' && navigator.userAgent.indexOf('Opera') < 1 ? 1 : 0;
17 var isOp = navigator.userAgent.indexOf('Opera') > -1 ? 1 : 0;
18 var isGe = navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('Safari') < 1 ? 1 : 0;
20 function hasClass(object, className) {
21 if (!object.className) return false;
22 return (object.className.search('(^|\\s)' + className + '(\\s|$)') != -1);
25 function hasValue(object, value) {
26 if (!object) return false;
27 return (object.search('(^|\\s)' + value + '(\\s|$)') != -1);
30 function removeClass(object,className) {
32 object.className = object.className.replace(new RegExp('(^|\\s)'+className+'(\\s|$)'), RegExp.$1+RegExp.$2);
35 function addClass(object,className) {
36 if (!object || hasClass(object, className)) return;
37 if (object.className) {
38 object.className += ' '+className;
40 object.className = className;
44 function GetElementsWithClassName(elementName,className) {
45 var allElements = document.getElementsByTagName(elementName);
46 var elemColl = new Array();
47 for (var i = 0; i< allElements.length; i++) {
48 if (hasClass(allElements[i], className)) {
49 elemColl[elemColl.length] = allElements[i];
55 function isParentOrSelf(element, id) {
56 if (element == null || element.nodeName=='BODY') return false;
57 else if (element.id == id) return true;
58 else return isParentOrSelf(element.parentNode, id);
61 function nodeValue(node) {
63 if (node.nodeType == 1) {
64 var children = node.childNodes;
65 for (var i = 0; i < children.length; ++i) {
66 result += nodeValue(children[i]);
69 else if (node.nodeType == 3) {
70 result = node.nodeValue;
75 function slideLabel() {
76 var slideColl = GetElementsWithClassName('*','slide');
77 var list = document.getElementById('jumplist');
78 smax = slideColl.length;
79 for (var n = 0; n < smax; n++) {
80 var obj = slideColl[n];
82 var did = 'slide' + n.toString();
83 obj.setAttribute('id',did);
87 var menu = obj.firstChild;
88 if (!menu) continue; // to cope with empty slides
89 while (menu && menu.nodeType == 3) {
90 menu = menu.nextSibling;
92 if (!menu) continue; // to cope with slides with only text nodes
94 var menunodes = menu.childNodes;
95 for (var o = 0; o < menunodes.length; o++) {
96 otext += nodeValue(menunodes[o]);
98 otext = otext.substr(0,15) + '...';
99 list.options[list.length] = new Option(n + ' : ' + otext, n);
103 function currentSlide() {
105 if (document.getElementById) {
106 cs = document.getElementById('currentSlide');
108 cs = document.currentSlide;
110 cs.innerHTML = '<span id="csHere">' + snum + '<\/span> ' +
111 '<span id="csSep">\/<\/span> ' +
112 '<span id="csTotal">' + (smax-1) + '<\/span>';
114 cs.style.visibility = 'hidden';
116 cs.style.visibility = 'visible';
121 if (document.getElementById('slideProj').disabled || step == 0) return;
122 var jl = document.getElementById('jumplist');
123 var cid = 'slide' + snum;
124 var ce = document.getElementById(cid);
125 if (incrementals[snum].length > 0) {
126 for (var i = 0; i < incrementals[snum].length; i++) {
127 removeClass(incrementals[snum][i], 'current');
128 removeClass(incrementals[snum][i], 'incremental');
134 if (snum > lmax) snum = lmax;
135 if (snum < 0) snum = 0;
137 snum = parseInt(jl.value);
138 var nid = 'slide' + snum;
139 var ne = document.getElementById(nid);
141 ne = document.getElementById('slide0');
144 if (step < 0) {incpos = incrementals[snum].length} else {incpos = 0;}
145 if (incrementals[snum].length > 0 && incpos == 0) {
146 for (var i = 0; i < incrementals[snum].length; i++) {
147 if (hasClass(incrementals[snum][i], 'current'))
150 addClass(incrementals[snum][i], 'incremental');
153 if (incrementals[snum].length > 0 && incpos > 0)
154 addClass(incrementals[snum][incpos - 1], 'current');
155 ce.style.visibility = 'hidden';
156 ne.style.visibility = 'visible';
157 jl.selectedIndex = snum;
162 function goTo(target) {
163 if (target >= smax || target == snum) return;
167 function subgo(step) {
169 removeClass(incrementals[snum][incpos - 1],'current');
170 removeClass(incrementals[snum][incpos], 'incremental');
171 addClass(incrementals[snum][incpos],'current');
175 removeClass(incrementals[snum][incpos],'current');
176 addClass(incrementals[snum][incpos], 'incremental');
177 addClass(incrementals[snum][incpos - 1],'current');
182 var slideColl = GetElementsWithClassName('*','slide');
183 var slides = document.getElementById('slideProj');
184 var outline = document.getElementById('outlineStyle');
185 if (!slides.disabled) {
186 slides.disabled = true;
187 outline.disabled = false;
190 for (var n = 0; n < smax; n++) {
191 var slide = slideColl[n];
192 slide.style.visibility = 'visible';
194 document.getElementById("toggle").value = "Lista slajdów";
196 slides.disabled = false;
197 outline.disabled = true;
200 for (var n = 0; n < smax; n++) {
201 var slide = slideColl[n];
202 slide.style.visibility = 'hidden';
204 slideColl[snum].style.visibility = 'visible';
205 document.getElementById("toggle").value = "Ciągły tekst";
209 function showHide(action) {
210 var obj = GetElementsWithClassName('*','hideme')[0];
212 case 's': obj.style.visibility = 'visible'; break;
213 case 'h': obj.style.visibility = 'hidden'; break;
215 if (obj.style.visibility != 'visible') {
216 obj.style.visibility = 'visible';
218 obj.style.visibility = 'hidden';
224 // 'keys' code adapted from MozPoint (http://mozpoint.mozdev.org/)
228 key.which = key.keyCode;
230 if (key.which == 84) {
238 if (window.event && isParentOrSelf(window.event.srcElement, 'controls')) return;
239 if (key.target && isParentOrSelf(key.target, 'controls')) return;
240 if(number != undef) {
245 case 34: // page down
248 if(number != undef) {
250 } else if (!incrementals[snum] || incpos >= incrementals[snum].length) {
259 if(number != undef) {
261 } else if (!incrementals[snum] || incpos <= 0) {
277 if (key.which < 48 || key.which > 57) {
280 if (window.event && isParentOrSelf(window.event.srcElement, 'controls')) return;
281 if (key.target && isParentOrSelf(key.target, 'controls')) return;
282 number = (((number != undef) ? number : 0) * 10) + (key.which - 48);
288 function clicker(e) {
292 target = window.event.srcElement;
294 } else target = e.target;
295 if (target.getAttribute('href') != null || hasValue(target.rel, 'external') || isParentOrSelf(target, 'controls') || isParentOrSelf(target,'embed') || isParentOrSelf(target,'object')) return true;
296 if (!e.which || e.which == 1) {
297 if (!incrementals[snum] || incpos >= incrementals[snum].length) {
305 function findSlide(hash) {
307 var slides = GetElementsWithClassName('*','slide');
308 for (var i = 0; i < slides.length; i++) {
309 var targetSlide = slides[i];
310 if ( (targetSlide.name && targetSlide.name == hash)
311 || (targetSlide.id && targetSlide.id == hash) ) {
312 target = targetSlide;
316 while(target != null && target.nodeName != 'BODY') {
317 if (hasClass(target, 'slide')) {
318 return parseInt(target.id.slice(5));
320 target = target.parentNode;
325 function slideJump() {
326 if (window.location.hash == null) return;
327 var sregex = /^#slide(\d+)$/;
328 var matches = sregex.exec(window.location.hash);
330 if (matches != null) {
331 dest = parseInt(matches[1]);
333 dest = findSlide(window.location.hash.slice(1));
339 function fixLinks() {
340 var thisUri = window.location.href;
341 thisUri = thisUri.slice(0, thisUri.length - window.location.hash.length);
342 var aelements = document.getElementsByTagName('A');
343 for (var i = 0; i < aelements.length; i++) {
344 var a = aelements[i].href;
345 var slideID = a.match('\#slide[0-9]{1,2}');
346 if ((slideID) && (slideID[0].slice(0,1) == '#')) {
347 var dest = findSlide(slideID[0].slice(1));
349 if (aelements[i].addEventListener) {
350 aelements[i].addEventListener("click", new Function("e",
351 "if (document.getElementById('slideProj').disabled) return;" +
352 "go("+dest+" - snum); " +
353 "if (e.preventDefault) e.preventDefault();"), true);
354 } else if (aelements[i].attachEvent) {
355 aelements[i].attachEvent("onclick", new Function("",
356 "if (document.getElementById('slideProj').disabled) return;" +
357 "go("+dest+" - snum); " +
358 "event.returnValue = false;"));
365 function externalLinks() {
366 if (!document.getElementsByTagName) return;
367 var anchors = document.getElementsByTagName('a');
368 for (var i=0; i<anchors.length; i++) {
369 var anchor = anchors[i];
370 if (anchor.getAttribute('href') && hasValue(anchor.rel, 'external')) {
371 anchor.target = '_blank';
372 addClass(anchor,'external');
377 function createControls() {
378 var controlsDiv = document.getElementById("controls");
379 if (!controlsDiv) return;
380 /*var hider = ' onmouseover="showHide(\'s\');" onmouseout="showHide(\'h\');"';
381 var hideDiv, hideList = '';
382 if (controlVis == 'hidden') {
387 controlsDiv.innerHTML = '' +
388 '<input type="button" accesskey="t" id="toggle" onclick="toggle();" value="Ciągły tekst"' +
389 '<input type="button" accesskey="z" id="prev" onclick="javascript:go(-1);" value="«"' +
390 '<input type="button" accesskey="x" id="next" onclick="javascript:go(1);" value="»"' +
391 '<select id="jumplist" onchange="go(\'j\');"><\/select><\/div>';
392 /*if (controlVis == 'hidden') {
393 var hidden = document.getElementById('navLinks');
395 var hidden = document.getElementById('jumplist');
397 addClass(hidden,'hideme');*/
398 document.getElementById("toggle").onclick = toggle;
401 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
402 if (!s5mode) return false;
403 var vScale = 22; // both yield 32 (after rounding) at 1024x768
404 var hScale = 32; // perhaps should auto-calculate based on theme's declared value?
405 if (window.innerHeight) {
406 var vSize = window.innerHeight;
407 var hSize = window.innerWidth;
408 } else if (document.documentElement.clientHeight) {
409 var vSize = document.documentElement.clientHeight;
410 var hSize = document.documentElement.clientWidth;
411 } else if (document.body.clientHeight) {
412 var vSize = document.body.clientHeight;
413 var hSize = document.body.clientWidth;
415 var vSize = 700; // assuming 1024x768, minus chrome and such
416 var hSize = 1024; // these do not account for kiosk mode or Opera Show
418 var newSize = Math.min(Math.round(vSize/vScale),Math.round(hSize/hScale));
419 fontSize(newSize + 'px');
420 if (isGe) { // hack to counter incremental reflow bugs
421 var obj = document.getElementsByTagName('body')[0];
422 obj.style.display = 'none';
423 obj.style.display = 'block';
427 function fontSize(value) {
428 if (!(s5ss = document.getElementById('s5ss'))) {
430 document.getElementsByTagName('head')[0].appendChild(s5ss = document.createElement('style'));
431 s5ss.setAttribute('media','screen, projection');
432 s5ss.setAttribute('id','s5ss');
434 document.createStyleSheet();
435 document.s5ss = document.styleSheets[document.styleSheets.length - 1];
439 while (s5ss.lastChild) s5ss.removeChild(s5ss.lastChild);
440 s5ss.appendChild(document.createTextNode('body {font-size: ' + value + ' !important;}'));
442 document.s5ss.addRule('body','font-size: ' + value + ' !important;');
446 function notOperaFix() {
447 slideCSS = document.getElementById('slideProj').href;
448 var slides = document.getElementById('slideProj');
449 var outline = document.getElementById('outlineStyle');
450 slides.setAttribute('media','screen');
451 outline.disabled = true;
453 slides.setAttribute('href','null'); // Gecko fix
454 slides.setAttribute('href',slideCSS); // Gecko fix
456 if (isIE && document.styleSheets && document.styleSheets[0]) {
457 document.styleSheets[0].addRule('img', 'behavior: url(ui/default/iepngfix.htc)');
458 document.styleSheets[0].addRule('div', 'behavior: url(ui/default/iepngfix.htc)');
459 document.styleSheets[0].addRule('.slide', 'behavior: url(ui/default/iepngfix.htc)');
463 function getIncrementals(obj) {
464 var incrementals = new Array();
467 var children = obj.childNodes;
468 for (var i = 0; i < children.length; i++) {
469 var child = children[i];
470 if (hasClass(child, 'incremental')) {
471 if (child.nodeName == 'OL' || child.nodeName == 'UL') {
472 removeClass(child, 'incremental');
473 for (var j = 0; j < child.childNodes.length; j++) {
474 if (child.childNodes[j].nodeType == 1) {
475 addClass(child.childNodes[j], 'incremental');
479 incrementals[incrementals.length] = child;
480 removeClass(child,'incremental');
483 if (hasClass(child, 'show-first')) {
484 if (child.nodeName == 'OL' || child.nodeName == 'UL') {
485 removeClass(child, 'show-first');
486 if (child.childNodes[isGe].nodeType == 1) {
487 removeClass(child.childNodes[isGe], 'incremental');
490 incrementals[incrementals.length] = child;
493 incrementals = incrementals.concat(getIncrementals(child));
498 function createIncrementals() {
499 var incrementals = new Array();
500 for (var i = 0; i < smax; i++) {
501 incrementals[i] = getIncrementals(document.getElementById('slide'+i));
506 function defaultCheck() {
507 var allMetas = document.getElementsByTagName('meta');
508 for (var i = 0; i< allMetas.length; i++) {
509 if (allMetas[i].name == 'defaultView') {
510 defaultView = allMetas[i].content;
512 if (allMetas[i].name == 'controlVis') {
513 controlVis = allMetas[i].content;
518 // Key trap fix, new function body for trap()
525 modifierKey = e.ctrlKey || e.altKey || e.metaKey;
530 return modifierKey || e.which == 0;
543 incrementals = createIncrementals();
545 if (defaultView == 'outline') {
548 document.onkeyup = keys;
549 document.onkeypress = trap;
550 document.onclick = clicker;
554 window.onload = startup;
555 window.onresize = function(){setTimeout('fontScale()', 50);}