X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=simpleWebSlides.js;h=c63bf25f53c1cb0a94706a46f2f96e5d8d020200;hb=4ca69fdef3daa22ecd2bfae66aa65633e0dc1434;hp=cd19624cf316dee042f6d07275414fc69b945aa1;hpb=0bd2fb253ff8486acc783de47465ea223e54d952;p=hacks%2FsimpleWebSlides.git diff --git a/simpleWebSlides.js b/simpleWebSlides.js index cd19624..c63bf25 100644 --- a/simpleWebSlides.js +++ b/simpleWebSlides.js @@ -57,6 +57,19 @@ SWS.Utils = new function () { SWS.Templates = new function () { var self = this; + self.helpPanel = "
\ +

Keyboard shortcuts

\ +\ +\ +\ +\ +\ +\ +\ +\ +\ +
c toggle the control panel
Left, PgUp,swipe left previous step
Right, PgDown, Space, swipe right next step
p previous slide
n next slide
Home first slide
End last slide
h toggle help
\ +
"; self.controlPanel = "
\
\ \ @@ -152,6 +165,7 @@ SWS.Effects = new function () { var self = this; self.objectDeactivateFadeOut = function (o) { + if (o.is("embed")) return; o.animate({'opacity': '0'}, 200, function () { @@ -293,8 +307,9 @@ SWS.Presentation = new function () { if (_initialized) return; //jQuery does not seem to work well //on a partial DOM - - var slide_num = $(".sws-slide").length - 1; + var slides = $(".sws-slide"); + var h1s = $("body").children("h1"); + var slide_num = slides.add(h1s).length - 1; SWS.Utils.push2(_slide_callbacks, slide_num,{ 'fn': f, 'frame': i }); @@ -315,11 +330,18 @@ SWS.Presentation = new function () { sessionStorage.setItem("current_slide", i); }; + self.showHelpAtStartup = function () { + var r = sessionStorage.getItem("show_help"); + if (r == "hide") return false; + sessionStorage.setItem("show_help", "hide"); + return true; + }; + } else { var _current_slide = 0; self.getCurrentSlide = function () { return _current_slide; }; self.setCurrentSlide = function (i) { _current_slide = i; }; - + self.showHelpAtStartup = function () { return false; }; }; self.firstSlide = function () { return 0; }; self.lastSlide = function () { return self.getNumSlides() - 1; }; @@ -353,23 +375,29 @@ SWS.Presentation = new function () { var cur = info.current; var custom = info.custom; var real_slide = to_slide.find(".sws-slide"); - - real_slide.find("*").andSelf().each(function (i){ + var dont_touch = real_slide.find("sws-protect").find("*").addBack(); + real_slide.find("*").addBack().not(dont_touch).each(function (i){ var frameset = $(this).data("sws-frame-set") || {}; if (frameset[cur]) SWS.Config['sws-object-activate']($(this)); else SWS.Config['sws-object-deactivate']($(this)); }); - var callbacks; - if (callbacks = info.callbacks.at_frame[self.getCurrentFrame()]){ - for (var k = 0; k < callbacks.length; k++) - callbacks[k]($(to_slide)); - }; + var all = $(from_slide).add(to_slide); all.find("*").addBack().promise().done(function() { - _disable_input_events = false; + var callbacks; + //execute callbacks when all elements are finished transitioning + if (callbacks = info.callbacks.at_frame[self.getCurrentFrame()]){ + for (var k = 0; k < callbacks.length; k++) + callbacks[k]($(to_slide)); + }; + all.find("*").addBack().promise().done(function() { + //wait for all elements to finish transitionning, in case a callback animate something + //an denable _input_events again. + _disable_input_events = false; + }); }); }; @@ -484,12 +512,60 @@ SWS.Presentation = new function () { } else { $("#sws-percent-progress").text(100); progress.remove(); + window.status = 'Ready'; } }; loop(); } + self.buildFullTOC = function () { + + var build_sections = function (doc) { + var res = []; + var h1s = doc.find("body").first().children("h1"); + var slides = doc.find("body").first().children(".sws-slide"); + var slide_num = 1; + var collection = h1s.add(slides); + collection.each (function () { + if ($(this).is("h1")) { + res.push({ 'title' : $(this).text(), + 'slide' : slide_num }); + } else { + slide_num++; + } + }); + return res; + }; + + var toc = []; + + var append = function (a,e) { + return a.push(e); + }; + var prepend = function (a,e) { + return a.unshift(e); + }; + + var loop = function (doc, dir, add, ignoreFirst) { + if (ignoreFirst !== true) { + var this_toc = { 'title' : doc.find("title").first().text(), + 'sections' : build_sections(doc) }; + add(toc, this_toc); + }; + var url = doc.find(dir).first().attr("href"); + if (!SWS.Utils.isUndefined(url) && url != "") { + $.ajax({ 'url' : url, 'async' : false ,'success' : function (page) { + loop ($(page), dir, add, false); + }}); + }; + }; + loop ($(document), ".sws-previous", prepend, false); + return toc; + + }; + + var _xstart = 0; self.inputHandler = function (event) { @@ -512,6 +588,7 @@ SWS.Presentation = new function () { default: return; }; + switch (code) { case 36:/* Home */ self.setCurrentSlide(self.firstSlide()); @@ -543,6 +620,9 @@ SWS.Presentation = new function () { return; case 67: /* c */ $("#sws-control-panel-canvas").toggle(); + return; + case 72: /* h */ + $("#sws-help-panel-canvas").toggle(); default: return; @@ -706,11 +786,38 @@ SWS.Presentation = new function () { $("html").addClass("sws-display"); //$(window).resize(self.redraw); + var slides = $(".sws-slide"); + var h1s = $("body").children("h1"); + var slide_num = slides.add(h1s).length - 1; - - _total_slides = $(".sws-slide").length; + _total_slides = $(".sws-slide").add($("body").children("h1")).length; var cur = self.getCurrentSlide(); + var toc = self.buildFullTOC(); + var common_html = "

Plan

    "; + var i; + for (i= 0; i < toc.length - 1; i++) + common_html += "
  • " + (i+1) + + ' ' + toc[i].title + "
  • "; + + common_html += "
  • " + toc.length + ' ' + toc[toc.length - 1].title; + common_html += "
      "; + var sections = toc[toc.length - 1].sections; + $("body").children("h1").each(function (i) { + var this_html = common_html; + var j; + var secnum = toc.length + '.'; + for (j = 0; j < i; ++j) + this_html += "
    • " + secnum + (j+1) + ' ' + + sections[j].title + "
    • "; + this_html += "
    • " + secnum + (i+1) + ' ' + + sections[i].title + "
    • "; + for (j = i+1; j < sections.length; j++) + this_html += "
    • " + secnum + (j+1) + ' ' + +sections[j].title + "
    • "; + this_html += "
"; + $(this).after(this_html); + }); $(".sws-slide").each(function (i) { @@ -757,6 +864,7 @@ SWS.Presentation = new function () { // Initialize the control panel $("body").append($(SWS.Templates.controlPanel)); + $("body").append($(SWS.Templates.helpPanel)); // Fill the theme switcher $("link.sws-theme").each (function (i) { var e = $(this); @@ -783,9 +891,10 @@ SWS.Presentation = new function () { nav.attr("max", SWS.Presentation.lastSlide() + 1); $('#sws-control-panel-total-slides').text('/' + SWS.Presentation.getNumSlides()); _update_ui(); - _slide_callbacks = null; /* avoid a leak */ var passed_theme = SWS.Utils.getParameterByName("theme"); + + //workaround weird chrome CSS loading bug var f = function () { @@ -796,12 +905,14 @@ SWS.Presentation = new function () { if (SWS.Utils.getParameterByName("mode") == "print") { self.printMode(); } - else + else { + if (self.showHelpAtStartup()) $("#sws-help-panel-canvas").show(); self.refresh(); + }; $(document).keydown(self.inputHandler); document.body.addEventListener('touchstart',self.inputHandler, false); document.body.addEventListener('touchend',self.inputHandler, false); - + _initialized = true; }; setTimeout(f, 100);