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 var controls = document.getElementById('controls');
186 if (!slides.disabled) {
187 slides.disabled = true;
188 outline.disabled = false;
191 for (var n = 0; n < smax; n++) {
192 var slide = slideColl[n];
193 slide.style.visibility = 'visible';
195 document.getElementById("toggle").value = "Lista slajdów";
196 addClass(controls, 'hideme');
199 slides.disabled = false;
200 outline.disabled = true;
203 for (var n = 0; n < smax; n++) {
204 var slide = slideColl[n];
205 slide.style.visibility = 'hidden';
207 slideColl[snum].style.visibility = 'visible';
208 document.getElementById("toggle").value = "Ciągły tekst";
213 function showHide(action) {
214 var obj = GetElementsWithClassName('*','hideme')[0];
216 case 's': obj.style.visibility = 'visible'; break;
217 case 'h': obj.style.visibility = 'hidden'; break;
219 if (obj.style.visibility != 'visible') {
220 obj.style.visibility = 'visible';
222 obj.style.visibility = 'hidden';
228 // 'keys' code adapted from MozPoint (http://mozpoint.mozdev.org/)
232 key.which = key.keyCode;
234 if (key.which == 84) {
242 if (window.event && isParentOrSelf(window.event.srcElement, 'controls')) return;
243 if (key.target && isParentOrSelf(key.target, 'controls')) return;
244 if(number != undef) {
249 case 34: // page down
252 if(number != undef) {
254 } else if (!incrementals[snum] || incpos >= incrementals[snum].length) {
263 if(number != undef) {
265 } else if (!incrementals[snum] || incpos <= 0) {
281 if (key.which < 48 || key.which > 57) {
284 if (window.event && isParentOrSelf(window.event.srcElement, 'controls')) return;
285 if (key.target && isParentOrSelf(key.target, 'controls')) return;
286 number = (((number != undef) ? number : 0) * 10) + (key.which - 48);
292 function clicker(e) {
296 target = window.event.srcElement;
298 } else target = e.target;
299 if (target.getAttribute('href') != null || hasValue(target.rel, 'external') || isParentOrSelf(target, 'controls') || isParentOrSelf(target,'embed') || isParentOrSelf(target,'object')) return true;
300 if (!e.which || e.which == 1) {
301 if (!incrementals[snum] || incpos >= incrementals[snum].length) {
309 function findSlide(hash) {
311 var slides = GetElementsWithClassName('*','slide');
312 for (var i = 0; i < slides.length; i++) {
313 var targetSlide = slides[i];
314 if ( (targetSlide.name && targetSlide.name == hash)
315 || (targetSlide.id && targetSlide.id == hash) ) {
316 target = targetSlide;
320 while(target != null && target.nodeName != 'BODY') {
321 if (hasClass(target, 'slide')) {
322 return parseInt(target.id.slice(5));
324 target = target.parentNode;
329 function slideJump() {
330 if (window.location.hash == null) return;
331 var sregex = /^#slide(\d+)$/;
332 var matches = sregex.exec(window.location.hash);
334 if (matches != null) {
335 dest = parseInt(matches[1]);
337 dest = findSlide(window.location.hash.slice(1));
343 function fixLinks() {
344 var thisUri = window.location.href;
345 thisUri = thisUri.slice(0, thisUri.length - window.location.hash.length);
346 var aelements = document.getElementsByTagName('A');
347 for (var i = 0; i < aelements.length; i++) {
348 var a = aelements[i].href;
349 var slideID = a.match('\#slide[0-9]{1,2}');
350 if ((slideID) && (slideID[0].slice(0,1) == '#')) {
351 var dest = findSlide(slideID[0].slice(1));
353 if (aelements[i].addEventListener) {
354 aelements[i].addEventListener("click", new Function("e",
355 "if (document.getElementById('slideProj').disabled) return;" +
356 "go("+dest+" - snum); " +
357 "if (e.preventDefault) e.preventDefault();"), true);
358 } else if (aelements[i].attachEvent) {
359 aelements[i].attachEvent("onclick", new Function("",
360 "if (document.getElementById('slideProj').disabled) return;" +
361 "go("+dest+" - snum); " +
362 "event.returnValue = false;"));
369 function externalLinks() {
370 if (!document.getElementsByTagName) return;
371 var anchors = document.getElementsByTagName('a');
372 for (var i=0; i<anchors.length; i++) {
373 var anchor = anchors[i];
374 if (anchor.getAttribute('href') && hasValue(anchor.rel, 'external')) {
375 anchor.target = '_blank';
376 addClass(anchor,'external');
381 function createControls() {
382 var controlsDiv = document.getElementById("controls");
383 if (!controlsDiv) return;
384 /*var hider = ' onmouseover="showHide(\'s\');" onmouseout="showHide(\'h\');"';
385 var hideDiv, hideList = '';
386 if (controlVis == 'hidden') {
391 controlsDiv.innerHTML = '' +
392 '<input type="button" accesskey="t" id="toggle" onclick="toggle();" value="Ciągły tekst"' +
393 '<input type="button" accesskey="z" id="prev" onclick="javascript:go(-1);" value="«"' +
394 '<input type="button" accesskey="x" id="next" onclick="javascript:go(1);" value="»"' +
395 '<select id="jumplist" onchange="go(\'j\');"><\/select><\/div>';
396 /*if (controlVis == 'hidden') {
397 var hidden = document.getElementById('navLinks');
399 var hidden = document.getElementById('jumplist');
401 addClass(hidden,'hideme');*/
402 document.getElementById("toggle").onclick = toggle;
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('slide'+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;
547 incrementals = createIncrementals();
549 if (defaultView == 'outline') {
552 document.onkeyup = keys;
553 document.onkeypress = trap;
554 document.onclick = clicker;
558 window.onload = startup;
559 window.onresize = function(){setTimeout('fontScale()', 50);}