Debian Codegraph @

inst/rmd/slidy/Slidy2/scripts/slidy.js

raw symbols SCIP
1 /* slidy.js
2
3 Copyright (c) 2005-2013 W3C (MIT, ERCIM, Keio), All Rights Reserved.
4 W3C liability, trademark, document use and software licensing
5 rules apply, see:
6
7 http://www.w3.org/Consortium/Legal/copyright-documents
8 http://www.w3.org/Consortium/Legal/copyright-software
9
10 Defines single name "w3c_slidy" in global namespace
11 Adds event handlers without trampling on any others
12 */
13
14 // the slidy object implementation
15 var w3c_slidy = {
16 // classify which kind of browser we're running under
17 ns_pos: (typeof window.pageYOffset!='undefined'),
18 khtml: ((navigator.userAgent).indexOf("KHTML") >= 0 ? true : false),
19 opera: ((navigator.userAgent).indexOf("Opera") >= 0 ? true : false),
20 ipad: ((navigator.userAgent).indexOf("iPad") >= 0 ? true : false),
21 iphone: ((navigator.userAgent).indexOf("iPhone") >= 0 ? true : false),
22 android: ((navigator.userAgent).indexOf("Android") >= 0 ? true : false),
23 ie: (typeof document.all != "undefined" && !this.opera),
24 ie6: (!this.ns_pos && navigator.userAgent.indexOf("MSIE 6") != -1),
25 ie7: (!this.ns_pos && navigator.userAgent.indexOf("MSIE 7") != -1),
26 ie8: (!this.ns_pos && navigator.userAgent.indexOf("MSIE 8") != -1),
27 ie9: (!this.ns_pos && navigator.userAgent.indexOf("MSIE 9") != -1),
28
29 // data for swipe and double tap detection on touch screens
30 last_tap: 0,
31 prev_tap: 0,
32 start_x: 0,
33 start_y: 0,
34 delta_x: 0,
35 delta_y: 0,
36
37 // are we running as XHTML? (doesn't work on Opera)
38 is_xhtml: /xml/.test(document.contentType),
39
40 slide_number: 0, // integer slide count: 0, 1, 2, ...
41 slide_number_element: null, // element containing slide number
42 slides: [], // set to array of slide div's
43 notes: [], // set to array of handout div's
44 backgrounds: [], // set to array of background div's
45 observers: [], // list of observer functions
46 toolbar: null, // element containing toolbar
47 title: null, // document title
48 last_shown: null, // last incrementally shown item
49 eos: null, // span element for end of slide indicator
50 toc: null, // table of contents
51 outline: null, // outline element with the focus
52 selected_text_len: 0, // length of drag selection on document
53 view_all: 0, // 1 to view all slides + handouts
54 want_toolbar: true, // user preference to show/hide toolbar
55 mouse_click_enabled: true, // enables left click for next slide
56 scroll_hack: 0, // IE work around for position: fixed
57 disable_slide_click: false, // used by clicked anchors
58
59 lang: "en", // updated to language specified by html file
60
61 help_anchor: null, // used for keyboard focus hack in showToolbar()
62 help_page: "http://www.w3.org/Talks/Tools/Slidy2/help/help.html",
63 help_text: "Navigate with mouse click, space bar, Cursor Left/Right, " +
64 "or Pg Up and Pg Dn. Use S and B to change font size.",
65
66 size_index: 0,
67 size_adjustment: 0,
68 sizes: new Array("10pt", "12pt", "14pt", "16pt", "18pt", "20pt",
69 "22pt", "24pt", "26pt", "28pt", "30pt", "32pt"),
70
71 // needed for efficient resizing
72 last_width: 0,
73 last_height: 0,
74
75
76 // Needed for cross browser support for relative width/height on
77 // object elements. The work around is to save width/height attributes
78 // and then to recompute absolute width/height dimensions on resizing
79 objects: [],
80
81 // attach initialiation event handlers
82 set_up: function () {
83 var init = function() { w3c_slidy.init(); };
84 if (typeof window.addEventListener != "undefined")
85 window.addEventListener("load", init, false);
86 else
87 window.attachEvent("onload", init);
88 },
89
90 hide_slides: function () {
91 if (document.body && !w3c_slidy.initialized)
92 document.body.style.visibility = "hidden";
93 else
94 setTimeout(w3c_slidy.hide_slides, 50);
95 },
96
97 // hack to persuade IE to compute correct document height
98 // as needed for simulating fixed positioning of toolbar
99 ie_hack: function () {
100 window.resizeBy(0,-1);
101 window.resizeBy(0, 1);
102 },
103
104 init: function () {
105 //alert("slidy starting test 10");
106 document.body.style.visibility = "visible";
107 this.init_localization();
108 this.add_toolbar();
109 this.wrap_implicit_slides();
110 this.collect_slides();
111 this.collect_notes();
112 this.collect_backgrounds();
113 this.objects = document.body.getElementsByTagName("object");
114 this.patch_anchors();
115 this.slide_number = this.find_slide_number(location.href);
116 window.offscreenbuffering = true;
117 this.size_adjustment = this.find_size_adjust();
118 this.time_left = this.find_duration();
119 this.hide_image_toolbar(); // suppress IE image toolbar popup
120 this.init_outliner(); // activate fold/unfold support
121 this.title = document.title;
122 this.keyboardless = (this.ipad||this.iphone||this.android);
123
124 if (this.keyboardless)
125 {
126 w3c_slidy.remove_class(w3c_slidy.toolbar, "hidden")
127 this.want_toolbar = 0;
128 }
129
130 // work around for opera bug
131 this.is_xhtml = (document.body.tagName == "BODY" ? false : true);
132
133 if (this.slides.length > 0)
134 {
135 var slide = this.slides[this.slide_number];
136
137 if (this.slide_number > 0)
138 {
139 this.set_visibility_all_incremental("visible");
140 this.last_shown = this.previous_incremental_item(null);
141 this.set_eos_status(true);
142 }
143 else
144 {
145 this.last_shown = null;
146 this.set_visibility_all_incremental("hidden");
147 this.set_eos_status(!this.next_incremental_item(this.last_shown));
148 }
149
150 this.set_location();
151 this.add_class(this.slides[0], "first-slide");
152 w3c_slidy.show_slide(slide);
153 }
154
155 this.toc = this.table_of_contents();
156
157 this.add_initial_prompt();
158
159 // bind event handlers without interfering with custom page scripts
160 // Tap events behave too weirdly to support clicks reliably on
161 // iPhone and iPad, so exclude these from click handler
162
163 if (!this.keyboardless)
164 {
165 this.add_listener(document.body, "click", this.mouse_button_click);
166 this.add_listener(document.body, "mousedown", this.mouse_button_down);
167 }
168
169 this.add_listener(document, "keydown", this.key_down);
170 this.add_listener(document, "keypress", this.key_press);
171 this.add_listener(window, "resize", this.resized);
172 this.add_listener(window, "scroll", this.scrolled);
173 this.add_listener(window, "unload", this.unloaded);
174
175 this.add_listener(document, "gesturechange", function ()
176 {
177 return false;
178 });
179
180 this.attach_touch_handers(this.slides);
181
182 // this seems to be a debugging hack
183 //if (!document.body.onclick)
184 // document.body.onclick = function () { };
185
186 this.single_slide_view();
187
188 //this.set_location();
189
190 this.resized();
191
192 if (this.ie7)
193 setTimeout(w3c_slidy.ie_hack, 100);
194
195 this.show_toolbar();
196
197 // for back button detection
198 setInterval(function () { w3c_slidy.check_location(); }, 200);
199 w3c_slidy.initialized = true;
200 },
201
202 // create div element with links to each slide
203 table_of_contents: function () {
204 var toc = this.create_element("div");
205 this.add_class(toc, "slidy_toc hidden");
206 //toc.setAttribute("tabindex", "0");
207
208 var heading = this.create_element("div");
209 this.add_class(heading, "toc-heading");
210 heading.innerHTML = this.localize("Table of Contents");
211
212 toc.appendChild(heading);
213 var previous = null;
214
215 for (var i = 0; i < this.slides.length; ++i)
216 {
217 var title = this.has_class(this.slides[i], "title");
218 var num = document.createTextNode((i + 1) + ". ");
219
220 toc.appendChild(num);
221
222 var a = this.create_element("a");
223 a.setAttribute("href", "#(" + (i+1) + ")");
224
225 if (title)
226 this.add_class(a, "titleslide");
227
228 var name = document.createTextNode(this.slide_name(i));
229 a.appendChild(name);
230 a.onclick = w3c_slidy.toc_click;
231 a.onkeydown = w3c_slidy.toc_key_down;
232 a.previous = previous;
233
234 if (previous)
235 previous.next = a;
236
237 toc.appendChild(a);
238
239 if (i == 0)
240 toc.first = a;
241
242 if (i < this.slides.length - 1)
243 {
244 var br = this.create_element("br");
245 toc.appendChild(br);
246 }
247
248 previous = a;
249 }
250
251 toc.focus = function () {
252 if (this.first)
253 this.first.focus();
254 }
255
256 toc.onmouseup = w3c_slidy.mouse_button_up;
257
258 toc.onclick = function (e) {
259 e||(e=window.event);
260
261 if (w3c_slidy.selected_text_len <= 0)
262 w3c_slidy.hide_table_of_contents(true);
263
264 w3c_slidy.stop_propagation(e);
265
266 if (e.cancel != undefined)
267 e.cancel = true;
268
269 if (e.returnValue != undefined)
270 e.returnValue = false;
271
272 return false;
273 };
274
275 document.body.insertBefore(toc, document.body.firstChild);
276 return toc;
277 },
278
279 is_shown_toc: function () {
280 return !w3c_slidy.has_class(w3c_slidy.toc, "hidden");
281 },
282
283 show_table_of_contents: function () {
284 w3c_slidy.remove_class(w3c_slidy.toc, "hidden");
285 var toc = w3c_slidy.toc;
286 toc.focus();
287
288 if (w3c_slidy.ie7 && w3c_slidy.slide_number == 0)
289 setTimeout(w3c_slidy.ie_hack, 100);
290 },
291
292 hide_table_of_contents: function (focus) {
293 w3c_slidy.add_class(w3c_slidy.toc, "hidden");
294
295 if (focus && !w3c_slidy.opera &&
296 !w3c_slidy.has_class(w3c_slidy.toc, "hidden"))
297 w3c_slidy.set_focus();
298 },
299
300 toggle_table_of_contents: function () {
301 if (w3c_slidy.is_shown_toc())
302 w3c_slidy.hide_table_of_contents(true);
303 else
304 w3c_slidy.show_table_of_contents();
305 },
306
307 // called on clicking toc entry
308 toc_click: function (e) {
309 if (!e)
310 e = window.event;
311
312 var target = w3c_slidy.get_target(e);
313
314 if (target && target.nodeType == 1)
315 {
316 var uri = target.getAttribute("href");
317
318 if (uri)
319 {
320 //alert("going to " + uri);
321 var slide = w3c_slidy.slides[w3c_slidy.slide_number];
322 w3c_slidy.hide_slide(slide);
323 w3c_slidy.slide_number = w3c_slidy.find_slide_number(uri);
324 slide = w3c_slidy.slides[w3c_slidy.slide_number];
325 w3c_slidy.last_shown = null;
326 w3c_slidy.set_location();
327 w3c_slidy.set_visibility_all_incremental("hidden");
328 w3c_slidy.set_eos_status(!w3c_slidy.next_incremental_item(w3c_slidy.last_shown));
329 w3c_slidy.show_slide(slide);
330 //target.focus();
331
332 try
333 {
334 if (!w3c_slidy.opera)
335 w3c_slidy.set_focus();
336 }
337 catch (e)
338 {
339 }
340 }
341 }
342
343 w3c_slidy.hide_table_of_contents(true);
344 if (w3c_slidy.ie7) w3c_slidy.ie_hack();
345 w3c_slidy.stop_propagation(e);
346 return w3c_slidy.cancel(e);
347 },
348
349 // called onkeydown for toc entry
350 toc_key_down: function (event) {
351 var key;
352
353 if (!event)
354 var event = window.event;
355
356 // kludge around NS/IE differences
357 if (window.event)
358 key = window.event.keyCode;
359 else if (event.which)
360 key = event.which;
361 else
362 return true; // Yikes! unknown browser
363
364 // ignore event if key value is zero
365 // as for alt on Opera and Konqueror
366 if (!key)
367 return true;
368
369 // check for concurrent control/command/alt key
370 // but are these only present on mouse events?
371
372 if (event.ctrlKey || event.altKey)
373 return true;
374
375 if (key == 13)
376 {
377 var uri = this.getAttribute("href");
378
379 if (uri)
380 {
381 //alert("going to " + uri);
382 var slide = w3c_slidy.slides[w3c_slidy.slide_number];
383 w3c_slidy.hide_slide(slide);
384 w3c_slidy.slide_number = w3c_slidy.find_slide_number(uri);
385 slide = w3c_slidy.slides[w3c_slidy.slide_number];
386 w3c_slidy.last_shown = null;
387 w3c_slidy.set_location();
388 w3c_slidy.set_visibility_all_incremental("hidden");
389 w3c_slidy.set_eos_status(!w3c_slidy.next_incremental_item(w3c_slidy.last_shown));
390 w3c_slidy.show_slide(slide);
391 //target.focus();
392
393 try
394 {
395 if (!w3c_slidy.opera)
396 w3c_slidy.set_focus();
397 }
398 catch (e)
399 {
400 }
401 }
402
403 w3c_slidy.hide_table_of_contents(true);
404
405 if (self.ie7)
406 w3c_slidy.ie_hack();
407
408 return w3c_slidy.cancel(event);
409 }
410
411 if (key == 40 && this.next)
412 {
413 this.next.focus();
414 return w3c_slidy.cancel(event);
415 }
416
417 if (key == 38 && this.previous)
418 {
419 this.previous.focus();
420 return w3c_slidy.cancel(event);
421 }
422
423 return true;
424 },
425
426 touchstart: function (e)
427 {
428 // a double touch often starts with a
429 // single touch due to fingers touching
430 // down at slightly different times
431 // thus avoid calling preventDefault here
432 this.prev_tap = this.last_tap;
433 this.last_tap = (new Date).getTime();
434
435 var tap_delay = this.last_tap - this.prev_tap;
436
437 if (tap_delay <= 200)
438 {
439 // double tap
440 }
441
442 var touch = e.touches[0];
443
444 this.pageX = touch.pageX;
445 this.pageY = touch.pageY;
446 this.screenX = touch.screenX;
447 this.screenY = touch.screenY;
448 this.clientX = touch.clientX;
449 this.clientY = touch.clientY;
450
451 this.delta_x = this.delta_y = 0;
452 },
453
454 touchmove: function (e)
455 {
456 // override native gestures for single touch
457 if (e.touches.length > 1)
458 return;
459
460 e.preventDefault();
461 var touch = e.touches[0];
462 this.delta_x = touch.pageX - this.pageX;
463 this.delta_y = touch.pageY - this.pageY;
464 },
465
466 touchend: function (e)
467 {
468 // default behavior for multi-touch
469 if (e.touches.length > 1)
470 return;
471
472 var delay = (new Date).getTime() - this.last_tap;
473 var dx = this.delta_x;
474 var dy = this.delta_y;
475 var abs_dx = Math.abs(dx);
476 var abs_dy = Math.abs(dy);
477
478 if (delay < 500 && (abs_dx > 100 || abs_dy > 100))
479 {
480 if (abs_dx > 0.5 * abs_dy)
481 {
482 e.preventDefault();
483
484 if (dx < 0)
485 w3c_slidy.next_slide(true);
486 else
487 w3c_slidy.previous_slide(true);
488 }
489 else if (abs_dy > 2 * abs_dx)
490 {
491 e.preventDefault();
492 w3c_slidy.toggle_table_of_contents();
493 }
494 }
495 },
496
497 // ### OBSOLETE ###
498 before_print: function () {
499 this.show_all_slides();
500 this.hide_toolbar();
501 alert("before print");
502 },
503
504 // ### OBSOLETE ###
505 after_print: function () {
506 if (!this.view_all)
507 {
508 this.single_slide_view();
509 this.show_toolbar();
510 }
511 alert("after print");
512 },
513
514 // ### OBSOLETE ###
515 print_slides: function () {
516 this.before_print();
517 window.print();
518 this.after_print();
519 },
520
521 // ### OBSOLETE ?? ###
522 toggle_view: function () {
523 if (this.view_all)
524 {
525 this.single_slide_view();
526 this.show_toolbar();
527 this.view_all = 0;
528 }
529 else
530 {
531 this.show_all_slides();
532 this.hide_toolbar();
533 this.view_all = 1;
534 }
535 },
536
537 // prepare for printing ### OBSOLETE ###
538 show_all_slides: function () {
539 this.remove_class(document.body, "single_slide");
540 this.set_visibility_all_incremental("visible");
541 },
542
543 // restore after printing ### OBSOLETE ###
544 single_slide_view: function () {
545 this.add_class(document.body, "single_slide");
546 this.set_visibility_all_incremental("visible");
547 this.last_shown = this.previous_incremental_item(null);
548 },
549
550 // suppress IE's image toolbar pop up
551 hide_image_toolbar: function () {
552 if (!this.ns_pos)
553 {
554 var images = document.getElementsByTagName("IMG");
555
556 for (var i = 0; i < images.length; ++i)
557 images[i].setAttribute("galleryimg", "no");
558 }
559 },
560
561 unloaded: function (e) {
562 //alert("unloaded");
563 },
564
565 // Safari and Konqueror don't yet support getComputedStyle()
566 // and they always reload page when location.href is updated
567 is_KHTML: function () {
568 var agent = navigator.userAgent;
569 return (agent.indexOf("KHTML") >= 0 ? true : false);
570 },
571
572 // find slide name from first h1 element
573 // default to document title + slide number
574 slide_name: function (index) {
575 var name = null;
576 var slide = this.slides[index];
577
578 var heading = this.find_heading(slide);
579
580 if (heading)
581 name = this.extract_text(heading);
582
583 if (!name)
584 name = this.title + "(" + (index + 1) + ")";
585
586 name.replace(/\&/g, "&amp;");
587 name.replace(/\</g, "&lt;");
588 name.replace(/\>/g, "&gt;");
589
590 return name;
591 },
592
593 // find first h1 element in DOM tree
594 find_heading: function (node) {
595 if (!node || node.nodeType != 1)
596 return null;
597
598 if (node.nodeName == "H1" || node.nodeName == "h1")
599 return node;
600
601 var child = node.firstChild;
602
603 while (child)
604 {
605 node = this.find_heading(child);
606
607 if (node)
608 return node;
609
610 child = child.nextSibling;
611 }
612
613 return null;
614 },
615
616 // recursively extract text from DOM tree
617 extract_text: function (node) {
618 if (!node)
619 return "";
620
621 // text nodes
622 if (node.nodeType == 3)
623 return node.nodeValue;
624
625 // elements
626 if (node.nodeType == 1)
627 {
628 node = node.firstChild;
629 var text = "";
630
631 while (node)
632 {
633 text = text + this.extract_text(node);
634 node = node.nextSibling;
635 }
636
637 return text;
638 }
639
640 return "";
641 },
642
643 // find copyright text from meta element
644 find_copyright: function () {
645 var name, content;
646 var meta = document.getElementsByTagName("meta");
647
648 for (var i = 0; i < meta.length; ++i)
649 {
650 name = meta[i].getAttribute("name");
651 content = meta[i].getAttribute("content");
652
653 if (name == "copyright")
654 return content;
655 }
656
657 return null;
658 },
659
660 find_size_adjust: function () {
661 var name, content, offset;
662 var meta = document.getElementsByTagName("meta");
663
664 for (var i = 0; i < meta.length; ++i)
665 {
666 name = meta[i].getAttribute("name");
667 content = meta[i].getAttribute("content");
668
669 if (name == "font-size-adjustment")
670 return 1 * content;
671 }
672
673 return 1;
674 },
675
676 // <meta name="duration" content="20" /> for 20 minutes
677 find_duration: function () {
678 var name, content, offset;
679 var meta = document.getElementsByTagName("meta");
680
681 for (var i = 0; i < meta.length; ++i)
682 {
683 name = meta[i].getAttribute("name");
684 content = meta[i].getAttribute("content");
685
686 if (name == "duration")
687 return 60000 * content;
688 }
689
690 return null;
691 },
692
693 replace_by_non_breaking_space: function (str) {
694 for (var i = 0; i < str.length; ++i)
695 str[i] = 160;
696 },
697
698 // ### CHECK ME ### is use of "li" okay for text/html?
699 // for XHTML do we also need to specify namespace?
700 init_outliner: function () {
701 var items = document.getElementsByTagName("li");
702
703 for (var i = 0; i < items.length; ++i)
704 {
705 var target = items[i];
706
707 if (!this.has_class(target.parentNode, "outline"))
708 continue;
709
710 target.onclick = this.outline_click;
711 /* ### more work needed for IE6
712 if (!this.ns_pos)
713 {
714 target.onmouseover = this.hover_outline;
715 target.onmouseout = this.unhover_outline;
716 }
717 */
718 if (this.foldable(target))
719 {
720 target.foldable = true;
721 target.onfocus = function () {w3c_slidy.outline = this;};
722 target.onblur = function () {w3c_slidy.outline = null;};
723
724 if (!target.getAttribute("tabindex"))
725 target.setAttribute("tabindex", "0");
726
727 if (this.has_class(target, "expand"))
728 this.unfold(target);
729 else
730 this.fold(target);
731 }
732 else
733 {
734 this.add_class(target, "nofold");
735 target.visible = true;
736 target.foldable = false;
737 }
738 }
739 },
740
741 foldable: function (item) {
742 if (!item || item.nodeType != 1)
743 return false;
744
745 var node = item.firstChild;
746
747 while (node)
748 {
749 if (node.nodeType == 1 && this.is_block(node))
750 return true;
751
752 node = node.nextSibling;
753 }
754
755 return false;
756 },
757
758 // ### CHECK ME ### switch to add/remove "hidden" class
759 fold: function (item) {
760 if (item)
761 {
762 this.remove_class(item, "unfolded");
763 this.add_class(item, "folded");
764 }
765
766 var node = item ? item.firstChild : null;
767
768 while (node)
769 {
770 if (node.nodeType == 1 && this.is_block(node)) // element
771 {
772 w3c_slidy.add_class(node, "hidden");
773 }
774
775 node = node.nextSibling;
776 }
777
778 item.visible = false;
779 },
780
781 // ### CHECK ME ### switch to add/remove "hidden" class
782 unfold: function (item) {
783 if (item)
784 {
785 this.add_class(item, "unfolded");
786 this.remove_class(item, "folded");
787 }
788
789 var node = item ? item.firstChild : null;
790
791 while (node)
792 {
793 if (node.nodeType == 1 && this.is_block(node)) // element
794 {
795 w3c_slidy.remove_class(node, "hidden");
796 }
797
798 node = node.nextSibling;
799 }
800
801 item.visible = true;
802 },
803
804 outline_click: function (e) {
805 if (!e)
806 e = window.event;
807
808 var rightclick = false;
809 var target = w3c_slidy.get_target(e);
810
811 while (target && target.visible == undefined)
812 target = target.parentNode;
813
814 if (!target)
815 return true;
816
817 if (e.which)
818 rightclick = (e.which == 3);
819 else if (e.button)
820 rightclick = (e.button == 2);
821
822 if (!rightclick && target.visible != undefined)
823 {
824 if (target.foldable)
825 {
826 if (target.visible)
827 w3c_slidy.fold(target);
828 else
829 w3c_slidy.unfold(target);
830 }
831
832 w3c_slidy.stop_propagation(e);
833 e.cancel = true;
834 e.returnValue = false;
835 }
836
837 return false;
838 },
839
840 add_initial_prompt: function () {
841 var prompt = this.create_element("div");
842 prompt.setAttribute("class", "initial_prompt");
843
844 var p1 = this.create_element("p");
845 prompt.appendChild(p1);
846 p1.setAttribute("class", "help");
847
848 if (this.keyboardless)
849 p1.innerHTML = "swipe left to move to next slide";
850 else
851 p1.innerHTML = "Space, Right Arrow or swipe left to move to " +
852 "next slide, click help below for more details";
853
854 this.add_listener(prompt, "click", function (e) {
855 document.body.removeChild(prompt);
856 w3c_slidy.stop_propagation(e);
857
858 if (e.cancel != undefined)
859 e.cancel = true;
860
861 if (e.returnValue != undefined)
862 e.returnValue = false;
863
864 return false;
865 });
866
867 document.body.appendChild(prompt);
868 this.initial_prompt = prompt;
869 setTimeout(function() {document.body.removeChild(prompt);}, 5000);
870 },
871
872 add_toolbar: function () {
873 var counter, page;
874
875 this.toolbar = this.create_element("div");
876 this.toolbar.setAttribute("class", "toolbar");
877
878 // a reasonably behaved browser
879 if (this.ns_pos || !this.ie6)
880 {
881 var right = this.create_element("div");
882 right.setAttribute("style", "float: right; text-align: right");
883
884 counter = this.create_element("span")
885 counter.innerHTML = this.localize("slide") + " n/m";
886 right.appendChild(counter);
887 this.toolbar.appendChild(right);
888
889 var left = this.create_element("div");
890 left.setAttribute("style", "text-align: left");
891
892 // global end of slide indicator
893 this.eos = this.create_element("span");
894 this.eos.innerHTML = "* ";
895 left.appendChild(this.eos);
896
897 var help = this.create_element("a");
898 help.setAttribute("href", this.help_page);
899 help.setAttribute("title", this.localize(this.help_text));
900 help.innerHTML = this.localize("help?");
901 left.appendChild(help);
902 help.style.display="none";
903 this.help_anchor = help; // save for focus hack
904
905 var gap1 = document.createTextNode(" ");
906 left.appendChild(gap1);
907
908 var contents = this.create_element("a");
909 contents.setAttribute("href", "javascript:w3c_slidy.toggle_table_of_contents()");
910 contents.setAttribute("title", this.localize("table of contents"));
911 contents.innerHTML = this.localize("Contents");
912 left.appendChild(contents);
913
914 var gap2 = document.createTextNode(" ");
915 left.appendChild(gap2);
916
917 var copyright = this.find_copyright();
918
919 if (copyright)
920 {
921 var span = this.create_element("span");
922 span.className = "copyright";
923 span.innerHTML = copyright;
924 left.appendChild(span);
925 }
926
927 this.toolbar.setAttribute("tabindex", "0");
928 this.toolbar.appendChild(left);
929 }
930 else // IE6 so need to work around its poor CSS support
931 {
932 this.toolbar.style.position = (this.ie7 ? "fixed" : "absolute");
933 this.toolbar.style.zIndex = "200";
934 this.toolbar.style.width = "99.9%";
935 this.toolbar.style.height = "1.2em";
936 this.toolbar.style.top = "auto";
937 this.toolbar.style.bottom = "0";
938 this.toolbar.style.left = "0";
939 this.toolbar.style.right = "0";
940 this.toolbar.style.textAlign = "left";
941 this.toolbar.style.fontSize = "60%";
942 this.toolbar.style.color = "red";
943 this.toolbar.borderWidth = 0;
944 this.toolbar.className = "toolbar";
945 this.toolbar.style.background = "rgb(240,240,240)";
946
947 // would like to have help text left aligned
948 // and page counter right aligned, floating
949 // div's don't work, so instead use nested
950 // absolutely positioned div's.
951
952 var sp = this.create_element("span");
953 sp.innerHTML = "&nbsp;&nbsp;*&nbsp;";
954 this.toolbar.appendChild(sp);
955 this.eos = sp; // end of slide indicator
956
957 var help = this.create_element("a");
958 help.setAttribute("href", this.help_page);
959 help.setAttribute("title", this.localize(this.help_text));
960 help.innerHTML = this.localize("help?");
961 this.toolbar.appendChild(help);
962 this.help_anchor = help; // save for focus hack
963
964 var gap1 = document.createTextNode(" ");
965 this.toolbar.appendChild(gap1);
966
967 var contents = this.create_element("a");
968 contents.setAttribute("href", "javascript:toggleTableOfContents()");
969 contents.setAttribute("title", this.localize("table of contents".localize));
970 contents.innerHTML = this.localize("contents?");
971 this.toolbar.appendChild(contents);
972
973 var gap2 = document.createTextNode(" ");
974 this.toolbar.appendChild(gap2);
975
976 var copyright = this.find_copyright();
977
978 if (copyright)
979 {
980 var span = this.create_element("span");
981 span.innerHTML = copyright;
982 span.style.color = "black";
983 span.style.marginLeft = "0.5em";
984 this.toolbar.appendChild(span);
985 }
986
987 counter = this.create_element("div")
988 counter.style.position = "absolute";
989 counter.style.width = "auto"; //"20%";
990 counter.style.height = "1.2em";
991 counter.style.top = "auto";
992 counter.style.bottom = 0;
993 counter.style.right = "0";
994 counter.style.textAlign = "right";
995 counter.style.color = "red";
996 counter.style.background = "rgb(240,240,240)";
997
998 counter.innerHTML = this.localize("slide") + " n/m";
999 this.toolbar.appendChild(counter);
1000 }
1001
1002 // ensure that click isn't passed through to the page
1003 this.toolbar.onclick =
1004 function (e) {
1005 if (!e)
1006 e = window.event;
1007
1008 var target = e.target;
1009
1010 if (!target && e.srcElement)
1011 target = e.srcElement;
1012
1013 // work around Safari bug
1014 if (target && target.nodeType == 3)
1015 target = target.parentNode;
1016
1017 w3c_slidy.stop_propagation(e);
1018
1019 if (target && target.nodeName.toLowerCase() != "a")
1020 w3c_slidy.mouse_button_click(e);
1021 };
1022
1023 this.slide_number_element = counter;
1024 this.set_eos_status(false);
1025 document.body.appendChild(this.toolbar);
1026 },
1027
1028 // wysiwyg editors make it hard to use div elements
1029 // e.g. amaya loses the div when you copy and paste
1030 // this function wraps div elements around implicit
1031 // slides which start with an h1 element and continue
1032 // up to the next heading or div element
1033 wrap_implicit_slides: function () {
1034 var i, heading, node, next, div;
1035 var headings = document.getElementsByTagName("h1");
1036
1037 if (!headings)
1038 return;
1039
1040 for (i = 0; i < headings.length; ++i)
1041 {
1042 heading = headings[i];
1043
1044 if (heading.parentNode != document.body)
1045 continue;
1046
1047 node = heading.nextSibling;
1048
1049 div = document.createElement("div");
1050 this.add_class(div, "slide");
1051 document.body.replaceChild(div, heading);
1052 div.appendChild(heading);
1053
1054 while (node)
1055 {
1056 if (node.nodeType == 1) // an element
1057 {
1058 if (node.nodeName == "H1" || node.nodeName == "h1")
1059 break;
1060
1061 if (node.nodeName == "DIV" || node.nodeName == "div")
1062 {
1063 if (this.has_class(node, "slide"))
1064 break;
1065
1066 if (this.has_class(node, "handout"))
1067 break;
1068 }
1069 }
1070
1071 next = node.nextSibling;
1072 node = document.body.removeChild(node);
1073 div.appendChild(node);
1074 node = next;
1075 }
1076 }
1077 },
1078
1079 attach_touch_handers: function(slides)
1080 {
1081 var i, slide;
1082
1083 for (i = 0; i < slides.length; ++i)
1084 {
1085 slide = slides[i];
1086 this.add_listener(slide, "touchstart", this.touchstart);
1087 this.add_listener(slide, "touchmove", this.touchmove);
1088 this.add_listener(slide, "touchend", this.touchend);
1089 }
1090 },
1091
1092 // return new array of all slides
1093 collect_slides: function () {
1094 var slides = new Array();
1095 var divs = document.body.getElementsByTagName("div");
1096
1097 for (var i = 0; i < divs.length; ++i)
1098 {
1099 div = divs.item(i);
1100
1101 if (this.has_class(div, "slide"))
1102 {
1103 // add slide to collection
1104 slides[slides.length] = div;
1105
1106 // hide each slide as it is found
1107 this.add_class(div, "hidden");
1108
1109 // add dummy <br/> at end for scrolling hack
1110 var node1 = document.createElement("br");
1111 div.appendChild(node1);
1112 var node2 = document.createElement("br");
1113 div.appendChild(node2);
1114 }
1115 else if (this.has_class(div, "background"))
1116 { // work around for Firefox SVG reload bug
1117 // which otherwise replaces 1st SVG graphic with 2nd
1118 div.style.display = "block";
1119 }
1120 }
1121
1122 this.slides = slides;
1123 },
1124
1125 // return new array of all <div class="handout">
1126 collect_notes: function () {
1127 var notes = new Array();
1128 var divs = document.body.getElementsByTagName("div");
1129
1130 for (var i = 0; i < divs.length; ++i)
1131 {
1132 div = divs.item(i);
1133
1134 if (this.has_class(div, "handout"))
1135 {
1136 // add note to collection
1137 notes[notes.length] = div;
1138
1139 // and hide it
1140 this.add_class(div, "hidden");
1141 }
1142 }
1143
1144 this.notes = notes;
1145 },
1146
1147 // return new array of all <div class="background">
1148 // including named backgrounds e.g. class="background titlepage"
1149 collect_backgrounds: function () {
1150 var backgrounds = new Array();
1151 var divs = document.body.getElementsByTagName("div");
1152
1153 for (var i = 0; i < divs.length; ++i)
1154 {
1155 div = divs.item(i);
1156
1157 if (this.has_class(div, "background"))
1158 {
1159 // add background to collection
1160 backgrounds[backgrounds.length] = div;
1161
1162 // and hide it
1163 this.add_class(div, "hidden");
1164 }
1165 }
1166
1167 this.backgrounds = backgrounds;
1168 },
1169
1170 // set click handlers on all anchors
1171 patch_anchors: function () {
1172 var self = w3c_slidy;
1173 var handler = function (event) {
1174 // compare this.href with location.href
1175 // for link to another slide in this doc
1176
1177 if (self.page_address(this.href) == self.page_address(location.href))
1178 {
1179 // yes, so find new slide number
1180 var newslidenum = self.find_slide_number(this.href);
1181
1182 if (newslidenum != self.slide_number)
1183 {
1184 var slide = self.slides[self.slide_number];
1185 self.hide_slide(slide);
1186 self.slide_number = newslidenum;
1187 slide = self.slides[self.slide_number];
1188 self.show_slide(slide);
1189 self.set_location();
1190 }
1191 }
1192 else
1193 w3c_slidy.stop_propagation(event);
1194
1195 // else if (this.target == null)
1196 // location.href = this.href;
1197
1198 this.blur();
1199 self.disable_slide_click = true;
1200 };
1201
1202 var anchors = document.body.getElementsByTagName("a");
1203
1204 for (var i = 0; i < anchors.length; ++i)
1205 {
1206 if (window.addEventListener)
1207 anchors[i].addEventListener("click", handler, false);
1208 else
1209 anchors[i].attachEvent("onclick", handler);
1210 }
1211 },
1212
1213 // ### CHECK ME ### see which functions are invoked via setTimeout
1214 // either directly or indirectly for use of w3c_slidy vs this
1215 show_slide_number: function () {
1216 var timer = w3c_slidy.get_timer();
1217 w3c_slidy.slide_number_element.innerHTML = timer + w3c_slidy.localize("slide") + " " +
1218 (w3c_slidy.slide_number + 1) + "/" + w3c_slidy.slides.length;
1219 },
1220
1221 // every 200mS check if the location has been changed as a
1222 // result of the user activating the Back button/menu item
1223 // doesn't work for Opera < 9.5
1224 check_location: function () {
1225 var hash = location.hash;
1226
1227 if (w3c_slidy.slide_number > 0 && (hash == "" || hash == "#"))
1228 w3c_slidy.goto_slide(0);
1229 else if (hash.length > 2 && hash != "#("+(w3c_slidy.slide_number+1)+")")
1230 {
1231 var num = parseInt(location.hash.substr(2));
1232
1233 if (!isNaN(num))
1234 w3c_slidy.goto_slide(num-1);
1235 }
1236
1237 if (w3c_slidy.time_left && w3c_slidy.slide_number > 0)
1238 {
1239 w3c_slidy.show_slide_number();
1240
1241 if (w3c_slidy.time_left > 0)
1242 w3c_slidy.time_left -= 200;
1243 }
1244 },
1245
1246 get_timer: function () {
1247 var timer = "";
1248 if (w3c_slidy.time_left)
1249 {
1250 var mins, secs;
1251 secs = Math.floor(w3c_slidy.time_left/1000);
1252 mins = Math.floor(secs / 60);
1253 secs = secs % 60;
1254 timer = (mins ? mins+"m" : "") + secs + "s ";
1255 }
1256
1257 return timer;
1258 },
1259
1260 // this doesn't push location onto history stack for IE
1261 // for which a hidden iframe hack is needed: load page into
1262 // the iframe with script that set's parent's location.hash
1263 // but that won't work for standalone use unless we can
1264 // create the page dynamically via a javascript: URL
1265 // ### use history.pushState if available
1266 set_location: function () {
1267 var uri = w3c_slidy.page_address(location.href);
1268 var hash = "#(" + (w3c_slidy.slide_number+1) + ")";
1269
1270 if (w3c_slidy.slide_number >= 0)
1271 uri = uri + hash;
1272
1273 if (typeof(history.pushState) != "undefined" && location.protocol !== "file:")
1274 {
1275 document.title = w3c_slidy.title + " (" + (w3c_slidy.slide_number+1) + ")";
1276 history.pushState(0, document.title, hash);
1277 w3c_slidy.show_slide_number();
1278 w3c_slidy.notify_observers();
1279 return;
1280 }
1281
1282 if (w3c_slidy.ie && (w3c_slidy.ie6 || w3c_slidy.ie7))
1283 w3c_slidy.push_hash(hash);
1284
1285 if (uri != location.href) // && !khtml
1286 location.href = uri;
1287
1288 if (this.khtml)
1289 hash = "(" + (w3c_slidy.slide_number+1) + ")";
1290
1291 if (!this.ie && location.hash != hash && location.hash != "")
1292 location.hash = hash;
1293
1294 document.title = w3c_slidy.title + " (" + (w3c_slidy.slide_number+1) + ")";
1295 w3c_slidy.show_slide_number();
1296 w3c_slidy.notify_observers();
1297 },
1298
1299 notify_observers: function ()
1300 {
1301 var slide = this.slides[this.slide_number];
1302
1303 for (var i = 0; i < this.observers.length; ++i)
1304 this.observers[i](this.slide_number+1, this.find_heading(slide).innerText, location.href);
1305 },
1306
1307 add_observer: function (observer)
1308 {
1309 for (var i = 0; i < this.observers.length; ++i)
1310 {
1311 if (observer == this.observers[i])
1312 return;
1313 }
1314
1315 this.observers.push(observer);
1316 },
1317
1318 remove_observer: function (o)
1319 {
1320 for (var i = 0; i < this.observers.length; ++i)
1321 {
1322 if (observer == this.observers[i])
1323 {
1324 this.observers.splice(i,1);
1325 break;
1326 }
1327 }
1328 },
1329
1330 page_address: function (uri) {
1331 var i = uri.indexOf("#");
1332
1333 if (i < 0)
1334 i = uri.indexOf("%23");
1335
1336 // check if anchor is entire page
1337
1338 if (i < 0)
1339 return uri; // yes
1340
1341 return uri.substr(0, i);
1342 },
1343
1344 // only used for IE6 and IE7
1345 on_frame_loaded: function (hash) {
1346 location.hash = hash;
1347 var uri = w3c_slidy.page_address(location.href);
1348 location.href = uri + hash;
1349 },
1350
1351 // history hack with thanks to Bertrand Le Roy
1352 push_hash: function (hash) {
1353 if (hash == "") hash = "#(1)";
1354 window.location.hash = hash;
1355
1356 var doc = document.getElementById("historyFrame").contentWindow.document;
1357 doc.open("javascript:'<html></html>'");
1358 doc.write("<html><head><script type=\"text/javascript\">window.parent.w3c_slidy.on_frame_loaded('"+
1359 (hash) + "');</script></head><body>hello mum</body></html>");
1360 doc.close();
1361 },
1362
1363 // find current slide based upon location
1364 // first find target anchor and then look
1365 // for associated div element enclosing it
1366 // finally map that to slide number
1367 find_slide_number: function (uri) {
1368 // first get anchor from page location
1369
1370 var i = uri.indexOf("#");
1371
1372 // check if anchor is entire page
1373 if (i < 0)
1374 return 0; // yes
1375
1376 var anchor = unescape(uri.substr(i+1));
1377
1378 // now use anchor as XML ID to find target
1379 var target = document.getElementById(anchor);
1380
1381 if (!target)
1382 {
1383 // does anchor look like "(2)" for slide 2 ??
1384 // where first slide is (1)
1385 var re = /\((\d)+\)/;
1386
1387 if (anchor.match(re))
1388 {
1389 var num = parseInt(anchor.substring(1, anchor.length-1));
1390
1391 if (num > this.slides.length)
1392 num = 1;
1393
1394 if (--num < 0)
1395 num = 0;
1396
1397 return num;
1398 }
1399
1400 // accept [2] for backwards compatibility
1401 re = /\[(\d)+\]/;
1402
1403 if (anchor.match(re))
1404 {
1405 var num = parseInt(anchor.substring(1, anchor.length-1));
1406
1407 if (num > this.slides.length)
1408 num = 1;
1409
1410 if (--num < 0)
1411 num = 0;
1412
1413 return num;
1414 }
1415
1416 // oh dear unknown anchor
1417 return 0;
1418 }
1419
1420 // search for enclosing slide
1421
1422 while (true)
1423 {
1424 // browser coerces html elements to uppercase!
1425 if (target.nodeName.toLowerCase() == "div" &&
1426 this.has_class(target, "slide"))
1427 {
1428 // found the slide element
1429 break;
1430 }
1431
1432 // otherwise try parent element if any
1433
1434 target = target.parentNode;
1435
1436 if (!target)
1437 {
1438 return 0; // no luck!
1439 }
1440 };
1441
1442 for (i = 0; i < slides.length; ++i)
1443 {
1444 if (slides[i] == target)
1445 return i; // success
1446 }
1447
1448 // oh dear still no luck
1449 return 0;
1450 },
1451
1452 previous_slide: function (incremental) {
1453 if (!w3c_slidy.view_all)
1454 {
1455 var slide;
1456
1457 if ((incremental || w3c_slidy.slide_number == 0) && w3c_slidy.last_shown != null)
1458 {
1459 w3c_slidy.last_shown = w3c_slidy.hide_previous_item(w3c_slidy.last_shown);
1460 w3c_slidy.set_eos_status(false);
1461 }
1462 else if (w3c_slidy.slide_number > 0)
1463 {
1464 slide = w3c_slidy.slides[w3c_slidy.slide_number];
1465 w3c_slidy.hide_slide(slide);
1466
1467 w3c_slidy.slide_number = w3c_slidy.slide_number - 1;
1468 slide = w3c_slidy.slides[w3c_slidy.slide_number];
1469 w3c_slidy.set_visibility_all_incremental("visible");
1470 w3c_slidy.last_shown = w3c_slidy.previous_incremental_item(null);
1471 w3c_slidy.set_eos_status(true);
1472 w3c_slidy.show_slide(slide);
1473 }
1474
1475 w3c_slidy.set_location();
1476
1477 if (!w3c_slidy.ns_pos)
1478 w3c_slidy.refresh_toolbar(200);
1479 }
1480 },
1481
1482 next_slide: function (incremental) {
1483 if (!w3c_slidy.view_all)
1484 {
1485 var slide, last = w3c_slidy.last_shown;
1486
1487 if (incremental || w3c_slidy.slide_number == w3c_slidy.slides.length - 1)
1488 w3c_slidy.last_shown = w3c_slidy.reveal_next_item(w3c_slidy.last_shown);
1489
1490 if ((!incremental || w3c_slidy.last_shown == null) &&
1491 w3c_slidy.slide_number < w3c_slidy.slides.length - 1)
1492 {
1493 slide = w3c_slidy.slides[w3c_slidy.slide_number];
1494 w3c_slidy.hide_slide(slide);
1495
1496 w3c_slidy.slide_number = w3c_slidy.slide_number + 1;
1497 slide = w3c_slidy.slides[w3c_slidy.slide_number];
1498 w3c_slidy.last_shown = null;
1499 w3c_slidy.set_visibility_all_incremental("hidden");
1500 w3c_slidy.show_slide(slide);
1501 }
1502 else if (!w3c_slidy.last_shown)
1503 {
1504 if (last && incremental)
1505 w3c_slidy.last_shown = last;
1506 }
1507
1508 w3c_slidy.set_location();
1509
1510 w3c_slidy.set_eos_status(!w3c_slidy.next_incremental_item(w3c_slidy.last_shown));
1511
1512 if (!w3c_slidy.ns_pos)
1513 w3c_slidy.refresh_toolbar(200);
1514 }
1515 },
1516
1517 // to first slide with nothing revealed
1518 // i.e. state at start of presentation
1519 first_slide: function () {
1520 if (!w3c_slidy.view_all)
1521 {
1522 var slide;
1523
1524 if (w3c_slidy.slide_number != 0)
1525 {
1526 slide = w3c_slidy.slides[w3c_slidy.slide_number];
1527 w3c_slidy.hide_slide(slide);
1528
1529 w3c_slidy.slide_number = 0;
1530 slide = w3c_slidy.slides[w3c_slidy.slide_number];
1531 w3c_slidy.last_shown = null;
1532 w3c_slidy.set_visibility_all_incremental("hidden");
1533 w3c_slidy.show_slide(slide);
1534 }
1535
1536 w3c_slidy.set_eos_status(
1537 !w3c_slidy.next_incremental_item(w3c_slidy.last_shown));
1538 w3c_slidy.set_location();
1539 }
1540 },
1541
1542 // goto last slide with everything revealed
1543 // i.e. state at end of presentation
1544 last_slide: function () {
1545 if (!w3c_slidy.view_all)
1546 {
1547 var slide;
1548
1549 w3c_slidy.last_shown = null; //revealNextItem(lastShown);
1550
1551 if (w3c_slidy.last_shown == null &&
1552 w3c_slidy.slide_number < w3c_slidy.slides.length - 1)
1553 {
1554 slide = w3c_slidy.slides[w3c_slidy.slide_number];
1555 w3c_slidy.hide_slide(slide);
1556 w3c_slidy.slide_number = w3c_slidy.slides.length - 1;
1557 slide = w3c_slidy.slides[w3c_slidy.slide_number];
1558 w3c_slidy.set_visibility_all_incremental("visible");
1559 w3c_slidy.last_shown = w3c_slidy.previous_incremental_item(null);
1560
1561 w3c_slidy.show_slide(slide);
1562 }
1563 else
1564 {
1565 w3c_slidy.set_visibility_all_incremental("visible");
1566 w3c_slidy.last_shown = w3c_slidy.previous_incremental_item(null);
1567 }
1568
1569 w3c_slidy.set_eos_status(true);
1570 w3c_slidy.set_location();
1571 }
1572 },
1573
1574
1575 // ### check this and consider add/remove class
1576 set_eos_status: function (state) {
1577 if (this.eos)
1578 this.eos.style.color = (state ? "rgb(240,240,240)" : "red");
1579 },
1580
1581 // first slide is 0
1582 goto_slide: function (num) {
1583 //alert("going to slide " + (num+1));
1584 var slide = w3c_slidy.slides[w3c_slidy.slide_number];
1585 w3c_slidy.hide_slide(slide);
1586 w3c_slidy.slide_number = num;
1587 slide = w3c_slidy.slides[w3c_slidy.slide_number];
1588 w3c_slidy.last_shown = null;
1589 w3c_slidy.set_visibility_all_incremental("hidden");
1590 w3c_slidy.set_eos_status(!w3c_slidy.next_incremental_item(w3c_slidy.last_shown));
1591 document.title = w3c_slidy.title + " (" + (w3c_slidy.slide_number+1) + ")";
1592 w3c_slidy.show_slide(slide);
1593 w3c_slidy.show_slide_number();
1594 },
1595
1596
1597 show_slide: function (slide) {
1598 this.sync_background(slide);
1599 this.remove_class(slide, "hidden");
1600
1601 // work around IE9 object rendering bug
1602 setTimeout("window.scrollTo(0,0);", 1);
1603 },
1604
1605 hide_slide: function (slide) {
1606 this.add_class(slide, "hidden");
1607 },
1608
1609 set_focus: function (element)
1610 {
1611 if (element)
1612 element.focus();
1613 else
1614 {
1615 w3c_slidy.help_anchor.focus();
1616
1617 setTimeout(function() {
1618 w3c_slidy.help_anchor.blur();
1619 }, 1);
1620 }
1621 },
1622
1623 // show just the backgrounds pertinent to this slide
1624 // when slide background-color is transparent
1625 // this should now work with rgba color values
1626 sync_background: function (slide) {
1627 var background;
1628 var bgColor;
1629
1630 if (slide.currentStyle)
1631 bgColor = slide.currentStyle["backgroundColor"];
1632 else if (document.defaultView)
1633 {
1634 var styles = document.defaultView.getComputedStyle(slide,null);
1635
1636 if (styles)
1637 bgColor = styles.getPropertyValue("background-color");
1638 else // broken implementation probably due Safari or Konqueror
1639 {
1640 //alert("defective implementation of getComputedStyle()");
1641 bgColor = "transparent";
1642 }
1643 }
1644 else
1645 bgColor == "transparent";
1646
1647 if (bgColor == "transparent" ||
1648 bgColor.indexOf("rgba") >= 0 ||
1649 bgColor.indexOf("opacity") >= 0)
1650 {
1651 var slideClass = this.get_class_list(slide);
1652
1653 for (var i = 0; i < this.backgrounds.length; i++)
1654 {
1655 background = this.backgrounds[i];
1656
1657 var bgClass = this.get_class_list(background);
1658
1659 if (this.matching_background(slideClass, bgClass))
1660 this.remove_class(background, "hidden");
1661 else
1662 this.add_class(background, "hidden");
1663 }
1664 }
1665 else // forcibly hide all backgrounds
1666 this.hide_backgrounds();
1667 },
1668
1669 hide_backgrounds: function () {
1670 for (var i = 0; i < this.backgrounds.length; i++)
1671 {
1672 background = this.backgrounds[i];
1673 this.add_class(background, "hidden");
1674 }
1675 },
1676
1677 // compare classes for slide and background
1678 matching_background: function (slideClass, bgClass) {
1679 var i, count, pattern, result;
1680
1681 // define pattern as regular expression
1682 pattern = /\w+/g;
1683
1684 // check background class names
1685 result = bgClass.match(pattern);
1686
1687 for (i = count = 0; i < result.length; i++)
1688 {
1689 if (result[i] == "hidden")
1690 continue;
1691
1692 if (result[i] == "background")
1693 continue;
1694
1695 ++count;
1696 }
1697
1698 if (count == 0) // default match
1699 return true;
1700
1701 // check for matches and place result in array
1702 result = slideClass.match(pattern);
1703
1704 // now check if desired name is present for background
1705 for (i = count = 0; i < result.length; i++)
1706 {
1707 if (result[i] == "hidden")
1708 continue;
1709
1710 if (this.has_token(bgClass, result[i]))
1711 return true;
1712 }
1713
1714 return false;
1715 },
1716
1717 resized: function () {
1718 var width = 0;
1719
1720 if ( typeof( window.innerWidth ) == 'number' )
1721 width = window.innerWidth; // Non IE browser
1722 else if (document.documentElement && document.documentElement.clientWidth)
1723 width = document.documentElement.clientWidth; // IE6
1724 else if (document.body && document.body.clientWidth)
1725 width = document.body.clientWidth; // IE4
1726
1727 var height = 0;
1728
1729 if ( typeof( window.innerHeight ) == 'number' )
1730 height = window.innerHeight; // Non IE browser
1731 else if (document.documentElement && document.documentElement.clientHeight)
1732 height = document.documentElement.clientHeight; // IE6
1733 else if (document.body && document.body.clientHeight)
1734 height = document.body.clientHeight; // IE4
1735
1736 if (height && (width/height > 1.05*1024/768))
1737 {
1738 width = height * 1024.0/768;
1739 }
1740
1741 // IE fires onresize even when only font size is changed!
1742 // so we do a check to avoid blocking < and > actions
1743 if (width != w3c_slidy.last_width || height != w3c_slidy.last_height)
1744 {
1745 if (width >= 1100)
1746 w3c_slidy.size_index = 5; // 4
1747 else if (width >= 1000)
1748 w3c_slidy.size_index = 4; // 3
1749 else if (width >= 800)
1750 w3c_slidy.size_index = 3; // 2
1751 else if (width >= 600)
1752 w3c_slidy.size_index = 2; // 1
1753 else if (width)
1754 w3c_slidy.size_index = 0;
1755
1756 // add in font size adjustment from meta element e.g.
1757 // <meta name="font-size-adjustment" content="-2" />
1758 // useful when slides have too much content ;-)
1759
1760 if (0 <= w3c_slidy.size_index + w3c_slidy.size_adjustment &&
1761 w3c_slidy.size_index + w3c_slidy.size_adjustment < w3c_slidy.sizes.length)
1762 w3c_slidy.size_index = w3c_slidy.size_index + w3c_slidy.size_adjustment;
1763
1764 // enables cross browser use of relative width/height
1765 // on object elements for use with SVG and Flash media
1766 w3c_slidy.adjust_object_dimensions(width, height);
1767
1768 if (document.body.style.fontSize != w3c_slidy.sizes[w3c_slidy.size_index])
1769 {
1770 document.body.style.fontSize = w3c_slidy.sizes[w3c_slidy.size_index];
1771 }
1772
1773 w3c_slidy.last_width = width;
1774 w3c_slidy.last_height = height;
1775
1776 // force reflow to work around Mozilla bug
1777 if (w3c_slidy.ns_pos)
1778 {
1779 var slide = w3c_slidy.slides[w3c_slidy.slide_number];
1780 w3c_slidy.hide_slide(slide);
1781 w3c_slidy.show_slide(slide);
1782 }
1783
1784 // force correct positioning of toolbar
1785 w3c_slidy.refresh_toolbar(200);
1786 }
1787 },
1788
1789 scrolled: function () {
1790 if (w3c_slidy.toolbar && !w3c_slidy.ns_pos && !w3c_slidy.ie7)
1791 {
1792 w3c_slidy.hack_offset = w3c_slidy.scroll_x_offset();
1793 // hide toolbar
1794 w3c_slidy.toolbar.style.display = "none";
1795
1796 // make it reappear later
1797 if (w3c_slidy.scrollhack == 0 && !w3c_slidy.view_all)
1798 {
1799 setTimeout(function () {w3c_slidy.show_toolbar(); }, 1000);
1800 w3c_slidy.scrollhack = 1;
1801 }
1802 }
1803 },
1804
1805 hide_toolbar: function () {
1806 w3c_slidy.add_class(w3c_slidy.toolbar, "hidden");
1807 window.focus();
1808 },
1809
1810 // used to ensure IE refreshes toolbar in correct position
1811 refresh_toolbar: function (interval) {
1812 if (!w3c_slidy.ns_pos && !w3c_slidy.ie7)
1813 {
1814 w3c_slidy.hide_toolbar();
1815 setTimeout(function () {w3c_slidy.show_toolbar();}, interval);
1816 }
1817 },
1818
1819 // restores toolbar after short delay
1820 show_toolbar: function () {
1821 if (w3c_slidy.want_toolbar)
1822 {
1823 w3c_slidy.toolbar.style.display = "block";
1824
1825 if (!w3c_slidy.ns_pos)
1826 {
1827 // adjust position to allow for scrolling
1828 var xoffset = w3c_slidy.scroll_x_offset();
1829 w3c_slidy.toolbar.style.left = xoffset;
1830 w3c_slidy.toolbar.style.right = xoffset;
1831
1832 // determine vertical scroll offset
1833 //var yoffset = scrollYOffset();
1834
1835 // bottom is doc height - window height - scroll offset
1836 //var bottom = documentHeight() - lastHeight - yoffset
1837
1838 //if (yoffset > 0 || documentHeight() > lastHeight)
1839 // bottom += 16; // allow for height of scrollbar
1840
1841 w3c_slidy.toolbar.style.bottom = 0; //bottom;
1842 }
1843
1844 w3c_slidy.remove_class(w3c_slidy.toolbar, "hidden");
1845 }
1846
1847 w3c_slidy.scrollhack = 0;
1848
1849
1850 // set the keyboard focus to the help link on the
1851 // toolbar to ensure that document has the focus
1852 // IE doesn't always work with window.focus()
1853 // and this hack has benefit of Enter for help
1854
1855 try
1856 {
1857 if (!w3c_slidy.opera)
1858 w3c_slidy.set_focus();
1859 }
1860 catch (e)
1861 {
1862 }
1863 },
1864
1865 // invoked via F key
1866 toggle_toolbar: function () {
1867 if (!w3c_slidy.view_all)
1868 {
1869 if (w3c_slidy.has_class(w3c_slidy.toolbar, "hidden"))
1870 {
1871 w3c_slidy.remove_class(w3c_slidy.toolbar, "hidden")
1872 w3c_slidy.want_toolbar = 1;
1873 }
1874 else
1875 {
1876 w3c_slidy.add_class(w3c_slidy.toolbar, "hidden")
1877 w3c_slidy.want_toolbar = 0;
1878 }
1879 }
1880 },
1881
1882 scroll_x_offset: function () {
1883 if (window.pageXOffset)
1884 return self.pageXOffset;
1885
1886 if (document.documentElement &&
1887 document.documentElement.scrollLeft)
1888 return document.documentElement.scrollLeft;
1889
1890 if (document.body)
1891 return document.body.scrollLeft;
1892
1893 return 0;
1894 },
1895
1896 scroll_y_offset: function () {
1897 if (window.pageYOffset)
1898 return self.pageYOffset;
1899
1900 if (document.documentElement &&
1901 document.documentElement.scrollTop)
1902 return document.documentElement.scrollTop;
1903
1904 if (document.body)
1905 return document.body.scrollTop;
1906
1907 return 0;
1908 },
1909
1910 // looking for a way to determine height of slide content
1911 // the slide itself is set to the height of the window
1912 optimize_font_size: function () {
1913 var slide = w3c_slidy.slides[w3c_slidy.slide_number];
1914
1915 //var dh = documentHeight(); //getDocHeight(document);
1916 var dh = slide.scrollHeight;
1917 var wh = getWindowHeight();
1918 var u = 100 * dh / wh;
1919
1920 alert("window utilization = " + u + "% (doc "
1921 + dh + " win " + wh + ")");
1922 },
1923
1924 // from document object
1925 get_doc_height: function (doc) {
1926 if (!doc)
1927 doc = document;
1928
1929 if (doc && doc.body && doc.body.offsetHeight)
1930 return doc.body.offsetHeight; // ns/gecko syntax
1931
1932 if (doc && doc.body && doc.body.scrollHeight)
1933 return doc.body.scrollHeight;
1934
1935 alert("couldn't determine document height");
1936 },
1937
1938 get_window_height: function () {
1939 if ( typeof( window.innerHeight ) == 'number' )
1940 return window.innerHeight; // Non IE browser
1941
1942 if (document.documentElement && document.documentElement.clientHeight)
1943 return document.documentElement.clientHeight; // IE6
1944
1945 if (document.body && document.body.clientHeight)
1946 return document.body.clientHeight; // IE4
1947 },
1948
1949 document_height: function () {
1950 var sh, oh;
1951
1952 sh = document.body.scrollHeight;
1953 oh = document.body.offsetHeight;
1954
1955 if (sh && oh)
1956 {
1957 return (sh > oh ? sh : oh);
1958 }
1959
1960 // no idea!
1961 return 0;
1962 },
1963
1964 smaller: function () {
1965 if (w3c_slidy.size_index > 0)
1966 {
1967 --w3c_slidy.size_index;
1968 }
1969
1970 w3c_slidy.toolbar.style.display = "none";
1971 document.body.style.fontSize = w3c_slidy.sizes[w3c_slidy.size_index];
1972 var slide = w3c_slidy.slides[w3c_slidy.slide_number];
1973 w3c_slidy.hide_slide(slide);
1974 w3c_slidy.show_slide(slide);
1975 setTimeout(function () {w3c_slidy.show_toolbar(); }, 50);
1976 },
1977
1978 bigger: function () {
1979 if (w3c_slidy.size_index < w3c_slidy.sizes.length - 1)
1980 {
1981 ++w3c_slidy.size_index;
1982 }
1983
1984 w3c_slidy.toolbar.style.display = "none";
1985 document.body.style.fontSize = w3c_slidy.sizes[w3c_slidy.size_index];
1986 var slide = w3c_slidy.slides[w3c_slidy.slide_number];
1987 w3c_slidy.hide_slide(slide);
1988 w3c_slidy.show_slide(slide);
1989 setTimeout(function () {w3c_slidy.show_toolbar(); }, 50);
1990 },
1991
1992 // enables cross browser use of relative width/height
1993 // on object elements for use with SVG and Flash media
1994 // with thanks to Ivan Herman for the suggestion
1995 adjust_object_dimensions: function (width, height) {
1996 for( var i = 0; i < w3c_slidy.objects.length; i++ )
1997 {
1998 var obj = this.objects[i];
1999 var mimeType = obj.getAttribute("type");
2000
2001 if (mimeType == "image/svg+xml" || mimeType == "application/x-shockwave-flash")
2002 {
2003 if ( !obj.initialWidth )
2004 obj.initialWidth = obj.getAttribute("width");
2005
2006 if ( !obj.initialHeight )
2007 obj.initialHeight = obj.getAttribute("height");
2008
2009 if ( obj.initialWidth && obj.initialWidth.charAt(obj.initialWidth.length-1) == "%" )
2010 {
2011 var w = parseInt(obj.initialWidth.slice(0, obj.initialWidth.length-1));
2012 var newW = width * (w/100.0);
2013 obj.setAttribute("width",newW);
2014 }
2015
2016 if ( obj.initialHeight &&
2017 obj.initialHeight.charAt(obj.initialHeight.length-1) == "%" )
2018 {
2019 var h = parseInt(obj.initialHeight.slice(0, obj.initialHeight.length-1));
2020 var newH = height * (h/100.0);
2021 obj.setAttribute("height", newH);
2022 }
2023 }
2024 }
2025 },
2026
2027 // needed for Opera to inhibit default behavior
2028 // since Opera delivers keyPress even if keyDown
2029 // was cancelled
2030 key_press: function (event) {
2031 if (!event)
2032 event = window.event;
2033
2034 if (!w3c_slidy.key_wanted)
2035 return w3c_slidy.cancel(event);
2036
2037 return true;
2038 },
2039
2040 // See e.g. http://www.quirksmode.org/js/events/keys.html for keycodes
2041 key_down: function (event) {
2042 var key, target, tag;
2043
2044 w3c_slidy.key_wanted = true;
2045
2046 if (!event)
2047 event = window.event;
2048
2049 // kludge around NS/IE differences
2050 if (window.event)
2051 {
2052 key = window.event.keyCode;
2053 target = window.event.srcElement;
2054 }
2055 else if (event.which)
2056 {
2057 key = event.which;
2058 target = event.target;
2059 }
2060 else
2061 return true; // Yikes! unknown browser
2062
2063 // ignore event if key value is zero
2064 // as for alt on Opera and Konqueror
2065 if (!key)
2066 return true;
2067
2068 // avoid interfering with keystroke
2069 // behavior for non-slidy chrome elements
2070 if (!w3c_slidy.slidy_chrome(target) &&
2071 w3c_slidy.special_element(target))
2072 return true;
2073
2074 // check for concurrent control/command/alt key
2075 // but are these only present on mouse events?
2076
2077 if (event.ctrlKey || event.altKey || event.metaKey)
2078 return true;
2079
2080 // dismiss table of contents if visible
2081 if (w3c_slidy.is_shown_toc() && key != 9 && key != 16 && key != 38 && key != 40)
2082 {
2083 w3c_slidy.hide_table_of_contents(true);
2084
2085 if (key == 27 || key == 84 || key == 67)
2086 return w3c_slidy.cancel(event);
2087 }
2088
2089 if (key == 34) // Page Down
2090 {
2091 if (w3c_slidy.view_all)
2092 return true;
2093
2094 w3c_slidy.next_slide(false);
2095 return w3c_slidy.cancel(event);
2096 }
2097 else if (key == 33) // Page Up
2098 {
2099 if (w3c_slidy.view_all)
2100 return true;
2101
2102 w3c_slidy.previous_slide(false);
2103 return w3c_slidy.cancel(event);
2104 }
2105 else if (key == 32) // space bar
2106 {
2107 w3c_slidy.next_slide(true);
2108 return w3c_slidy.cancel(event);
2109 }
2110 else if (key == 37) // Left arrow
2111 {
2112 w3c_slidy.previous_slide(!event.shiftKey);
2113 return w3c_slidy.cancel(event);
2114 }
2115 else if (key == 36) // Home
2116 {
2117 w3c_slidy.first_slide();
2118 return w3c_slidy.cancel(event);
2119 }
2120 else if (key == 35) // End
2121 {
2122 w3c_slidy.last_slide();
2123 return w3c_slidy.cancel(event);
2124 }
2125 else if (key == 39) // Right arrow
2126 {
2127 w3c_slidy.next_slide(!event.shiftKey);
2128 return w3c_slidy.cancel(event);
2129 }
2130 else if (key == 13) // Enter
2131 {
2132 if (w3c_slidy.outline)
2133 {
2134 if (w3c_slidy.outline.visible)
2135 w3c_slidy.fold(w3c_slidy.outline);
2136 else
2137 w3c_slidy.unfold(w3c_slidy.outline);
2138
2139 return w3c_slidy.cancel(event);
2140 }
2141 }
2142 else if (key == 188) // < for smaller fonts
2143 {
2144 w3c_slidy.smaller();
2145 return w3c_slidy.cancel(event);
2146 }
2147 else if (key == 190) // > for larger fonts
2148 {
2149 w3c_slidy.bigger();
2150 return w3c_slidy.cancel(event);
2151 }
2152 else if (key == 189 || key == 109) // - for smaller fonts
2153 {
2154 w3c_slidy.smaller();
2155 return w3c_slidy.cancel(event);
2156 }
2157 else if (key == 187 || key == 191 || key == 107) // = + for larger fonts
2158 {
2159 w3c_slidy.bigger();
2160 return w3c_slidy.cancel(event);
2161 }
2162 else if (key == 83) // S for smaller fonts
2163 {
2164 w3c_slidy.smaller();
2165 return w3c_slidy.cancel(event);
2166 }
2167 else if (key == 66) // B for larger fonts
2168 {
2169 w3c_slidy.bigger();
2170 return w3c_slidy.cancel(event);
2171 }
2172 else if (key == 90) // Z for last slide
2173 {
2174 w3c_slidy.last_slide();
2175 return w3c_slidy.cancel(event);
2176 }
2177 else if (key == 70) // F for toggle toolbar
2178 {
2179 w3c_slidy.toggle_toolbar();
2180 return w3c_slidy.cancel(event);
2181 }
2182 else if (key == 65) // A for toggle view single/all slides
2183 {
2184 w3c_slidy.toggle_view();
2185 return w3c_slidy.cancel(event);
2186 }
2187 else if (key == 75) // toggle action of left click for next page
2188 {
2189 w3c_slidy.mouse_click_enabled = !w3c_slidy.mouse_click_enabled;
2190 var alert_msg = (w3c_slidy.mouse_click_enabled ?
2191 "enabled" : "disabled") + " mouse click advance";
2192
2193 alert(w3c_slidy.localize(alert_msg));
2194 return w3c_slidy.cancel(event);
2195 }
2196 else if (key == 84 || key == 67) // T or C for table of contents
2197 {
2198 if (w3c_slidy.toc)
2199 w3c_slidy.toggle_table_of_contents();
2200
2201 return w3c_slidy.cancel(event);
2202 }
2203 else if (key == 72) // H for help
2204 {
2205 window.location = w3c_slidy.help_page;
2206 return w3c_slidy.cancel(event);
2207 }
2208 //else alert("key code is "+ key);
2209
2210 return true;
2211 },
2212
2213 // safe for both text/html and application/xhtml+xml
2214 create_element: function (name) {
2215 if (this.xhtml && (typeof document.createElementNS != 'undefined'))
2216 return document.createElementNS("http://www.w3.org/1999/xhtml", name)
2217
2218 return document.createElement(name);
2219 },
2220
2221 get_element_style: function (elem, IEStyleProp, CSSStyleProp) {
2222 if (elem.currentStyle)
2223 {
2224 return elem.currentStyle[IEStyleProp];
2225 }
2226 else if (window.getComputedStyle)
2227 {
2228 var compStyle = window.getComputedStyle(elem, "");
2229 return compStyle.getPropertyValue(CSSStyleProp);
2230 }
2231 return "";
2232 },
2233
2234 // the string str is a whitespace separated list of tokens
2235 // test if str contains a particular token, e.g. "slide"
2236 has_token: function (str, token) {
2237 if (str)
2238 {
2239 // define pattern as regular expression
2240 var pattern = /\w+/g;
2241
2242 // check for matches
2243 // place result in array
2244 var result = str.match(pattern);
2245
2246 // now check if desired token is present
2247 for (var i = 0; i < result.length; i++)
2248 {
2249 if (result[i] == token)
2250 return true;
2251 }
2252 }
2253
2254 return false;
2255 },
2256
2257 get_class_list: function (element) {
2258 if (typeof element.className != 'undefined')
2259 return element.className;
2260
2261 return element.getAttribute("class");
2262 },
2263
2264 has_class: function (element, name) {
2265 if (element.nodeType != 1)
2266 return false;
2267
2268 var regexp = new RegExp("(^| )" + name + "\W*");
2269
2270 if (typeof element.className != 'undefined')
2271 return regexp.test(element.className);
2272
2273 return regexp.test(element.getAttribute("class"));
2274 },
2275
2276 remove_class: function (element, name) {
2277 var regexp = new RegExp("(^| )" + name + "\W*");
2278 var clsval = "";
2279
2280 if (typeof element.className != 'undefined')
2281 {
2282 clsval = element.className;
2283
2284 if (clsval)
2285 {
2286 clsval = clsval.replace(regexp, "");
2287 element.className = clsval;
2288 }
2289 }
2290 else
2291 {
2292 clsval = element.getAttribute("class");
2293
2294 if (clsval)
2295 {
2296 clsval = clsval.replace(regexp, "");
2297 element.setAttribute("class", clsval);
2298 }
2299 }
2300 },
2301
2302 add_class: function (element, name) {
2303 if (!this.has_class(element, name))
2304 {
2305 if (typeof element.className != 'undefined')
2306 element.className += " " + name;
2307 else
2308 {
2309 var clsval = element.getAttribute("class");
2310 clsval = clsval ? clsval + " " + name : name;
2311 element.setAttribute("class", clsval);
2312 }
2313 }
2314 },
2315
2316 // HTML elements that can be used with class="incremental"
2317 // note that you can also put the class on containers like
2318 // up, ol, dl, and div to make their contents appear
2319 // incrementally. Upper case is used since this is what
2320 // browsers report for HTML node names (text/html).
2321 incremental_elements: null,
2322 okay_for_incremental: function (name) {
2323 if (!this.incremental_elements)
2324 {
2325 var inclist = new Array();
2326 inclist["p"] = true;
2327 inclist["pre"] = true;
2328 inclist["li"] = true;
2329 inclist["blockquote"] = true;
2330 inclist["dt"] = true;
2331 inclist["dd"] = true;
2332 inclist["h2"] = true;
2333 inclist["h3"] = true;
2334 inclist["h4"] = true;
2335 inclist["h5"] = true;
2336 inclist["h6"] = true;
2337 inclist["span"] = true;
2338 inclist["address"] = true;
2339 inclist["table"] = true;
2340 inclist["tr"] = true;
2341 inclist["th"] = true;
2342 inclist["td"] = true;
2343 inclist["img"] = true;
2344 inclist["object"] = true;
2345 this.incremental_elements = inclist;
2346 }
2347 return this.incremental_elements[name.toLowerCase()];
2348 },
2349
2350 next_incremental_item: function (node) {
2351 var br = this.is_xhtml ? "br" : "BR";
2352 var slide = w3c_slidy.slides[w3c_slidy.slide_number];
2353
2354 for (;;)
2355 {
2356 node = w3c_slidy.next_node(slide, node);
2357
2358 if (node == null || node.parentNode == null)
2359 break;
2360
2361 if (node.nodeType == 1) // ELEMENT
2362 {
2363 if (node.nodeName == br)
2364 continue;
2365
2366 if (w3c_slidy.has_class(node, "incremental")
2367 && w3c_slidy.okay_for_incremental(node.nodeName))
2368 return node;
2369
2370 if (w3c_slidy.has_class(node.parentNode, "incremental")
2371 && !w3c_slidy.has_class(node, "non-incremental"))
2372 return node;
2373 }
2374 }
2375
2376 return node;
2377 },
2378
2379 previous_incremental_item: function (node) {
2380 var br = this.is_xhtml ? "br" : "BR";
2381 var slide = w3c_slidy.slides[w3c_slidy.slide_number];
2382
2383 for (;;)
2384 {
2385 node = w3c_slidy.previous_node(slide, node);
2386
2387 if (node == null || node.parentNode == null)
2388 break;
2389
2390 if (node.nodeType == 1)
2391 {
2392 if (node.nodeName == br)
2393 continue;
2394
2395 if (w3c_slidy.has_class(node, "incremental")
2396 && w3c_slidy.okay_for_incremental(node.nodeName))
2397 return node;
2398
2399 if (w3c_slidy.has_class(node.parentNode, "incremental")
2400 && !w3c_slidy.has_class(node, "non-incremental"))
2401 return node;
2402 }
2403 }
2404
2405 return node;
2406 },
2407
2408 // set visibility for all elements on current slide with
2409 // a parent element with attribute class="incremental"
2410 set_visibility_all_incremental: function (value) {
2411 var node = this.next_incremental_item(null);
2412
2413 if (value == "hidden")
2414 {
2415 while (node)
2416 {
2417 w3c_slidy.add_class(node, "invisible");
2418 node = w3c_slidy.next_incremental_item(node);
2419 }
2420 }
2421 else // value == "visible"
2422 {
2423 while (node)
2424 {
2425 w3c_slidy.remove_class(node, "invisible");
2426 node = w3c_slidy.next_incremental_item(node);
2427 }
2428 }
2429 },
2430
2431 // reveal the next hidden item on the slide
2432 // node is null or the node that was last revealed
2433 reveal_next_item: function (node) {
2434 node = w3c_slidy.next_incremental_item(node);
2435
2436 if (node && node.nodeType == 1) // an element
2437 w3c_slidy.remove_class(node, "invisible");
2438
2439 return node;
2440 },
2441
2442 // exact inverse of revealNextItem(node)
2443 hide_previous_item: function (node) {
2444 if (node && node.nodeType == 1) // an element
2445 w3c_slidy.add_class(node, "invisible");
2446
2447 return this.previous_incremental_item(node);
2448 },
2449
2450 // left to right traversal of root's content
2451 next_node: function (root, node) {
2452 if (node == null)
2453 return root.firstChild;
2454
2455 if (node.firstChild)
2456 return node.firstChild;
2457
2458 if (node.nextSibling)
2459 return node.nextSibling;
2460
2461 for (;;)
2462 {
2463 node = node.parentNode;
2464
2465 if (!node || node == root)
2466 break;
2467
2468 if (node && node.nextSibling)
2469 return node.nextSibling;
2470 }
2471
2472 return null;
2473 },
2474
2475 // right to left traversal of root's content
2476 previous_node: function (root, node) {
2477 if (node == null)
2478 {
2479 node = root.lastChild;
2480
2481 if (node)
2482 {
2483 while (node.lastChild)
2484 node = node.lastChild;
2485 }
2486
2487 return node;
2488 }
2489
2490 if (node.previousSibling)
2491 {
2492 node = node.previousSibling;
2493
2494 while (node.lastChild)
2495 node = node.lastChild;
2496
2497 return node;
2498 }
2499
2500 if (node.parentNode != root)
2501 return node.parentNode;
2502
2503 return null;
2504 },
2505
2506 previous_sibling_element: function (el) {
2507 el = el.previousSibling;
2508
2509 while (el && el.nodeType != 1)
2510 el = el.previousSibling;
2511
2512 return el;
2513 },
2514
2515 next_sibling_element: function (el) {
2516 el = el.nextSibling;
2517
2518 while (el && el.nodeType != 1)
2519 el = el.nextSibling;
2520
2521 return el;
2522 },
2523
2524 first_child_element: function (el) {
2525 var node;
2526
2527 for (node = el.firstChild; node; node = node.nextSibling)
2528 {
2529 if (node.nodeType == 1)
2530 break;
2531 }
2532
2533 return node;
2534 },
2535
2536 first_tag: function (element, tag) {
2537 var node;
2538
2539 if (!this.is_xhtml)
2540 tag = tag.toUpperCase();
2541
2542 for (node = element.firstChild; node; node = node.nextSibling)
2543 {
2544 if (node.nodeType == 1 && node.nodeName == tag)
2545 break;
2546 }
2547
2548 return node;
2549 },
2550
2551 hide_selection: function () {
2552 if (window.getSelection) // Firefox, Chromium, Safari, Opera
2553 {
2554 var selection = window.getSelection();
2555
2556 if (selection.rangeCount > 0)
2557 {
2558 var range = selection.getRangeAt(0);
2559 range.collapse (false);
2560 }
2561 }
2562 else // Internet Explorer
2563 {
2564 var textRange = document.selection.createRange ();
2565 textRange.collapse (false);
2566 }
2567 },
2568
2569 get_selected_text: function () {
2570 try
2571 {
2572 if (window.getSelection)
2573 return window.getSelection().toString();
2574
2575 if (document.getSelection)
2576 return document.getSelection().toString();
2577
2578 if (document.selection)
2579 return document.selection.createRange().text;
2580 }
2581 catch (e)
2582 {
2583 }
2584
2585 return "";
2586 },
2587
2588 // make note of length of selected text
2589 // as this evaluates to zero in click event
2590 mouse_button_up: function (e) {
2591 w3c_slidy.selected_text_len = w3c_slidy.get_selected_text().length;
2592 },
2593
2594 mouse_button_down: function (e) {
2595 w3c_slidy.selected_text_len = w3c_slidy.get_selected_text().length;
2596 w3c_slidy.mouse_x = e.clientX;
2597 w3c_slidy.mouse_y = e.clientY;
2598 },
2599
2600 // right mouse button click is reserved for context menus
2601 // it is more reliable to detect rightclick than leftclick
2602 mouse_button_click: function (e) {
2603 if (!e)
2604 var e = window.event;
2605
2606 if (Math.abs(e.clientX -w3c_slidy.mouse_x) +
2607 Math.abs(e.clientY -w3c_slidy.mouse_y) > 10)
2608 return true;
2609
2610 if (w3c_slidy.selected_text_len > 0)
2611 return true;
2612
2613 var rightclick = false;
2614 var leftclick = false;
2615 var middleclick = false;
2616 var target;
2617
2618 if (!e)
2619 var e = window.event;
2620
2621 if (e.target)
2622 target = e.target;
2623 else if (e.srcElement)
2624 target = e.srcElement;
2625
2626 // work around Safari bug
2627 if (target.nodeType == 3)
2628 target = target.parentNode;
2629
2630 if (e.which) // all browsers except IE
2631 {
2632 leftclick = (e.which == 1);
2633 middleclick = (e.which == 2);
2634 rightclick = (e.which == 3);
2635 }
2636 else if (e.button)
2637 {
2638 // Konqueror gives 1 for left, 4 for middle
2639 // IE6 gives 0 for left and not 1 as I expected
2640
2641 if (e.button == 4)
2642 middleclick = true;
2643
2644 // all browsers agree on 2 for right button
2645 rightclick = (e.button == 2);
2646 }
2647 else
2648 leftclick = true;
2649
2650 if (w3c_slidy.selected_text_len > 0)
2651 {
2652 w3c_slidy.stop_propagation(e);
2653 e.cancel = true;
2654 e.returnValue = false;
2655 return false;
2656 }
2657
2658 // dismiss table of contents
2659 w3c_slidy.hide_table_of_contents(false);
2660
2661 // check if target is something that probably want's clicks
2662 // e.g. a, embed, object, input, textarea, select, option
2663 var tag = target.nodeName.toLowerCase();
2664
2665 if (w3c_slidy.mouse_click_enabled && leftclick &&
2666 !w3c_slidy.special_element(target) &&
2667 !target.onclick)
2668 {
2669 w3c_slidy.next_slide(true);
2670 w3c_slidy.stop_propagation(e);
2671 e.cancel = true;
2672 e.returnValue = false;
2673 return false;
2674 }
2675
2676 return true;
2677 },
2678
2679 special_element: function (element) {
2680 if (this.has_class(element, "non-interactive"))
2681 return false;
2682
2683 var tag = element.nodeName.toLowerCase();
2684
2685 return element.onkeydown ||
2686 element.onclick ||
2687 tag == "a" ||
2688 tag == "embed" ||
2689 tag == "object" ||
2690 tag == "video" ||
2691 tag == "audio" ||
2692 tag == "svg" ||
2693 tag == "canvas" ||
2694 tag == "input" ||
2695 tag == "textarea" ||
2696 tag == "select" ||
2697 tag == "option";
2698 },
2699
2700 slidy_chrome: function (el) {
2701 while (el)
2702 {
2703 if (el == w3c_slidy.toc ||
2704 el == w3c_slidy.toolbar ||
2705 w3c_slidy.has_class(el, "outline"))
2706 return true;
2707
2708 el = el.parentNode;
2709 }
2710
2711 return false;
2712 },
2713
2714 get_key: function (e)
2715 {
2716 var key;
2717
2718 // kludge around NS/IE differences
2719 if (typeof window.event != "undefined")
2720 key = window.event.keyCode;
2721 else if (e.which)
2722 key = e.which;
2723
2724 return key;
2725 },
2726
2727 get_target: function (e) {
2728 var target;
2729
2730 if (!e)
2731 e = window.event;
2732
2733 if (e.target)
2734 target = e.target;
2735 else if (e.srcElement)
2736 target = e.srcElement;
2737
2738 if (target.nodeType != 1)
2739 target = target.parentNode;
2740
2741 return target;
2742 },
2743
2744 // does display property provide correct defaults?
2745 is_block: function (elem) {
2746 var tag = elem.nodeName.toLowerCase();
2747
2748 return tag == "ol" || tag == "ul" || tag == "p" || tag == "dl" ||
2749 tag == "li" || tag == "table" || tag == "pre" ||
2750 tag == "h1" || tag == "h2" || tag == "h3" ||
2751 tag == "h4" || tag == "h5" || tag == "h6" ||
2752 tag == "blockquote" || tag == "address";
2753 },
2754
2755 add_listener: function (element, event, handler) {
2756 if (window.addEventListener)
2757 element.addEventListener(event, handler, false);
2758 else
2759 element.attachEvent("on"+event, handler);
2760 },
2761
2762 // used to prevent event propagation from field controls
2763 stop_propagation: function (event) {
2764 event = event ? event : window.event;
2765 event.cancelBubble = true; // for IE
2766
2767 if (event.stopPropagation)
2768 event.stopPropagation();
2769
2770 return true;
2771 },
2772
2773 cancel: function (event) {
2774 if (event)
2775 {
2776 event.cancel = true;
2777 event.returnValue = false;
2778
2779 if (event.preventDefault)
2780 event.preventDefault();
2781 }
2782
2783 w3c_slidy.key_wanted = false;
2784 return false;
2785 },
2786
2787 // for each language define an associative array
2788 // and also the help text which is longer
2789
2790 strings_es: {
2791 "slide":"pág.",
2792 "help?":"Ayuda",
2793 "contents?":"Índice",
2794 "table of contents":"tabla de contenidos",
2795 "Table of Contents":"Tabla de Contenidos",
2796 "restart presentation":"Reiniciar presentación",
2797 "restart?":"Inicio"
2798 },
2799 help_es:
2800 "Utilice el ratón, barra espaciadora, teclas Izda/Dcha, " +
2801 "o Re pág y Av pág. Use S y B para cambiar el tamaño de fuente.",
2802
2803 strings_ca: {
2804 "slide":"pàg..",
2805 "help?":"Ajuda",
2806 "contents?":"Índex",
2807 "table of contents":"taula de continguts",
2808 "Table of Contents":"Taula de Continguts",
2809 "restart presentation":"Reiniciar presentació",
2810 "restart?":"Inici"
2811 },
2812 help_ca:
2813 "Utilitzi el ratolí, barra espaiadora, tecles Esq./Dta. " +
2814 "o Re pàg y Av pàg. Usi S i B per canviar grandària de font.",
2815
2816 strings_cs: {
2817 "slide":"snímek",
2818 "help?":"nápověda",
2819 "contents?":"obsah",
2820 "table of contents":"obsah prezentace",
2821 "Table of Contents":"Obsah prezentace",
2822 "restart presentation":"znovu spustit prezentaci",
2823 "restart?":"restart"
2824 },
2825 help_cs:
2826 "Prezentaci můžete procházet pomocí kliknutí myši, mezerníku, " +
2827 "šipek vlevo a vpravo nebo kláves PageUp a PageDown. Písmo se " +
2828 "dá zvětšit a zmenšit pomocí kláves B a S.",
2829
2830 strings_nl: {
2831 "slide":"pagina",
2832 "help?":"Help?",
2833 "contents?":"Inhoud?",
2834 "table of contents":"inhoudsopgave",
2835 "Table of Contents":"Inhoudsopgave",
2836 "restart presentation":"herstart presentatie",
2837 "restart?":"Herstart?"
2838 },
2839 help_nl:
2840 "Navigeer d.m.v. het muis, spatiebar, Links/Rechts toetsen, " +
2841 "of PgUp en PgDn. Gebruik S en B om de karaktergrootte te veranderen.",
2842
2843 strings_de: {
2844 "slide":"Seite",
2845 "help?":"Hilfe",
2846 "contents?":"Übersicht",
2847 "table of contents":"Inhaltsverzeichnis",
2848 "Table of Contents":"Inhaltsverzeichnis",
2849 "restart presentation":"Präsentation neu starten",
2850 "restart?":"Neustart"
2851 },
2852 help_de:
2853 "Benutzen Sie die Maus, Leerschlag, die Cursortasten links/rechts oder " +
2854 "Page up/Page Down zum Wechseln der Seiten und S und B für die Schriftgrösse.",
2855
2856 strings_pl: {
2857 "slide":"slajd",
2858 "help?":"pomoc?",
2859 "contents?":"spis treści?",
2860 "table of contents":"spis treści",
2861 "Table of Contents":"Spis Treści",
2862 "restart presentation":"Restartuj prezentację",
2863 "restart?":"restart?"
2864 },
2865 help_pl:
2866 "Zmieniaj slajdy klikając myszą, naciskając spację, strzałki lewo/prawo" +
2867 "lub PgUp / PgDn. Użyj klawiszy S i B, aby zmienić rozmiar czczionki.",
2868
2869 strings_fr: {
2870 "slide":"page",
2871 "help?":"Aide",
2872 "contents?":"Index",
2873 "table of contents":"table des matières",
2874 "Table of Contents":"Table des matières",
2875 "restart presentation":"Recommencer l'exposé",
2876 "restart?":"Début"
2877 },
2878 help_fr:
2879 "Naviguez avec la souris, la barre d'espace, les flèches " +
2880 "gauche/droite ou les touches Pg Up, Pg Dn. Utilisez " +
2881 "les touches S et B pour modifier la taille de la police.",
2882
2883 strings_hu: {
2884 "slide":"oldal",
2885 "help?":"segítség",
2886 "contents?":"tartalom",
2887 "table of contents":"tartalomjegyzék",
2888 "Table of Contents":"Tartalomjegyzék",
2889 "restart presentation":"bemutató újraindítása",
2890 "restart?":"újraindítás"
2891 },
2892 help_hu:
2893 "Az oldalak közti lépkedéshez kattintson az egérrel, vagy " +
2894 "használja a szóköz, a bal, vagy a jobb nyíl, illetve a Page Down, " +
2895 "Page Up billentyűket. Az S és a B billentyűkkel változtathatja " +
2896 "a szöveg méretét.",
2897
2898 strings_it: {
2899 "slide":"pag.",
2900 "help?":"Aiuto",
2901 "contents?":"Indice",
2902 "table of contents":"indice",
2903 "Table of Contents":"Indice",
2904 "restart presentation":"Ricominciare la presentazione",
2905 "restart?":"Inizio"
2906 },
2907 help_it:
2908 "Navigare con mouse, barra spazio, frecce sinistra/destra o " +
2909 "PgUp e PgDn. Usare S e B per cambiare la dimensione dei caratteri.",
2910
2911 strings_el: {
2912 "slide":"σελίδα",
2913 "help?":"βοήθεια;",
2914 "contents?":"περιεχόμενα;",
2915 "table of contents":"πίνακας περιεχομένων",
2916 "Table of Contents":"Πίνακας Περιεχομένων",
2917 "restart presentation":"επανεκκίνηση παρουσίασης",
2918 "restart?":"επανεκκίνηση;"
2919 },
2920 help_el:
2921 "Πλοηγηθείτε με το κλίκ του ποντικιού, το space, τα βέλη αριστερά/δεξιά, " +
2922 "ή Page Up και Page Down. Χρησιμοποιήστε τα πλήκτρα S και B για να αλλάξετε " +
2923 "το μέγεθος της γραμματοσειράς.",
2924
2925 strings_ja: {
2926 "slide":"スライド",
2927 "help?":"ヘルプ",
2928 "contents?":"目次",
2929 "table of contents":"目次を表示",
2930 "Table of Contents":"目次",
2931 "restart presentation":"最初から再生",
2932 "restart?":"最初から"
2933 },
2934 help_ja:
2935 "マウス左クリック ・ スペース ・ 左右キー " +
2936 "または Page Up ・ Page Downで操作, S ・ Bでフォントサイズ変更",
2937
2938 strings_zh: {
2939 "slide":"幻灯片",
2940 "help?":"帮助?",
2941 "contents?":"内容?",
2942 "table of contents":"目录",
2943 "Table of Contents":"目录",
2944 "restart presentation":"重新启动展示",
2945 "restart?":"重新启动?"
2946 },
2947 help_zh:
2948 "用鼠标点击, 空格条, 左右箭头, Pg Up 和 Pg Dn 导航. " +
2949 "用 S, B 改变字体大小.",
2950
2951 strings_ru: {
2952 "slide":"слайд",
2953 "help?":"помощь?",
2954 "contents?":"содержание?",
2955 "table of contents":"оглавление",
2956 "Table of Contents":"Оглавление",
2957 "restart presentation":"перезапустить презентацию",
2958 "restart?":"перезапуск?"
2959 },
2960 help_ru:
2961 "Перемещайтесь кликая мышкой, используя клавишу пробел, стрелки" +
2962 "влево/вправо или Pg Up и Pg Dn. Клавиши S и B меняют размер шрифта.",
2963
2964 strings_sv: {
2965 "slide":"sida",
2966 "help?":"hjälp",
2967 "contents?":"innehåll",
2968 "table of contents":"innehållsförteckning",
2969 "Table of Contents":"Innehållsförteckning",
2970 "restart presentation":"visa presentationen från början",
2971 "restart?":"börja om"
2972 },
2973 help_sv:
2974 "Bläddra med ett klick med vänstra musknappen, mellanslagstangenten, " +
2975 "vänster- och högerpiltangenterna eller tangenterna Pg Up, Pg Dn. " +
2976 "Använd tangenterna S och B för att ändra textens storlek.",
2977
2978 strings: { },
2979
2980 localize: function (src) {
2981 if (src == "")
2982 return src;
2983
2984 // try full language code, e.g. en-US
2985 var s, lookup = w3c_slidy.strings[w3c_slidy.lang];
2986
2987 if (lookup)
2988 {
2989 s = lookup[src];
2990
2991 if (s)
2992 return s;
2993 }
2994
2995 // strip country code suffix, e.g.
2996 // try en if undefined for en-US
2997 var lg = w3c_slidy.lang.split("-");
2998
2999 if (lg.length > 1)
3000 {
3001 lookup = w3c_slidy.strings[lg[0]];
3002
3003 if (lookup)
3004 {
3005 s = lookup[src];
3006
3007 if (s)
3008 return s;
3009 }
3010 }
3011
3012 // otherwise string as is
3013 return src;
3014 },
3015
3016 init_localization: function () {
3017 var i18n = w3c_slidy;
3018 var help_text = w3c_slidy.help_text;
3019
3020 // each such language array is declared in the localize array
3021 // this is used as in w3c_slidy.localize("foo");
3022 this.strings = {
3023 "es":this.strings_es,
3024 "ca":this.strings_ca,
3025 "cs":this.strings_cs,
3026 "nl":this.strings_nl,
3027 "de":this.strings_de,
3028 "pl":this.strings_pl,
3029 "fr":this.strings_fr,
3030 "hu":this.strings_hu,
3031 "it":this.strings_it,
3032 "el":this.strings_el,
3033 "jp":this.strings_ja,
3034 "zh":this.strings_zh,
3035 "ru":this.strings_ru,
3036 "sv":this.strings_sv
3037 },
3038
3039 i18n.strings_es[help_text] = i18n.help_es;
3040 i18n.strings_ca[help_text] = i18n.help_ca;
3041 i18n.strings_cs[help_text] = i18n.help_cs;
3042 i18n.strings_nl[help_text] = i18n.help_nl;
3043 i18n.strings_de[help_text] = i18n.help_de;
3044 i18n.strings_pl[help_text] = i18n.help_pl;
3045 i18n.strings_fr[help_text] = i18n.help_fr;
3046 i18n.strings_hu[help_text] = i18n.help_hu;
3047 i18n.strings_it[help_text] = i18n.help_it;
3048 i18n.strings_el[help_text] = i18n.help_el;
3049 i18n.strings_ja[help_text] = i18n.help_ja;
3050 i18n.strings_zh[help_text] = i18n.help_zh;
3051 i18n.strings_ru[help_text] = i18n.help_ru;
3052 i18n.strings_sv[help_text] = i18n.help_sv;
3053
3054 w3c_slidy.lang = document.body.parentNode.getAttribute("lang");
3055
3056 if (!w3c_slidy.lang)
3057 w3c_slidy.lang = document.body.parentNode.getAttribute("xml:lang");
3058
3059 if (!w3c_slidy.lang)
3060 w3c_slidy.lang = "en";
3061 }
3062 };
3063
3064 // hack for back button behavior
3065 if (w3c_slidy.ie6 || w3c_slidy.ie7)
3066 {
3067 document.write("<iframe id='historyFrame' " +
3068 "src='javascript:\"<html"+"></"+"html>\"' " +
3069 "height='1' width='1' " +
3070 "style='position:absolute;left:-800px'></iframe>");
3071 }
3072
3073 // attach event listeners for initialization
3074 w3c_slidy.set_up();
3075
3076 // hide the slides as soon as body element is available
3077 // to reduce annoying screen mess before the onload event
3078 setTimeout(w3c_slidy.hide_slides, 50);
3079