Namespace object.
*/
-var SWS = {};
+var SWS = SWS || {};
-/* Utility functions */
-SWS.isUndefined = function (o) { return typeof o == "undefined"; };
-/*
- Representation of intervals of positive integers.
-
-SWS.Interval = new function (init) {
+SWS.Utils = new function () {
var self = this;
- self.data = new Array();
- self.parseString(s) {
+
+ self.isUndefined = function (o) { return typeof o == "undefined"; };
+ self.push2 = function (t, i, v) {
+ if ((typeof t[i]) == 'undefined') {
+ t[i] = new Array();
+ };
+ var l = t[i].length;
+ 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) continue;
- if (SWS.isUndefined(bounds[1])) bounds[1] = bounds[0];
- if (!(isFinite(bounds[0]) && isFinite(bounds[1]))) continue;
-
- self.add(+(bounds[0]), +(bounds[1]));
+ 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.add(x, y) {
- if (SWS.isUndefined(y) && isFinite(x)) self.add(x,x);
+
+ 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 = "<div id='sws-control-panel-canvas'><div id='sws-control-panel'>\
+<div id='sws-control-panel-title-bar'>\
+<a title='Toggle fullscreen' id='sws-control-panel-fullscreen' class='sws-symbol' onclick='SWS.Presentation.toggleFullScreen();'></a>\
+<a title='Close panel' id='sws-control-panel-close' onclick='$(\"#sws-control-panel-canvas\").toggle();'>✖</a>\
+</div>\
+<div id='sws-control-panel-options'>\
+<span title='Change the aspect ratio' class='sws-symbol' >💻</span><select id='sws-aspect-select' onchange='SWS.Presentation.changeAspect();'>\
+<option value='sws-aspect-4-3'>4:3</option>\
+<option value='sws-aspect-16-9'>16:9</option>\
+<option value='sws-aspect-16-10'>16:10</option>\
+</select>\
+<span title='Change the theme' class='sws-symbol'>🎨</span><select id='sws-theme-select' onchange='SWS.Presentation.changeTheme();'></select>\
+<a onclick='SWS.Presentation.openPrint()' ><span title='Open Print-Out' class='sws-symbol'></span></a>\
+</div>\
+<div id='sws-control-panel-navigation'>\
+<a title='First slide' class='sws-symbol' onclick='SWS.Presentation.goToSlide(SWS.Presentation.firstSlide());' >⏮</a>\
+<a title='Previous slide' class='sws-symbol' onclick='SWS.Presentation.previousSlide();SWS.Presentation.refresh();'>⏪</a>\
+<a title='Previous step' class='sws-symbol' style='-webkit-transform: scaleX(-1);' onclick='SWS.Presentation.previous();SWS.Presentation.refresh();'>▶</a>\
+<a title='Next step' class='sws-symbol' onclick='SWS.Presentation.next();SWS.Presentation.refresh();'>▶</a>\
+<a title='Next slide' class='sws-symbol' onclick='SWS.Presentation.nextSlide();SWS.Presentation.refresh();'>⏩</a>\
+<a title='Last slide' class='sws-symbol' onclick='SWS.Presentation.goToSlide(SWS.Presentation.lastSlide());'>⏭</a>\
+<br/>\
+<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>\
+<input type='range' title='Navigate the presentation' id='sws-control-panel-navigation-bar' onchange='SWS.Presentation.navigate();' step='1'></input>\
+</div>\
+</div>\
+</div>";
+ self.slideActivate = function (o) {
+ if (!(o.hasClass("sws-active-slide"))){
+ o.removeClass("sws-inactive-slide").addClass("sws-active-slide");
+ };
};
-5B
+ self.slideDeactivate = function (o) {
+ if (!(o.hasClass("sws-inactive-slide"))){
+ o.removeClass("sws-active-slide").addClass("sws-inactive-slide");
+ };
+ };
+ self.slideChange = function (from, to) {
+ var canvas = $(".sws-canvas");
+ self.slideDeactivate($(canvas[from]));
+ self.slideActivate($(canvas[to]));
};
-};
-*/
-SWS.Presentation = new function () {
+ self.objectActivate = function (o) {
+ 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) {
+ 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)) {
+ var i = SWS.Presentation.getCurrentSlide();
+ var cur = $( "<span class='sws-current-slide-number'>"
+ + (i + 1)
+ +"</span>");
+ var sep = $( "<span class='sws-slide-num-sep' />");
+ var tot = $( "<span class='sws-last-slide-number'>"
+ + (SWS.Presentation.getNumSlides())
+ +"</span>");
+ footer.append(cur).append(sep).append(tot);
+ };
+ };
+ 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;
+};
- var templates = {};
+SWS.Defaults = new SWS.ConfigBuilder ();
- //TODO: clean-up;
- var _total_slides;
- var _defered_custom = new Array();
- var _initialized = false;
- var _animations_running = false;
+SWS.Config = new SWS.ConfigBuilder ();
- //Utility functions
+SWS.Effects = new function () {
+ var self = this;
+ self.objectDeactivateFadeOut = function (o) {
+ o.animate({'opacity': '0.1'}, 200,
+ function () { SWS.Templates.objectDeactivate(o)});
+ };
- function push_following(t, i, v) {
- if ((typeof t[i]) == 'undefined') {
- t[i] = new Array();
+ self.objectActivateFadeIn = function (o) {
+
+ if (SWS.Templates.objectActivate(o)){
+ o.animate({'opacity': '1' }, 200);
};
- var l = t[i].length;
- if (l == 0 || !($.contains(t[i][l-1].get()[0], v.get()[0]))) {
- t[i][l] = v;
+
+ };
+
+ 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%');
+ 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.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);
};
};
- function push(t, i, v) {
- if ((typeof t[i]) == 'undefined') {
- t[i] = new Array();
+
+ self.slideChangeVerticalSlide = function (from, to) {
+ var f = SWS.Presentation.getSlide(from);
+ var t = SWS.Presentation.getSlide(to);
+ if (from < to) {
+ t.css('top', '100%');
+ 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.Templates.slideActivate(t);
+ f.animate({ 'top': '100%' }, 250, function () { SWS.Templates.slideDeactivate(f); });
+ t.animate({ 'top': '0%' }, 250);
};
- var l = t[i].length;
- t[i][l] = v;
};
+};
- function init_canvas(canvas) {
- var cur_frame = 0;
- var last_frame = canvas.find(".sws-pause").length;
- //Add all regular elements to the frame list
- canvas.find("*").each(function(i) {
- if ($(this).filter('*[class*="sws-onslide-"]').length) {
- } else {
- if ($(this).hasClass("sws-pause")) cur_frame++;
- var o = {};
- for (var j = cur_frame; j <= last_frame; j++)
- o[ "f" + j ] = true;
- $(this).data("sws-frame-set", o);
+SWS.Fullscreen = new function () {
+ var self = this;
+
+ 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();
};
- });
- canvas.data("sws-frame-info", { current: 0,
- last: last_frame,
- custom: new Array() });
+ } 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();
+ };
};
- //Public methods
- self.setTemplate = function (tn, fn) { templates[tn] = fn; };
+};
+
+SWS.Presentation = new function () {
+
+
+ var self = this;
+
+ //TODO move outside of the Presentation object
+
+
+ var _total_slides;
+ var _initialized = false;
+ var _disable_input_events = false;
+ var _print_mode = false;
+ var _slide_callbacks = new Array ();
+ var _total_steps = -1;
+ var _current_theme = "";
self.getNumSlides = function () { return _total_slides; };
+ self.getSlide = function(i) {
+ return $($(".sws-canvas")[i]);
+ };
- self.registerCustom = function (i, f) {
+ self.registerCallback = function (i, f) {
if (_initialized) return;
//jQuery does not seem to work well
- //on partal doms
+ //on a partial DOM
- var scripts = document.getElementsByTagName("script");
- var current = scripts[scripts.length-1];
+ var slide_num = $(".sws-slide").length - 1;
- var slide = $(current).parents(".sws-slide");
- if (slide.length == 0) {
- console.log("no parent ?");
- return;
- }
- _defered_custom[_defered_custom.length] = { src: slide[0],
- fn: f,
- frame: i };
- $(current).remove();
+ SWS.Utils.push2(_slide_callbacks, slide_num,{ 'fn': f, 'frame': i });
};
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 {
};
self.setCurrentSlide = function (i) {
- sessionStorage.current_slide = i;
+ sessionStorage.setItem("current_slide", i);
};
} else {
var _current_slide = 0;
- self.getCurrentSlide = function () { return current_slide; };
+ self.getCurrentSlide = function () { return _current_slide; };
self.setCurrentSlide = function (i) { _current_slide = i; };
};
self.firstSlide = function () { return 0; };
self.lastSlide = function () { return self.getNumSlides() - 1; };
-
self.refresh = function () {
- var to_slide = $(".sws-canvas")[self.getCurrentSlide()];
- var from_slide = $(".sws-active-slide")[0];
-
- if (!(to_slide === from_slide)) {
- templates['sws-template-slide-deactivate'](
- $(from_slide),
- function (o){
- o.removeClass("sws-active-slide")
- .addClass("sws-inactive-slide");
- templates['sws-template-slide-activate'](
- $(to_slide).removeClass("sws-inactive-slide")
- .addClass("sws-active-slide"),
- function (_){
- });
- });
-
+ /* 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 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:
+ SWS.Config['sws-slide-change'](from_slide_num, to_slide_num);
+ watch_slide_anim = true;
+ for (var i = 0; i < info.callbacks.at_slide.length;i++){
+ info.callbacks.at_slide[i](to_slide);
+ };
};
- var info = $(to_slide).data("sws-frame-info");
+
+
var cur = info.current;
var custom = info.custom;
+ var real_slide = to_slide.find(".sws-slide");
- $(to_slide).find("*").each (function (i) {
- var fcur = "f" + cur;
+ real_slide.find("*").andSelf().each(function (i){
var frameset = $(this).data("sws-frame-set") || {};
- if (frameset[fcur]) {
- if (!($(this).hasClass("sws-active-frame"))) {
- templates['sws-template-frame-activate'](
- $(this).removeClass("sws-inactive-frame")
- .addClass("sws-active-frame"),
- function (_){ });
-
- };
-
- } else {
- if (!($(this).hasClass("sws-inactive-frame"))) {
- templates['sws-template-frame-deactivate'](
- $(this),
- function (o){
- o.removeClass("sws-active-frame")
- .addClass("sws-inactive-frame");
- });
-
- };
-
-
- };
+ if (frameset[cur])
+ SWS.Config['sws-object-activate']($(this));
+ else
+ SWS.Config['sws-object-deactivate']($(this));
});
- _animation_running = true;
- var callbacks;
- if (callbacks = custom[self.getCurrentFrame()]){
+ var callbacks;
+ if (callbacks = info.callbacks.at_frame[self.getCurrentFrame()]){
for (var k = 0; k < callbacks.length; k++)
callbacks[k]($(to_slide));
};
- $(to_slide).find("*").promise().done(function() {
- _animation_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.lastSlide()));
+ self.setCurrentFrame(self.firstFrame());
};
self.previousSlide = function () {
self.setCurrentSlide(Math.max(self.getCurrentSlide()-1,
self.firstSlide()));
+ self.setCurrentFrame(self.firstFrame());
};
self.getFrameInfo = 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; };
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 = $("<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>");
+ $("body").append(progress);
+
+ $("html").removeClass("sws-display").addClass("sws-print");
+ self.goToSlide(0,0);
+ var steps = self.getTotalSteps();
+ var total_steps = steps;
+ var loop;
+ loop = function () {
+ if (steps >= 0) {
+ $(".sws-canvas").find("*").addBack().promise().done(function() {
+ var percent = ((total_steps - steps) / total_steps) * 100;
+ $("#sws-percent-progress").text(Math.round(percent));
+ console.log ("Step: " + steps);
+ SWS.Config['sws-slide-change'] = SWS.Templates.slideChange;
+ self.refresh();
+ $($(".sws-canvas")[self.getCurrentSlide()]).css( { 'opacity': 1 });
+ self.next();
+ steps--;
+ loop();
+ })
+ } else {
+ $("#sws-percent-progress").text(100);
+ progress.remove();
+ window.print();
+ }
+ };
+ loop();
+
+ }
+
self.inputHandler = function (event) {
- if (_animation_running) return;
+ if (_disable_input_events || _print_mode ) return;
switch (event.which) {
case 36:/* Home */
- self.firstSlide();
+ self.setCurrentSlide(self.firstSlide());
break;
case 35:/* End */
- self.lastSlide();
+ self.setCurrentSlide(self.lastSlide());
break;
case 32: /* space */
+ case 34: /* PgDown */
case 39: /* -> */
- case 1: /* mouse button 1 */
+ if (self.getCurrentSlide() == self.lastSlide()
+ && self.getCurrentFrame() == self.lastFrame()) return;
self.next();
break;
- case 34: /* PgDown */
case 78: /* n */
self.nextSlide();
break;
case 8: /* backspace */
+ case 33: /* PgUp */
case 37: /* <- */
self.previous();
break;
- case 33: /* PgUp */
case 80: /* p */
self.previousSlide();
break;
+ case 83: /* s */
+ self.cycleStyle();
+ return;
+ case 67: /* c */
+ $("#sws-control-panel-canvas").toggle();
default:
return;
};
};
- function default_footer_template() {
- var elem = '<div class="sws-footer"><span class="sws-current-slide-num">' + (i+1);
- elem += '</span><span class="sws-slide-num-sep"/><span class="sws-total-slide-num">';
- elem += self.getNumSlides() + '</span></div>';
- return $(elem);
+
+ function init_canvas(canvas, custom) {
+ var cur_frame = 0;
+ var last_frame = canvas.find(".sws-pause").length;
+ //Add all regular elements to the frame list
+ var slide = $(canvas.find(".sws-slide")[0]);
+
+ var callbacks = { at_slide : new Array(),
+ at_frame : new Array() }
+
+ if (SWS.Utils.isUndefined(custom)) {
+ custom = new Array ();
+ };
+
+ for (var i = 0; i < custom.length; i++) {
+ if (isFinite(custom[i].frame)){
+ var num = +(custom[i].frame);
+ if (num > last_frame) last_frame = num;
+ SWS.Utils.push2(callbacks.at_frame, num, custom[i].fn);
+ } else if (custom[i].frame == "slide")
+ callbacks.at_slide.push(custom[i].fn);
+ else {
+ var frame_set = SWS.Utils.parseFrameSpec(custom[i].frame);
+ for(var f in frame_set){
+ if (f > last_frame) last_frame = f;
+ SWS.Utils.push2(callbacks.at_frame, +(f), custom[i].fn);
+ };
+ }
+ };
+
+ var specials = null;
+
+ slide.find('*[class*="sws-onframe-"]').each(function(_){
+ var cls = $(this).attr('class');
+ var idx = cls.indexOf("sws-onframe-");
+ if (idx >= 0) {
+ var end = cls.indexOf(" ", idx);
+ end = (end == -1) ? cls.length : end;
+ var spec = cls.substring(idx+12, end);
+ var o = SWS.Utils.parseFrameSpec(spec);
+ for(var f in o)
+ if (f > last_frame) last_frame = f;
+ $(this).find("*").andSelf().each(function(_){
+ if (!SWS.Utils.isEmpty(o))
+ $(this).data("sws-frame-set", o);
+ if (specials)
+ specials.add($(this));
+ else
+ specials = $(this);
+ });
+ };
+ });
+
+ slide.find("*").andSelf().not(specials).each(function(i) {
+ if ($(this).hasClass("sws-pause")) cur_frame++;
+ var o = {};
+ for (var j = cur_frame; j <= last_frame; j++)
+ o[ j ] = true;
+ if (!SWS.Utils.isEmpty(o))
+ $(this).data("sws-frame-set", o);
+ });
+
+ canvas.data("sws-frame-info", { current: 0,
+ last: (last_frame - 0), // force cast to integer
+ callbacks: callbacks
+ });
+
};
- self.setTemplate('sws-template-footer', function (x) { });
- self.setTemplate('sws-template-frame-activate', function (x, f) {f(x);});
- self.setTemplate('sws-template-frame-deactivate', function (x, f) {f(x);});
- self.setTemplate('sws-template-slide-activate', function (x, f) {f(x);});
- self.setTemplate('sws-template-slide-deactivate', function (x, f) {f(x);});
+ /* Forces redrawing the page without reloading */
+ self.redraw = function () {
+ $("body").hide();
+ $("body").show();
+ };
+
+ self.changeAspect = function() {
+ $("html").removeClass("sws-aspect-4-3")
+ .removeClass("sws-aspect-16-9")
+ .removeClass("sws-aspect-16-10")
+ .addClass($("#sws-aspect-select").val());
+ self.redraw();
+ };
+
+
+ self.changeTheme = function (name) {
+ var theme_name;
+ if (typeof name === 'undefined')
+ theme_name = $("#sws-theme-select").val()
+ else
+ theme_name = name;
+ _current_theme = theme_name;
+ $("link.sws-theme").each (function (i) {
+ var e = $(this);
+ var title = e.attr("title");
+ if (title == theme_name) {
+ e[0].rel = "stylesheet";
+ e[0].disabled = false;
+ e[0].media="all";
+
+ } else {
+ e[0].rel = "alternate stylesheet";
+ e[0].disabled = true;
+ e[0].media="all";
+ };
+ });
+ self.redraw();
+ };
+
+ self.openPrint = function () {
+ window.open("?mode=print&theme=" + _current_theme);
+ }
+ var _fullscreen_icon_on = "";
+ var _fullscreen_icon_off = "";
+ self.toggleFullScreen = function () {
+ if (SWS.Fullscreen.status()) {
+ SWS.Fullscreen.exit();
+ $("a#sws-control-panel-fullscreen")
+ .html(_fullscreen_icon_off);
- function init () {
+
+ } else {
+ SWS.Fullscreen.enter($("body")[0]);
+ $("a#sws-control-panel-fullscreen")
+ .html(_fullscreen_icon_on);
+ };
+ };
+ function _update_ui() {
+ var nav = $('#sws-control-panel-navigation-bar');
+ nav.val(SWS.Presentation.getCurrentSlide() + 1);
+ $('#sws-control-panel-slide-input').val(nav.val());
+ }
+ self.navigate = function () {
+ self.goToSlide($("#sws-control-panel-navigation-bar").val()-1);
+ _update_ui();
+ };
+
+
+ self.init = function () {
+
+
+ $("html").addClass("sws-display");
+ $(window).resize(self.redraw);
+
+
+ $(window).bind('storage', function (e) {
+ console.log(e);
+ });
_total_slides = $(".sws-slide").length;
$(document).keydown(self.inputHandler);
- $(document).mousedown(self.inputHandler);
+
var cur = self.getCurrentSlide();
$(".sws-slide").each (function (i) {
- if (!($(this).hasClass("sws-option-nofooter"))) {
- $(this).append(templates['sws-template-footer']());
- };
var par = $(this).parent();
+
$(this).remove();
var canvas = $('<div class="sws-canvas"/>');
- canvas.append($(this));
+
+ if (!($(this).hasClass("sws-option-noheader"))) {
+ canvas.append($('<div class="sws-header"/><br/>'));
+ };
+
+ var inner = $('<div class="sws-inner-canvas"/>');
+ var content = $('<div class="sws-content"/>');
+ $(this).find('script[type="text/javascript"]').remove();
+ content.append($(this));
+ inner.append(content);
+ inner.append($('<span class="sws-vertical-align"> </span><br/>'));
+ canvas.append(inner);
+
+ if (!($(this).hasClass("sws-option-nofooter"))) {
+ canvas.append($('<div class="sws-footer"/>'));
+ };
+
par.append(canvas);
+
if (i == cur) {
canvas
.addClass("sws-active-slide")
- .removeClass("sws-inacitve-slide");
+ .removeClass("sws-inactive-slide");
} else {
canvas
.addClass("sws-inactive-slide")
.removeClass("sws-active-slide");
};
- init_canvas(canvas);
+ init_canvas(canvas,_slide_callbacks[i]);
});
- for (var i = 0; i < _defered_custom.length; i++){
- var custom = _defered_custom[i];
- var canvas = $(custom.src).parents(".sws-canvas");
- if (canvas.length == 0) continue;
- canvas = $(canvas[0]);
- var info = canvas.data("sws-frame-info");
- push(info.custom, custom.frame, custom.fn);
+ // Initialize the control panel
+ $("body").append($(SWS.Templates.controlPanel));
+ // Fill the theme switcher
+ $("link.sws-theme").each (function (i) {
+ var e = $(this);
+ var opt = "<option value='";
+ opt += e.attr("title");
+ opt += "' ";
+ if (e.attr("rel") == "stylesheet") {
+ opt+= "selected='selected'";
+ };
+ opt += ">" + e.attr("title") + "</option>";
+ $("#sws-theme-select").append($(opt));
+ });
+ // Set the fullscreen icon
+ if (SWS.Fullscreen.status()) {
+ $("a#sws-control-panel-fullscreen")
+ .html(_fullscreen_icon_on);
+ } else {
+ $("a#sws-control-panel-fullscreen")
+ .html(_fullscreen_icon_off);
};
- self.refresh();
+ // Put the navigation range at the correct position
+ var nav = $('#sws-control-panel-navigation-bar');
+ nav.attr("min", SWS.Presentation.firstSlide() + 1);
+ 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");
+ if (passed_theme == "")
+ self.changeTheme();
+ else
+ self.changeTheme(passed_theme);
+
+ if (SWS.Utils.getParameterByName("mode") == "print") {
+ self.printMode();
+ }
+ else
+ self.refresh();
+
_initialized = true;
- };
- self.init = function () {
- $(document).ready(init);
};
};