$(document).ready(function() { window.ToggleView = Spine.Class.create({ init: function () { this.element = $(arguments[0]) var eventPrefix = arguments[1] $.subscribe( eventPrefix + ":show",$.proxy(function() { this.show() },this)); $.subscribe( eventPrefix + ":hide",$.proxy(function() { this.hide() },this)); $.subscribe( eventPrefix + ":toggle",$.proxy(function() { this.toggle() },this)); }, show: function() { this.element.show() }, hide: function() { this.element.hide() }, toggle: function() { this.element.toggle() } }); window.Footer = ToggleView.sub({ init: function() { this.constructor.__super__.init.apply(this, arguments); this.progressView = $("#slideInfo") $.subscribe("presentation:slide:didChange",$.proxy(this.updateProgress,this)); }, progressPercentage: function (slideIndex,slideCount) { return Math.ceil(((slideIndex + 1) / slideCount) * 100) }, updateProgress: function(event,slideIndex,slideCount) { percent = this.progressPercentage(slideIndex,slideCount); this.progressView.text((slideIndex + 1) + '/' + slideCount + ' - ' + percent + '%') } }); window.HelpMenu = ToggleView.sub(); window.PauseScreen = ToggleView.sub(); window.DebugView = ToggleView.sub({ log: function(text) { this.element.text(text); } }); window.Slide = Spine.Class.create({ index: 0, maxSlides: 0, init: function() { this.htmlContent = arguments[0]; this.index = arguments[1]; this.maxSlides = arguments[2]; this.transition = this.htmlContent.attr('data-transition'); this.sequence = parseInt(this.htmlContent.attr('data-sequence')); this.title = this.htmlContent.attr('data-title'); if (this.title === undefined) { this.title = this.htmlContent.text().trim().split("\n")[0]; if (this.title.length > 20) { this.title = this.title.substr(0,15) + "..."; } } this.sections = []; if (this.htmlContent.attr('data-sections') != undefined) { this.sections = this.htmlContent.attr('data-sections').split(','); } this.increments = this.htmlContent.find(".incremental > ul > li"); this.currentIncrement = 0; if (this.increments.size() == 0) { this.increments = this.htmlContent.find(".incremental pre pre") this.codeIncremental = true; } this.increments.each(function(index, increment) { $(increment).css('visibility', 'hidden'); }); }, currentIncrement: 0, increment: function(incrementIndex) { var increment = this.increments.eq(incrementIndex); if (this.codeIncremental && increment.hasClass('command')) { var typeInputOverDuration = increment.find('.input').text().length / 24; increment.find('.prompt').css('visibility', 'visible'); increment.find('.input').css('visibility', 'visible').jTypeWriter({duration:typeInputOverDuration}); } else { increment.css('visibility', 'visible'); } }, nextIncrement: function() { this.increment(this.currentIncrement); this.trigger("parade:incr"); this.currentIncrement ++; }, hasIncrement: function() { return (this.currentIncrement < this.increments.size()); }, showAllIncrements: function() { this.increments.each(function(index, increment) { $(increment).css('visibility', 'visible'); }); this.currentIncrement = this.increments.size(); }, notes: function() { return this.htmlContent.find("p.notes").text(); }, trigger: function(eventName) { var event = jQuery.Event(eventName); this.htmlContent.find(".content").trigger(event,this); return event; } }); window.Slides = Spine.Class.create({ init: function() { this.element = $("#slides"); this.load(arguments[0],arguments[1]); this }, show: function() { this.element.show() }, hide: function() { this.element.hide() }, load: function(options,afterLoad) { var slidesURL = options.urlPrefix + "/slides?height=" + options.height + "&width=" + options.width; $("#slides").load(slidesURL,$.proxy(function() { this.slides = $("#slides > .slide"); afterLoad(); },this)); }, size: function() { return this.slides.size(); }, at: function(index) { return new Slide($(this.slides.eq(index)),index,this.size()); }, find: function(query) { var regexQuery = new RegExp(query,"i"); var matchedSlideNumbers = []; for (var index = 0; index < this.size(); index++) { var slide = this.at(index); // console.log(slide.title + " " + regexQuery); if (regexQuery.exec(slide.title)) { matchedSlideNumbers.push(slide.sequence); } } console.log("Found: " + matchedSlideNumbers); return matchedSlideNumbers; }, findClosestToQuery: function(position,query) { console.log('Finding the query `' + query + '` next to position ' + position); var matchingSlides = this.find(query); var closestPosition = matchingSlides[0]; console.log('Defaulting to ' + closestPosition); for (var mI = 0; mI < matchingSlides.length; mI++) { if (matchingSlides[mI] > position) { console.log('Setting movement to ' + matchingSlides[mI]); closestPosition = matchingSlides[mI]; break; } } return closestPosition; } }); window.NavigationMenu = ToggleView.sub({ init: function() { this.constructor.__super__.init.apply(this,arguments); this.menuView = $("#navigation"); }, populate: function(slides) { var menu = new ListMenu(); for (var i = 0; i < slides.size(); i++) { var slide = slides.at(i); var sectionsMinusRoot = slide.sections.slice(1,slide.sections.length); sectionsMinusRoot.push(slide.sequence); menu.addItem(sectionsMinusRoot, slide.title, slide.sequence); } this.menuView.html(menu.getList()); this.element.menu({ content: this.menuView.html(), flyOut: true, width: 200 }); }, toggle: function() { this.constructor.__super__.toggle.apply(this,arguments); this.open(); }, show: function() { this.constructor.__super__.show.apply(this,arguments); this.open(); }, open: function() { this.element.trigger('click'); }, createMenu: function(slide) { console.log(this); function menu(slide) { console.log(this); } } }); function ListMenu(slide) { this.slide = slide this.typeName = 'ListMenu' this.itemLength = 0; this.items = new Array(); this.addItem = function (key, text, slide) { if (key.length > 1) { thisKey = key.shift() if (!this.items[thisKey]) { this.items[thisKey] = new ListMenu(slide) } this.items[thisKey].addItem(key, text, slide) } else { thisKey = key.shift() this.items[thisKey] = new ListMenuItem(text, slide) } } this.getList = function() { var newMenu = $("