X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;ds=sidebyside;f=simpleWebSlides.js;h=6229a74fb7b68d420e6c0d58670f70cbe004c3f4;hb=ad268c9cd746bf3c74c379055ea0c3518353882a;hp=e592eb869e49806ba6f2c5668166d7052dbfa499;hpb=ac79fe8adf86a2e4ddd1ddf2d16e4e8809d8ea58;p=hacks%2FsimpleWebSlides.git diff --git a/simpleWebSlides.js b/simpleWebSlides.js index e592eb8..6229a74 100644 --- a/simpleWebSlides.js +++ b/simpleWebSlides.js @@ -2,7 +2,7 @@ Namespace object. */ -var SWS = {}; +var SWS = SWS || {}; @@ -18,7 +18,72 @@ SWS.Utils = new function () { t[i][l] = v; }; + self.isEmpty = function (o) { + for(var _ in o) return false; + return true; + }; + + self.parseFrameSpec = function (s) { + var elems = s.split("_"); + var result = {}; + var min_last = 10000; + var max_value = -1; + for(var i = 0; i < elems.length; i++){ + var bounds = elems[i].split("-"); + if (bounds.length > 2 || bounds.length == 0) return {}; + if (bounds.length == 1) bounds[1] = bounds[0]; + var a = parseInt(bounds[0]); + var b = parseInt(bounds[1]) + if (!isFinite(a) || !isFinite(b)) return {}; + a = Math.min(a, 1000); // don't allow more than 1000 frames/slide + b = Math.min(b, 1000); + if (b > max_value) max_value = b; + for (var j = a; j <= b; j++) + result[j] = true; + }; + return result; + }; + + self.getParameterByName = function (name) { + name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); + var regex = new RegExp("[\\?&]" + name + "=([^]*)"), + results = regex.exec(location.search); + return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); + } +}; + + + +SWS.Templates = new function () { + var self = this; + self.controlPanel = "
"; self.slideActivate = function (o) { if (!(o.hasClass("sws-active-slide"))){ o.removeClass("sws-inactive-slide").addClass("sws-active-slide"); @@ -41,15 +106,19 @@ SWS.Utils = new function () { if (!(o.hasClass("sws-active-object"))){ o.removeClass("sws-inactive-object").addClass("sws-active-object"); o.css({'visibility':'visible'}); + return true; }; + return false; }; self.objectDeactivate = function (o) { - o.css({'visibility':'hidden', 'display':''}); if (!(o.hasClass("sws-inactive-object"))){ o.addClass("sws-inactive-object").removeClass("sws-active-object"); + return true; }; + return false; }; + self.updateFooter = function (o) { var footer = o.find(".sws-footer"); if (footer.length && (footer.children("*").length == 0)) { @@ -58,7 +127,7 @@ SWS.Utils = new function () { + (i + 1) +""); var sep = $( ""); - var tot = $( "" + var tot = $( "" + (SWS.Presentation.getNumSlides()) +""); footer.append(cur).append(sep).append(tot); @@ -66,31 +135,76 @@ SWS.Utils = new function () { }; self.updateHeader = function (o) {}; }; +SWS.ConfigBuilder = function () { + var self = this; + self['sws-object-activate'] = SWS.Templates.objectActivate; + self['sws-object-deactivate'] = SWS.Templates.objectDeactivate; + self['sws-slide-change'] = SWS.Templates.slideChange; + self['sws-update-footer'] = SWS.Templates.updateFooter; + self['sws-update-header'] = SWS.Templates.updateHeader; +}; + +SWS.Defaults = new SWS.ConfigBuilder (); + +SWS.Config = new SWS.ConfigBuilder (); SWS.Effects = new function () { var self = this; + self.objectDeactivateFadeOut = function (o) { - o.fadeOut(150, function () { SWS.Utils.objectDeactivate(o)}); + o.animate({'opacity': '0.1'}, 200, + function () { SWS.Templates.objectDeactivate(o)}); }; self.objectActivateFadeIn = function (o) { - SWS.Utils.objectActivate(o); - o.fadeIn(150); + + if (SWS.Templates.objectActivate(o)){ + o.animate({'opacity': '1' }, 200); + }; + }; + self.slideChangeHorizontalFlip = function (from, to){ + var f = SWS.Presentation.getSlide(from); + var t = SWS.Presentation.getSlide(to); + f.animate({ 'left': '50%', 'width': '0pt', 'opacity':'0.2' }, 150, + function () { + SWS.Templates.slideDeactivate(f); + f.css({'left':'0%', 'width': '100%'}); + t.css({ 'left': '50%', 'width': '0pt','opacity':'0.3' }); + SWS.Templates.slideActivate(t); + t.animate({'left':'0%', 'width': '100%','opacity':'1'}); + }); + }; + self.slideChangeFadeOutIn = function (from, to) { + var f = SWS.Presentation.getSlide(from); + var t = SWS.Presentation.getSlide(to); + f.animate({ 'opacity': '0.4'}, 150, + function () { SWS.Templates.slideDeactivate(f); + SWS.Templates.slideActivate(t); + t.css('opacity', '0.5'); + t.animate({ 'opacity': '1'}, 150); + }); + }; self.slideChangeHorizontalSlide = function (from, to) { var f = SWS.Presentation.getSlide(from); var t = SWS.Presentation.getSlide(to); if (from < to) { t.css('left', '100%'); - SWS.Utils.slideActivate(t); - f.animate({ 'left': '-100%' }, 250, function () { SWS.Utils.slideDeactivate(f); }); - t.animate({ 'left': '0%' }, 250); + t.css('opacity', '1'); + SWS.Templates.slideActivate(t); + f.animate({ 'left': '-100%' }, 250, function () { SWS.Templates.slideDeactivate(f); + f.css('opacity', '0.6'); + t.animate({ 'left': '0%' }, 250); + }); } else { t.css('left', '-100%'); - SWS.Utils.slideActivate(t); - f.animate({ 'left': '100%' }, 250, function () { SWS.Utils.slideDeactivate(f); }); + SWS.Templates.slideActivate(t); + f.animate({ 'left': '100%' }, 250, function () { SWS.Templates.slideDeactivate(f); + f.css('opacity', '0.7'); + }); + t.css('opacity', '1'); t.animate({ 'left': '0%' }, 250); }; }; @@ -101,74 +215,71 @@ SWS.Effects = new function () { var t = SWS.Presentation.getSlide(to); if (from < to) { t.css('top', '100%'); - SWS.Utils.slideActivate(t); - f.animate({ 'top': '-100%' }, 250, function () { SWS.Utils.slideDeactivate(f); }); + SWS.Templates.slideActivate(t); + f.animate({ 'top': '-100%' }, 250, function () { SWS.Templates.slideDeactivate(f); }); t.animate({ 'top': '0%' }, 250); } else { t.css('top', '-100%'); - SWS.Utils.slideActivate(t); - f.animate({ 'top': '100%' }, 250, function () { SWS.Utils.slideDeactivate(f); }); + SWS.Templates.slideActivate(t); + f.animate({ 'top': '100%' }, 250, function () { SWS.Templates.slideDeactivate(f); }); t.animate({ 'top': '0%' }, 250); }; }; }; -/* - Representation of intervals of positive integers. - -SWS.Interval = new function (init) { - +SWS.Fullscreen = new function () { var self = this; - self.data = new Array(); - self.parseString(s) { - var elems = s.split("_"); - for(var i = 0; i < elems.length; i++){ - var bounds = elems[i].split("-"); - if (bounds.length > 2) continue; - if (SWS.isUndefined(bounds[1])) bounds[1] = bounds[0]; - if (!(isFinite(bounds[0]) && isFinite(bounds[1]))) continue; - - self.add(+(bounds[0]), +(bounds[1])); - }; -7C - }; - self.add(x, y) { - if (SWS.isUndefined(y) && isFinite(x)) self.add(x,x); + if (SWS.Utils.isUndefined(document.fullScreen)) { + if (SWS.Utils.isUndefined(document.mozfullScreen)) { + self.status = function () { return document.webkitIsFullScreen; }; + self.enter = function(e) { + e.webkitRequestFullScreen(); + }; + self.exit = function () { + document.webkitCancelFullScreen(); + }; + } else { + self.status = function () { return document.mozfullScreen; }; + self.enter = function(e) { + e.mozRequestFullScreen(); + }; + self.exit = function () { + document.mozCancelFullScreen(); + }; + }; + } else { + self.status = function () { return document.fullScreen; }; + self.enter = function(e) { + e.requestFullScreen(); + }; + self.exit = function () { + document.cancelFullScreen(); + }; }; -5B - }; }; -*/ SWS.Presentation = new function () { var self = this; - var templates = {}; + //TODO move outside of the Presentation object - //TODO: clean-up; var _total_slides; var _initialized = false; - var _animations_running = false; - + var _disable_input_events = false; + var _print_mode = false; var _slide_callbacks = new Array (); - - - - - //Public methods - self.setTemplate = function (tn, fn) { - templates[tn] = fn; - }; + var _total_steps = -1; + var _current_theme = ""; self.getNumSlides = function () { return _total_slides; }; @@ -190,7 +301,7 @@ SWS.Presentation = new function () { if (typeof(Storage)!=="undefined"){ self.getCurrentSlide = function () { //unary + casts to integer - var i = +(sessionStorage.current_slide); + var i = +(sessionStorage.getItem("current_slide")); if (!(i >= 0 && i < self.getNumSlides())){ return 0; } else { @@ -199,7 +310,7 @@ SWS.Presentation = new function () { }; self.setCurrentSlide = function (i) { - sessionStorage.current_slide = i; + sessionStorage.setItem("current_slide", i); }; } else { @@ -210,25 +321,27 @@ SWS.Presentation = new function () { }; self.firstSlide = function () { return 0; }; self.lastSlide = function () { return self.getNumSlides() - 1; }; - self.refresh = function () { - /* block upcoming input event until all animation are finished */ - _animations_running = true; + /* block upcoming input event until all animations are finished */ + _disable_input_events = true; var canvas = $(".sws-canvas"); var from_slide_num = canvas.index($(".sws-active-slide")); var to_slide_num = self.getCurrentSlide(); var watch_slide_anim = false; var to_slide = $(canvas[to_slide_num]); - var slide_change = !_initialized || (from_slide_num != to_slide_num); + var from_slide = $(canvas[from_slide_num]); + var slide_change = (from_slide_num != to_slide_num); + var info = to_slide.data("sws-frame-info"); + SWS.Config['sws-update-header'](to_slide); + SWS.Config['sws-update-footer'](to_slide); + if (slide_change) { //Launch a slide transition: - templates['sws-slide-change'](from_slide_num, to_slide_num); + SWS.Config['sws-slide-change'](from_slide_num, to_slide_num); watch_slide_anim = true; - templates['sws-update-header'](to_slide); - templates['sws-update-footer'](to_slide); for (var i = 0; i < info.callbacks.at_slide.length;i++){ info.callbacks.at_slide[i](to_slide); }; @@ -237,14 +350,14 @@ SWS.Presentation = new function () { var cur = info.current; var custom = info.custom; - var real_slide = to_slide.children(".sws-slide"); - real_slide.find("*").add(real_slide).each (function (i) { - var fcur = "f" + cur; + var real_slide = to_slide.find(".sws-slide"); + + real_slide.find("*").andSelf().each(function (i){ var frameset = $(this).data("sws-frame-set") || {}; - if (frameset[fcur]) - templates['sws-object-activate']($(this)); + if (frameset[cur]) + SWS.Config['sws-object-activate']($(this)); else - templates['sws-object-deactivate']($(this)); + SWS.Config['sws-object-deactivate']($(this)); }); var callbacks; @@ -253,24 +366,22 @@ SWS.Presentation = new function () { callbacks[k]($(to_slide)); }; - var to_watch = $(to_slide).find("*"); - if (watch_slide_anim) { - to_watch = to_watch.add(to_slide).add($(canvas[from_slide_num])); - }; - - to_watch.find("*").promise().done(function() { - _animations_running = false; + var all = $(from_slide).add(to_slide); + all.find("*").addBack().promise().done(function() { + _disable_input_events = false; }); }; self.nextSlide = function () { self.setCurrentSlide(Math.min(self.getCurrentSlide()+1, self.lastSlide())); + self.setCurrentFrame(self.firstFrame()); }; self.previousSlide = function () { self.setCurrentSlide(Math.max(self.getCurrentSlide()-1, self.firstSlide())); + self.setCurrentFrame(self.firstFrame()); }; self.getFrameInfo = function () { @@ -280,6 +391,19 @@ SWS.Presentation = new function () { var infos = canvas.data("sws-frame-info"); return infos; }; + + self.getTotalSteps = function () { + if (_total_steps >= 0) return _total_steps; + _total_steps = 0; + $(".sws-canvas").each(function(i) { + var canvas = $($(".sws-canvas")[i]); + var infos = canvas.data("sws-frame-info"); + console.log(infos); + _total_steps += infos.last + 1; + }); + return _total_steps; + }; + self.getCurrentFrame = function () { return self.getFrameInfo().current; }; self.setCurrentFrame = function (i) { self.getFrameInfo().current = i; }; self.firstFrame = function () { return 0; }; @@ -297,48 +421,109 @@ SWS.Presentation = new function () { self.next = function () { var i = self.getCurrentFrame(); - if (i == self.lastFrame()) + if (i == self.lastFrame()) { self.nextSlide(); - else + self.setCurrentFrame(self.firstFrame()); + } else self.nextFrame(); }; self.previous = function () { var i = self.getCurrentFrame(); - if (i == self.firstFrame()) + if (i == self.firstFrame()){ self.previousSlide(); + self.setCurrentFrame(self.lastFrame()); + } else self.previousFrame(); }; + self.goToSlide = function (s, f) { + if (SWS.Utils.isUndefined(f)) + f = 0; + if (!(s >= self.firstSlide() && s <= self.lastSlide())) return; + self.setCurrentSlide(s); + if (!(f >= self.firstFrame() && f <= self.lastFrame())) f = 0; + self.setCurrentFrame(f); + self.refresh(); + }; + + self.cycleStyle = function() { + var styles = $("head").children('link[rel$="stylesheet"][title]'); + var j = styles.index(styles.filter(':not(:disabled)')); + styles[j].disabled = true; + if (++j == styles.length) j = 0; + styles[j].disabled = false; + }; + + + self.printMode = function () { + _print_mode = true; + var progress = $("