9 SWS.Utils = new function () {
12 self.isUndefined = function (o) { return typeof o == "undefined"; };
13 self.push2 = function (t, i, v) {
14 if ((typeof t[i]) == 'undefined') {
21 self.isEmpty = function (o) {
22 for(var _ in o) return false;
26 self.parseFrameSpec = function (s) {
27 var elems = s.split("_");
31 for(var i = 0; i < elems.length; i++){
32 var bounds = elems[i].split("-");
33 if (bounds.length > 2 || bounds.length == 0) return {};
34 if (bounds.length == 1) bounds[1] = bounds[0];
35 var a = parseInt(bounds[0]);
36 var b = parseInt(bounds[1])
37 if (!isFinite(a) || !isFinite(b)) return {};
38 a = Math.min(a, 1000); // don't allow more than 1000 frames/slide
39 b = Math.min(b, 1000);
40 if (b > max_value) max_value = b;
41 for (var j = a; j <= b; j++)
47 self.getParameterByName = function (name) {
48 name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
49 var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
50 results = regex.exec(location.search);
51 return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
58 SWS.Templates = new function () {
60 self.helpPanel = "<div id='sws-help-panel-canvas'>\
61 <h1>Keyboard shortcuts</h1>\
63 <tr ><td style='color:#f55;'>h</td><td style='color:#f55;'> toggle help</td></tr>\
64 <tr><td>c</td><td> toggle the control panel</td></tr>\
65 <tr><td>Left, PgUp,swipe left</td><td> previous step</td></tr>\
66 <tr><td>Right, PgDown, Space, swipe right</td><td> next step</td></tr>\
67 <tr><td>p</td><td> previous slide</td></tr>\
68 <tr><td>n</td><td> next slide</td></tr>\
69 <tr><td>Home</td><td> first slide</td></tr>\
70 <tr><td>End</td><td> last slide</td></tr>\
73 self.controlPanel = "<div id='sws-control-panel-canvas'><div id='sws-control-panel'>\
74 <div id='sws-control-panel-title-bar'>\
75 <a title='Toggle fullscreen' id='sws-control-panel-fullscreen' class='sws-symbol' onclick='SWS.Presentation.toggleFullScreen();'></a>\
76 <a title='Close panel' id='sws-control-panel-close' onclick='$(\"#sws-control-panel-canvas\").toggle();'>✖</a>\
78 <div id='sws-control-panel-options'>\
79 <span title='Change the aspect ratio' class='sws-symbol' >💻</span><select id='sws-aspect-select' onchange='SWS.Presentation.changeAspect();'>\
80 <option value='sws-aspect-4-3' selected='selected'>4:3</option>\
81 <option value='sws-aspect-16-9'>16:9</option>\
82 <option value='sws-aspect-16-10'>16:10</option>\
84 <span title='Change the theme' class='sws-symbol'>🎨</span><select id='sws-theme-select' onchange='SWS.Presentation.changeTheme();'></select>\
85 <a onclick='SWS.Presentation.openPrint()' ><span title='Open Print-Out' class='sws-symbol'></span></a>\
87 <div id='sws-control-panel-navigation'>\
88 <a title='First slide' class='sws-symbol' onclick='SWS.Presentation.goToSlide(SWS.Presentation.firstSlide());' >⏮</a>\
89 <a title='Previous slide' class='sws-symbol' onclick='SWS.Presentation.previousSlide();SWS.Presentation.refresh();'>⏪</a>\
90 <a title='Previous step' class='sws-symbol' style='-webkit-transform: scaleX(-1);' onclick='SWS.Presentation.previous();SWS.Presentation.refresh();'>▶</a>\
91 <a title='Next step' class='sws-symbol' onclick='SWS.Presentation.next();SWS.Presentation.refresh();'>▶</a>\
92 <a title='Next slide' class='sws-symbol' onclick='SWS.Presentation.nextSlide();SWS.Presentation.refresh();'>⏩</a>\
93 <a title='Last slide' class='sws-symbol' onclick='SWS.Presentation.goToSlide(SWS.Presentation.lastSlide());'>⏭</a>\
95 <span class='sws-symbol'></span><input type='text' id='sws-control-panel-slide-input' oninput='SWS.Presentation.goToSlide($(\"#sws-control-panel-slide-input\").val()-1);'></input><span id='sws-control-panel-total-slides'></span>\
96 <input type='range' title='Navigate the presentation' id='sws-control-panel-navigation-bar' onchange='SWS.Presentation.navigate();' step='1'></input>\
100 self.slideActivate = function (o) {
101 if (!(o.hasClass("sws-active-slide"))){
102 o.removeClass("sws-inactive-slide").addClass("sws-active-slide");
106 self.slideDeactivate = function (o) {
107 if (!(o.hasClass("sws-inactive-slide"))){
108 o.removeClass("sws-active-slide").addClass("sws-inactive-slide");
112 self.slideChange = function (from, to) {
113 var canvas = $(".sws-canvas");
114 self.slideDeactivate($(canvas[from]));
115 self.slideActivate($(canvas[to]));
118 self.objectActivate = function (o) {
119 if (!(o.hasClass("sws-active-object"))){
120 o.removeClass("sws-inactive-object").addClass("sws-active-object");
126 self.objectDeactivate = function (o) {
127 if (!(o.hasClass("sws-inactive-object"))){
128 o.addClass("sws-inactive-object").removeClass("sws-active-object");
134 self.updateFooter = function (o) {
135 var footer = o.find(".sws-footer");
136 if (footer.length && (footer.children("*").length == 0)) {
137 var i = SWS.Presentation.getCurrentSlide();
138 var cur = $( "<span class='sws-current-slide-number'>"
141 var sep = $( "<span class='sws-slide-num-sep' />");
142 var tot = $( "<span class='sws-last-slide-number'>"
143 + (SWS.Presentation.getNumSlides())
145 footer.append(cur).append(sep).append(tot);
148 self.updateHeader = function (o) {};
150 SWS.ConfigBuilder = function () {
152 self['sws-object-activate'] = SWS.Templates.objectActivate;
153 self['sws-object-deactivate'] = SWS.Templates.objectDeactivate;
154 self['sws-slide-change'] = SWS.Templates.slideChange;
155 self['sws-update-footer'] = SWS.Templates.updateFooter;
156 self['sws-update-header'] = SWS.Templates.updateHeader;
159 SWS.Defaults = new SWS.ConfigBuilder ();
161 SWS.Config = new SWS.ConfigBuilder ();
164 SWS.Effects = new function () {
167 self.objectDeactivateFadeOut = function (o) {
168 if (o.is("embed")) return;
169 o.animate({'opacity': '0'}, 200,
172 SWS.Templates.objectDeactivate(o);
176 self.objectActivateFadeIn = function (o) {
178 if (SWS.Templates.objectActivate(o)){
179 o.animate({'opacity': '1' }, 200);
184 self.slideChangeHorizontalFlip = function (from, to){
185 var f = SWS.Presentation.getSlide(from);
186 var t = SWS.Presentation.getSlide(to);
187 f.animate({ 'left': '50%', 'width': '0pt', 'opacity':'0' }, 150,
189 SWS.Templates.slideDeactivate(f);
190 f.css({'left':'0%', 'width': '100%'});
191 t.css({ 'left': '50%', 'width': '0pt','opacity':'0' });
192 SWS.Templates.slideActivate(t);
193 t.animate({'left':'0%', 'width': '100%','opacity':'1'});
196 self.slideChangeFadeOutIn = function (from, to) {
197 var f = SWS.Presentation.getSlide(from);
198 var t = SWS.Presentation.getSlide(to);
199 f.animate({ 'opacity': '0'}, 150,
200 function () { SWS.Templates.slideDeactivate(f);
201 SWS.Templates.slideActivate(t);
202 t.css('opacity', '0');
203 t.animate({ 'opacity': '1'}, 150);
206 self.slideChangeHorizontalSlide = function (from, to) {
207 var f = SWS.Presentation.getSlide(from);
208 var t = SWS.Presentation.getSlide(to);
210 t.css('left', '100%');
211 t.css('opacity', '1');
212 SWS.Templates.slideActivate(t);
213 f.animate({ 'left': '-100%' }, 250, function () { SWS.Templates.slideDeactivate(f);
214 f.css('opacity', '0');
215 t.animate({ 'left': '0%' }, 250);
218 t.css('left', '-100%');
219 SWS.Templates.slideActivate(t);
220 f.animate({ 'left': '100%' }, 250, function () { SWS.Templates.slideDeactivate(f);
221 f.css('opacity', '0');
223 t.css('opacity', '1');
224 t.animate({ 'left': '0%' }, 250);
229 self.slideChangeVerticalSlide = function (from, to) {
230 var f = SWS.Presentation.getSlide(from);
231 var t = SWS.Presentation.getSlide(to);
233 t.css('top', '100%');
234 SWS.Templates.slideActivate(t);
235 f.animate({ 'top': '-100%' }, 250, function () { SWS.Templates.slideDeactivate(f); });
236 t.animate({ 'top': '0%' }, 250);
238 t.css('top', '-100%');
239 SWS.Templates.slideActivate(t);
240 f.animate({ 'top': '100%' }, 250, function () { SWS.Templates.slideDeactivate(f); });
241 t.animate({ 'top': '0%' }, 250);
247 SWS.Fullscreen = new function () {
250 if (SWS.Utils.isUndefined(document.fullScreen)) {
251 if (SWS.Utils.isUndefined(document.mozfullScreen)) {
252 self.status = function () { return document.webkitIsFullScreen; };
253 self.enter = function(e) {
254 e.webkitRequestFullScreen();
256 self.exit = function () {
257 document.webkitCancelFullScreen();
261 self.status = function () { return document.mozfullScreen; };
262 self.enter = function(e) {
263 e.mozRequestFullScreen();
265 self.exit = function () {
266 document.mozCancelFullScreen();
271 self.status = function () { return document.fullScreen; };
272 self.enter = function(e) {
273 e.requestFullScreen();
275 self.exit = function () {
276 document.cancelFullScreen();
284 SWS.Presentation = new function () {
289 //TODO move outside of the Presentation object
293 var _initialized = false;
294 var _disable_input_events = false;
295 var _print_mode = false;
296 var _slide_callbacks = new Array ();
297 var _total_steps = -1;
298 var _current_theme = "";
300 self.getNumSlides = function () { return _total_slides; };
302 self.getSlide = function(i) {
303 return $($(".sws-canvas")[i]);
306 self.registerCallback = function (i, f) {
307 if (_initialized) return;
308 //jQuery does not seem to work well
310 var slides = $(".sws-slide");
311 var h1s = $("body").children("h1");
312 var slide_num = slides.add(h1s).length - 1;
313 SWS.Utils.push2(_slide_callbacks, slide_num,{ 'fn': f, 'frame': i });
317 if (typeof(Storage)!=="undefined"){
318 self.getCurrentSlide = function () {
319 //unary + casts to integer
320 var i = +(sessionStorage.getItem("current_slide"));
321 if (!(i >= 0 && i < self.getNumSlides())){
328 self.setCurrentSlide = function (i) {
329 sessionStorage.setItem("current_slide", i);
332 self.showHelpAtStartup = function () {
333 var r = sessionStorage.getItem("show_help");
334 if (r == "hide") return false;
335 sessionStorage.setItem("show_help", "hide");
340 var _current_slide = 0;
341 self.getCurrentSlide = function () { return _current_slide; };
342 self.setCurrentSlide = function (i) { _current_slide = i; };
343 self.showHelpAtStartup = function () { return false; };
345 self.firstSlide = function () { return 0; };
346 self.lastSlide = function () { return self.getNumSlides() - 1; };
347 self.refresh = function () {
348 /* block upcoming input event until all animations are finished */
349 _disable_input_events = true;
351 var canvas = $(".sws-canvas");
352 var from_slide_num = canvas.index($(".sws-active-slide"));
353 var to_slide_num = self.getCurrentSlide();
354 var watch_slide_anim = false;
355 var to_slide = $(canvas[to_slide_num]);
356 var from_slide = $(canvas[from_slide_num]);
357 var slide_change = (from_slide_num != to_slide_num);
360 var info = to_slide.data("sws-frame-info");
361 SWS.Config['sws-update-header'](to_slide);
362 SWS.Config['sws-update-footer'](to_slide);
365 //Launch a slide transition:
366 SWS.Config['sws-slide-change'](from_slide_num, to_slide_num);
367 watch_slide_anim = true;
368 for (var i = 0; i < info.callbacks.at_slide.length;i++){
369 info.callbacks.at_slide[i](to_slide);
374 var cur = info.current;
375 var custom = info.custom;
376 var real_slide = to_slide.find(".sws-slide");
377 var dont_touch = real_slide.find("sws-protect").find("*").addBack();
378 real_slide.find("*").addBack().not(dont_touch).each(function (i){
379 var frameset = $(this).data("sws-frame-set") || {};
381 SWS.Config['sws-object-activate']($(this));
383 SWS.Config['sws-object-deactivate']($(this));
387 var all = $(from_slide).add(to_slide);
388 all.find("*").addBack().promise().done(function() {
390 //execute callbacks when all elements are finished transitioning
391 if (callbacks = info.callbacks.at_frame[self.getCurrentFrame()]){
392 for (var k = 0; k < callbacks.length; k++)
393 callbacks[k]($(to_slide));
395 all.find("*").addBack().promise().done(function() {
396 //wait for all elements to finish transitionning, in case a callback animate something
397 //and enable _input_events again.
398 _disable_input_events = false;
403 self.nextSlide = function () {
404 self.setCurrentSlide(Math.min(self.getCurrentSlide()+1,
406 self.setCurrentFrame(self.firstFrame());
409 self.previousSlide = function () {
410 self.setCurrentSlide(Math.max(self.getCurrentSlide()-1,
412 self.setCurrentFrame(self.firstFrame());
415 self.getFrameInfo = function () {
417 var i = self.getCurrentSlide();
418 var canvas = $($(".sws-canvas")[i]);
419 var infos = canvas.data("sws-frame-info");
423 self.getTotalSteps = function () {
424 if (_total_steps >= 0) return _total_steps;
426 $(".sws-canvas").each(function(i) {
427 var canvas = $($(".sws-canvas")[i]);
428 var infos = canvas.data("sws-frame-info");
429 _total_steps += infos.last + 1;
434 self.getCurrentFrame = function () { return self.getFrameInfo().current; };
435 self.setCurrentFrame = function (i) { self.getFrameInfo().current = i; };
436 self.firstFrame = function () { return 0; };
437 self.lastFrame = function () { return self.getFrameInfo().last; };
439 self.nextFrame = function () {
440 self.setCurrentFrame(Math.min(self.getCurrentFrame()+1,
444 self.previousFrame = function () {
445 self.setCurrentFrame(Math.max(self.getCurrentFrame()-1,
449 self.next = function () {
450 var i = self.getCurrentFrame();
451 if (i == self.lastFrame()) {
453 self.setCurrentFrame(self.firstFrame());
458 self.previous = function () {
459 var i = self.getCurrentFrame();
460 if (i == self.firstFrame()){
461 self.previousSlide();
462 self.setCurrentFrame(self.lastFrame());
465 self.previousFrame();
468 self.goToSlide = function (s, f) {
469 if (SWS.Utils.isUndefined(f))
471 if (!(s >= self.firstSlide() && s <= self.lastSlide())) return;
472 self.setCurrentSlide(s);
473 if (!(f >= self.firstFrame() && f <= self.lastFrame())) f = 0;
474 self.setCurrentFrame(f);
478 self.cycleStyle = function() {
479 var styles = $("head").children('link[rel$="stylesheet"][title]');
480 var j = styles.index(styles.filter(':not(:disabled)'));
481 styles[j].disabled = true;
482 if (++j == styles.length) j = 0;
483 styles[j].disabled = false;
487 self.printMode = function () {
490 var old_fx_status = $.fx.off;
491 //disable animation while printing.
494 var progress = $("<div style='position:fixed;top:0pt;left:0pt;background:white;color:black;width:100%;height:100vh;z-index:200;' id='sws-print-progress'>Rendering presentation: <span id='sws-percent-progress'></span>%</div>");
495 $("body").append(progress);
497 $("html").removeClass("sws-display").addClass("sws-print");
499 var steps = self.getTotalSteps();
500 var total_steps = steps;
504 //Crazy workaround for chromium
505 ($("link.sws-theme[rel='stylesheet']")[0]).disabled = false;
506 $(".sws-canvas").find("*").addBack().promise().done(function() {
507 var percent = ((total_steps - steps) / total_steps) * 100;
508 $("#sws-percent-progress").text(Math.round(percent));
509 SWS.Config['sws-slide-change'] = SWS.Templates.slideChange;
511 $($(".sws-canvas")[self.getCurrentSlide()]).css('opacity', 1 );
517 $("#sws-percent-progress").text(100);
519 window.status = 'Ready';
520 $.fx.off = old_fx_status;
528 self.buildFullTOC = function () {
530 var build_sections = function (doc) {
532 var h1s = doc.find("body").first().children("h1");
533 var slides = doc.find("body").first().children(".sws-slide");
535 var collection = h1s.add(slides);
536 collection.each (function () {
537 if ($(this).is("h1")) {
538 res.push({ 'title' : $(this).text(),
539 'slide' : slide_num });
549 var append = function (a,e) {
552 var prepend = function (a,e) {
556 var loop = function (doc, dir, add, ignoreFirst) {
557 if (ignoreFirst !== true) {
558 var this_toc = { 'title' : doc.find("title").first().text()
559 .replace ("&", "&")
560 .replace("'","'")
561 .replace('"', """)
562 .replace("<", "<")
563 .replace(">", ">"),
564 'sections' : build_sections(doc) };
567 var url = doc.find(dir).first().attr("href");
568 if (!SWS.Utils.isUndefined(url) && url != "") {
569 $.ajax({ 'url' : url, 'async' : false ,'success' : function (page) {
570 loop ($(page), dir, add, false);
574 loop ($(document), ".sws-previous", prepend, false);
581 var _startTouch = null;
583 self.inputHandler = function (event) {
584 if (_disable_input_events || _print_mode) return;
586 switch (event.type) {
588 _startTouch = event.changedTouches[0];
591 if (!_startTouch) return;
592 var _endTouch = event.changedTouches[0];
593 var Xdist = _endTouch.clientX - _startTouch.clientX;
594 var Ydist = _endTouch.clientY - _startTouch.clientY;
595 if (Xdist > 40) code = 39
596 else if (Xdist < -40) code = 37
597 else if (Ydist > 20 && !$("#sws-control-panel-canvas").is(":visible")) code = 67;
598 else if (Ydist < -20 && $("#sws-control-panel-canvas").is(":visible")) code = 67;
610 self.setCurrentSlide(self.firstSlide());
614 self.setCurrentSlide(self.lastSlide());
617 case 34: /* PgDown */
619 case 176: /* Multimedia skip forward */
620 case 179: /* Multimedia play/pause */
621 if (self.getCurrentSlide() == self.lastSlide()
622 && self.getCurrentFrame() == self.lastFrame()) return;
628 case 8: /* backspace */
631 case 177: /* Multimedia skip backward */
635 self.previousSlide();
641 $("#sws-control-panel-canvas").toggle();
644 $("#sws-help-panel-canvas").toggle();
654 function init_canvas(canvas, custom) {
656 var last_frame = canvas.find(".sws-pause").length;
657 //Add all regular elements to the frame list
658 var slide = $(canvas.find(".sws-slide")[0]);
660 var callbacks = { at_slide : new Array(),
661 at_frame : new Array() }
663 if (SWS.Utils.isUndefined(custom)) {
664 custom = new Array ();
667 for (var i = 0; i < custom.length; i++) {
668 if (isFinite(custom[i].frame)){
669 var num = +(custom[i].frame);
670 if (num > last_frame) last_frame = num;
671 SWS.Utils.push2(callbacks.at_frame, num, custom[i].fn);
672 } else if (custom[i].frame == "slide")
673 callbacks.at_slide.push(custom[i].fn);
675 var frame_set = SWS.Utils.parseFrameSpec(custom[i].frame);
676 for(var f in frame_set){
677 if (f > last_frame) last_frame = f;
678 SWS.Utils.push2(callbacks.at_frame, +(f), custom[i].fn);
683 var specials = $([]);
685 slide.find('*[class*="sws-onframe-"]').each(function(_){
686 var cls = $(this).attr('class');
687 var idx = cls.indexOf("sws-onframe-");
689 var end = cls.indexOf(" ", idx);
690 end = (end == -1) ? cls.length : end;
691 var spec = cls.substring(idx+12, end);
692 var o = SWS.Utils.parseFrameSpec(spec);
694 if (f > last_frame) last_frame = f;
695 $(this).find("*").andSelf().each(function(_){
696 if (!SWS.Utils.isEmpty(o)){
697 $(this).data("sws-frame-set", o);
699 specials = specials.add($(this));
704 slide.find("*").andSelf().not(specials).each(function(i) {
705 if ($(this).hasClass("sws-pause")) cur_frame++;
707 for (var j = cur_frame; j <= last_frame; j++)
709 if (!SWS.Utils.isEmpty(o))
710 $(this).data("sws-frame-set", o);
713 canvas.data("sws-frame-info", { current: 0,
714 last: (last_frame - 0), // force cast to integer
720 /* Forces redrawing the page without reloading */
721 self.redraw = function (f) {
722 if (SWS.Utils.isUndefined(f))
723 $("body").hide().show(400, function () {
724 $("body").css("display","block");
725 if (!SWS.Utils.isUndefined(f))
729 self.changeAspect = function() {
730 if (_print_mode) return;
731 var newClass = $("#sws-aspect-select").val();
732 var args = newClass.split("-");
733 var targetRatio = (args[2] - 0) / (args[3] - 0);
734 var realRatio = window.innerWidth / window.innerHeight;
735 var byClass = (targetRatio > realRatio ) ? "sws-by-height" : "sws-by-width";
736 if ($("html").hasClass(newClass)
737 && $("html").hasClass(byClass))
740 $("html").removeClass("sws-aspect-4-3")
741 .removeClass("sws-aspect-16-9")
742 .removeClass("sws-aspect-16-10")
743 .removeClass("sws-by-width")
744 .removeClass("sws-by-height")
745 .addClass(newClass).addClass(byClass);
749 self.getCurrentTheme = function () {
750 var l = $("link.sws-theme[rel='stylesheet']")[0];
758 self.changeTheme = function (name) {
760 if (typeof name === 'undefined')
761 theme_name = $("#sws-theme-select").val()
765 _current_theme = theme_name;
766 $("link.sws-theme").each (function (i) {
769 if (title == theme_name) {
770 e.rel = "stylesheet";
774 e.rel = "alternate stylesheet";
783 self.openPrint = function () {
784 window.open ("?mode=print&theme=" + self.getCurrentTheme());
786 var _fullscreen_icon_on = "";
787 var _fullscreen_icon_off = "";
789 self.toggleFullScreen = function () {
790 if (SWS.Fullscreen.status()) {
791 SWS.Fullscreen.exit();
792 $("a#sws-control-panel-fullscreen")
793 .html(_fullscreen_icon_off);
798 SWS.Fullscreen.enter($("body")[0]);
799 $("a#sws-control-panel-fullscreen")
800 .html(_fullscreen_icon_on);
803 function _update_ui() {
804 var nav = $('#sws-control-panel-navigation-bar');
805 nav.val(SWS.Presentation.getCurrentSlide() + 1);
806 $('#sws-control-panel-slide-input').val(nav.val());
808 self.navigate = function () {
809 self.goToSlide($("#sws-control-panel-navigation-bar").val()-1);
814 self.init = function () {
817 $("html").addClass("sws-display");
818 //$(window).resize(self.redraw);
820 var slides = $(".sws-slide");
821 var h1s = $("body").children("h1");
822 var slide_num = slides.add(h1s).length - 1;
824 _total_slides = $(".sws-slide").add($("body").children("h1")).length;
826 var cur = self.getCurrentSlide();
827 var toc = self.buildFullTOC();
828 var common_html = "<div class='sws-slide sws-toc'><h1>Plan</h1><ul style='list-style-type:none'>";
830 for (i= 0; i < toc.length - 1; i++)
831 common_html += "<li class='done'>" + (i+1) +
832 ' ' + toc[i].title + "</li>";
834 common_html += "<li>" + toc.length + ' ' + toc[toc.length - 1].title;
835 common_html += "<ul style='list-style-type:none' >";
836 var sections = toc[toc.length - 1].sections;
837 $("body").children("h1").each(function (i) {
838 var this_html = common_html;
840 var secnum = toc.length + '.';
841 for (j = 0; j < i; ++j)
842 this_html += "<li class='done'>" + secnum + (j+1) + ' ' +
843 sections[j].title + "</li>";
844 this_html += "<li class='hl'>" + secnum + (i+1) + ' ' +
845 sections[i].title + "</li>";
846 for (j = i+1; j < sections.length; j++)
847 this_html += "<li>" + secnum + (j+1) + ' '
848 +sections[j].title + "</li>";
849 this_html += "</ul></li></ul></div>";
850 $(this).after(this_html);
853 $(".sws-slide").each(function (i) {
855 var par = $(this).parent();
859 var canvas = $('<div class="sws-canvas"/>');
861 if (!($(this).hasClass("sws-option-noheader"))) {
862 canvas.append($('<div class="sws-header"/>'));
865 if (!$(this).hasClass("sws-cover")) {
866 var title = $($(this).find("h1")[0]);
867 var title_div = $('<div class="sws-title" />');
868 title_div.append(title);
869 canvas.append(title_div);
872 var inner = $('<div class="sws-inner-canvas"/>');
873 var content = $('<div class="sws-content"/>');
874 $(this).find('script[type="text/javascript"]').remove();
875 content.append($(this));
876 inner.append(content);
877 canvas.append(inner);
879 [ "sws-cover", "sws-toc" ].forEach(
881 if ($(that).hasClass(v)) {
883 $(that).removeClass(v);
887 if (!($(this).hasClass("sws-option-nofooter"))) {
888 canvas.append($('<div class="sws-footer"/>'));
895 .addClass("sws-active-slide")
896 .removeClass("sws-inactive-slide");
899 .addClass("sws-inactive-slide")
900 .removeClass("sws-active-slide");
902 init_canvas(canvas,_slide_callbacks[i]);
906 // Initialize the control panel
907 $("body").append($(SWS.Templates.controlPanel));
908 $("body").append($(SWS.Templates.helpPanel));
909 // Fill the theme switcher
910 $("link.sws-theme").each (function (i) {
912 var opt = "<option value='";
913 opt += e.attr("title");
915 if (e.attr("rel") == "stylesheet") {
916 opt+= "selected='selected'";
918 opt += ">" + e.attr("title") + "</option>";
919 $("#sws-theme-select").append($(opt));
921 // Set the fullscreen icon
922 if (SWS.Fullscreen.status()) {
923 $("a#sws-control-panel-fullscreen")
924 .html(_fullscreen_icon_on);
926 $("a#sws-control-panel-fullscreen")
927 .html(_fullscreen_icon_off);
929 // Put the navigation range at the correct position
930 var nav = $('#sws-control-panel-navigation-bar');
931 nav.attr("min", SWS.Presentation.firstSlide() + 1);
932 nav.attr("max", SWS.Presentation.lastSlide() + 1);
933 $('#sws-control-panel-total-slides').text('/' + SWS.Presentation.getNumSlides());
935 _slide_callbacks = null; /* avoid a leak */
936 var passed_theme = SWS.Utils.getParameterByName("theme");
939 //workaround weird chrome CSS loading bug
942 if (passed_theme == "")
945 self.changeTheme(passed_theme);
946 if (SWS.Utils.getParameterByName("mode") == "print") {
950 if (self.showHelpAtStartup()) $("#sws-help-panel-canvas").show().delay(5000).hide();
954 $(document).keydown(self.inputHandler);
955 document.body.addEventListener('touchstart',self.inputHandler, false);
956 document.body.addEventListener('touchend',self.inputHandler, false);
957 $(window).resize(self.changeAspect);
960 //setTimeout(f, 100);