From 78fbef6280fade94a36a8314c2055bd2cbdcde05 Mon Sep 17 00:00:00 2001 From: miripiruni Date: Sun, 20 Jan 2013 16:06:54 +0400 Subject: [PATCH 1/5] Remove invoke shower.showPresenterNotes() in enterSlideMode because it already invoked in shower.go() --- shower.js | 1 - 1 file changed, 1 deletion(-) diff --git a/shower.js b/shower.js index 68cbccc..20c9a47 100755 --- a/shower.js +++ b/shower.js @@ -248,7 +248,6 @@ window.shower = (function(window, document, undefined) { } shower.go(currentSlideNumber); - shower.showPresenterNotes(currentSlideNumber); if (shower.isListMode() && isHistoryApiSupported) { history.pushState(null, null, url.pathname + '?full' + shower.getSlideHash(currentSlideNumber)); From a06c84a0b365a34587e5807290762bf997f5ab10 Mon Sep 17 00:00:00 2001 From: miripiruni Date: Sun, 20 Jan 2013 16:08:48 +0400 Subject: [PATCH 2/5] Rename: innerNavigationCompleted -> isInnerNavCompleted --- shower.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/shower.js b/shower.js index 20c9a47..6825b5b 100755 --- a/shower.js +++ b/shower.js @@ -595,7 +595,7 @@ window.shower = (function(window, document, undefined) { if (e.altKey || e.ctrlKey || e.metaKey) { return; } var currentSlideNumber = shower.getCurrentSlideNumber(), - innerNavigationCompleted = true; + isInnerNavCompleted = true; switch (e.which) { case 116: // F5 @@ -644,20 +644,19 @@ window.shower = (function(window, document, undefined) { if (shower.isSlideMode()) { // Inner navigation is "completed" if current slide have // no inner navigation or inner navigation is fully shown - innerNavigationCompleted = !slideList[currentSlideNumber].hasInnerNavigation || + isInnerNavCompleted = !slideList[currentSlideNumber].hasInnerNavigation || -1 === shower.increaseInnerNavigation(currentSlideNumber); } else { // Also inner navigation is always "completed" if we are in // list mode - innerNavigationCompleted = true; + isInnerNavCompleted = true; } - // NOTE: First of all check if there is no current slide + if ( - -1 === currentSlideNumber || innerNavigationCompleted + -1 === currentSlideNumber || isInnerNavCompleted ) { currentSlideNumber++; shower.go(currentSlideNumber); - // We must run slideshow only in full mode if (shower.isSlideMode()) { shower.runInnerNavigation(currentSlideNumber); } From 09750b072c477becaec0593157fcbe6b468ec02e Mon Sep 17 00:00:00 2001 From: miripiruni Date: Sun, 20 Jan 2013 16:21:26 +0400 Subject: [PATCH 3/5] Refactoring: shower.increaseInnerNavigation() returns only Boolean --- shower.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/shower.js b/shower.js index 6825b5b..a1a2130 100755 --- a/shower.js +++ b/shower.js @@ -172,8 +172,8 @@ window.shower = (function(window, document, undefined) { // NOTE: But first of all check if there is no current slide if ( -1 === currentSlideNumber || - !slideList[currentSlideNumber].hasInnerNavigation || - -1 === shower.increaseInnerNavigation(currentSlideNumber) + ! slideList[currentSlideNumber].hasInnerNavigation || + ! shower.increaseInnerNavigation(currentSlideNumber) ) { shower.go(currentSlideNumber + 1); // slides starts from 0 @@ -540,12 +540,11 @@ window.shower = (function(window, document, undefined) { /** * Increases inner navigation by adding 'active' class to next inactive inner navigation item * @param {Number} slideNumber - * @returns {Number} + * @returns {Boolean} */ shower.increaseInnerNavigation = function(slideNumber) { var nextNodes, - node, - ret = -1; + node; if ( ! shower._isNumber(slideNumber)) { throw new Error('Gimme slide number as Number, baby!'); @@ -558,11 +557,11 @@ window.shower = (function(window, document, undefined) { if (0 !== nextNodes.length) { node = nextNodes[0]; node.classList.add('active'); - ret = nextNodes.length - 1; + return true; } } - return ret; + return false; }; @@ -644,8 +643,8 @@ window.shower = (function(window, document, undefined) { if (shower.isSlideMode()) { // Inner navigation is "completed" if current slide have // no inner navigation or inner navigation is fully shown - isInnerNavCompleted = !slideList[currentSlideNumber].hasInnerNavigation || - -1 === shower.increaseInnerNavigation(currentSlideNumber); + isInnerNavCompleted = ! slideList[currentSlideNumber].hasInnerNavigation || + ! shower.increaseInnerNavigation(currentSlideNumber); } else { // Also inner navigation is always "completed" if we are in // list mode From 496e00972dcd69be92b9c459b636ce50d64e5d21 Mon Sep 17 00:00:00 2001 From: miripiruni Date: Sun, 20 Jan 2013 16:51:33 +0400 Subject: [PATCH 4/5] Refactoring keydown listener PgDown/Down/Right/l/j --- shower.js | 93 +++++++++++++++++++++++-------------------------------- 1 file changed, 38 insertions(+), 55 deletions(-) diff --git a/shower.js b/shower.js index a1a2130..096ccb5 100755 --- a/shower.js +++ b/shower.js @@ -158,8 +158,34 @@ window.shower = (function(window, document, undefined) { /** - * Show next slide. If slide is last returns false, otherwise return slide - * number which been shown. + * Go to slide number... + * @param {Number} slideNumber slide number (sic!). Attention: starts from zero. + * @param {Function} [callback] runs only if you not in List mode + * @returns {Number} + */ + shower.go = function(slideNumber, callback) { + if ( ! shower._isNumber(slideNumber)) { + throw new Error('Gimme slide number as Number, baby!'); + } + + url.hash = shower.getSlideHash(slideNumber); + + if (shower.isSlideMode()) { + shower.updateProgress(slideNumber); + shower.updateCurrentAndPassedSlides(slideNumber); + shower.showPresenterNotes(slideNumber); + + if (typeof(callback) === 'function') { + callback(); + } + } + + return slideNumber; + }; + + /** + * Show next slide or show next item of Inner navigation. If slide is last + * returns false, otherwise return slide number which been shown. * @param {Function} [callback] runs only if shower.next() complete successfully * @returns {Number|Boolean} */ @@ -176,12 +202,16 @@ window.shower = (function(window, document, undefined) { ! shower.increaseInnerNavigation(currentSlideNumber) ) { shower.go(currentSlideNumber + 1); - // slides starts from 0 + // Slides starts from 0. So return next slide number. ret = currentSlideNumber + 2; + } - if (typeof(callback) === 'function') { - callback(); - } + if (shower.isSlideMode()) { + shower.runInnerNavigation(currentSlideNumber + 1); + } + + if (typeof(callback) === 'function') { + callback(); } return ret; @@ -481,32 +511,6 @@ window.shower = (function(window, document, undefined) { return '#' + slideList[slideNumber].id; }; - /** - * Go to slide number... - * @param {Number} slideNumber slide number (sic!). Attention: starts from zero. - * @param {Function} [callback] runs only if you not in List mode - * @returns {Number} - */ - shower.go = function(slideNumber, callback) { - if ( ! shower._isNumber(slideNumber)) { - throw new Error('Gimme slide number as Number, baby!'); - } - - url.hash = shower.getSlideHash(slideNumber); - - if (shower.isSlideMode()) { - shower.updateProgress(slideNumber); - shower.updateCurrentAndPassedSlides(slideNumber); - shower.showPresenterNotes(slideNumber); - - if (typeof(callback) === 'function') { - callback(); - } - } - - return slideNumber; - }; - /** * Run slide show if presented. * @param {Number} slideNumber @@ -528,8 +532,7 @@ window.shower = (function(window, document, undefined) { timing = parseInt(timing[0], 10) * 60 * 1000 + parseInt(timing[1], 10) * 1000; timer = setTimeout(function() { - shower.go(slideNumber + 1); - shower.runInnerNavigation(slideNumber + 1); + shower.next(); }, timing); } @@ -639,27 +642,7 @@ window.shower = (function(window, document, undefined) { case 76: // l case 74: // j e.preventDefault(); - - if (shower.isSlideMode()) { - // Inner navigation is "completed" if current slide have - // no inner navigation or inner navigation is fully shown - isInnerNavCompleted = ! slideList[currentSlideNumber].hasInnerNavigation || - ! shower.increaseInnerNavigation(currentSlideNumber); - } else { - // Also inner navigation is always "completed" if we are in - // list mode - isInnerNavCompleted = true; - } - - if ( - -1 === currentSlideNumber || isInnerNavCompleted - ) { - currentSlideNumber++; - shower.go(currentSlideNumber); - if (shower.isSlideMode()) { - shower.runInnerNavigation(currentSlideNumber); - } - } + shower.next(); break; case 36: // Home From 8cd2aa3544f283153e0ca9d5fbd51fa77e58ae3f Mon Sep 17 00:00:00 2001 From: miripiruni Date: Sun, 20 Jan 2013 21:59:45 +0400 Subject: [PATCH 5/5] Fix for presenter notes, fix timing for inner nav; Refactoring. --- shower.js | 101 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 63 insertions(+), 38 deletions(-) diff --git a/shower.js b/shower.js index 096ccb5..95677d3 100755 --- a/shower.js +++ b/shower.js @@ -75,7 +75,7 @@ window.shower = (function(window, document, undefined) { * @returns {Boolean} */ shower._isNumber = function(arg) { - return ! isNaN(parseFloat(arg)) && isFinite(arg); + return ! isNaN(parseFloat(arg)) && isFinite(arg); }; /** @@ -128,7 +128,7 @@ window.shower = (function(window, document, undefined) { * @returns {Boolean} */ shower._checkInteractiveElement = function(e) { - return 'A' === e.target.nodeName; + return 'A' === e.target.nodeName; }; /** @@ -168,16 +168,19 @@ window.shower = (function(window, document, undefined) { throw new Error('Gimme slide number as Number, baby!'); } + // Also triggers popstate and invoke shower.enter__Mode() url.hash = shower.getSlideHash(slideNumber); if (shower.isSlideMode()) { + shower.showPresenterNotes(slideNumber); shower.updateProgress(slideNumber); shower.updateCurrentAndPassedSlides(slideNumber); - shower.showPresenterNotes(slideNumber); + shower.runInnerNavigation(slideNumber); - if (typeof(callback) === 'function') { - callback(); - } + } + + if (typeof(callback) === 'function') { + callback(); } return slideNumber; @@ -185,7 +188,7 @@ window.shower = (function(window, document, undefined) { /** * Show next slide or show next item of Inner navigation. If slide is last - * returns false, otherwise return slide number which been shown. + * returns false, otherwise return slide number which been shown. * @param {Function} [callback] runs only if shower.next() complete successfully * @returns {Number|Boolean} */ @@ -197,9 +200,13 @@ window.shower = (function(window, document, undefined) { // navigation or inner navigation is fully shown // NOTE: But first of all check if there is no current slide if ( - -1 === currentSlideNumber || - ! slideList[currentSlideNumber].hasInnerNavigation || - ! shower.increaseInnerNavigation(currentSlideNumber) + ( + -1 === currentSlideNumber || + ! slideList[currentSlideNumber].hasInnerNavigation || + ! shower.increaseInnerNavigation(currentSlideNumber) + ) && + // If exist next slide + (currentSlideNumber + 2) <= slideList.length ) { shower.go(currentSlideNumber + 1); // Slides starts from 0. So return next slide number. @@ -273,32 +280,22 @@ window.shower = (function(window, document, undefined) { shower.enterSlideMode = function(callback) { var currentSlideNumber = shower.getCurrentSlideNumber(); - if (currentSlideNumber === -1) { - currentSlideNumber = 0; - } - - shower.go(currentSlideNumber); + // Anyway: change body class (@TODO: refactoring) + body.classList.remove('list'); + body.classList.add('full'); + // Preparing URL for shower.go() if (shower.isListMode() && isHistoryApiSupported) { history.pushState(null, null, url.pathname + '?full' + shower.getSlideHash(currentSlideNumber)); } - body.classList.remove('list'); - body.classList.add('full'); - - if (window.console && window.console.clear) { - console.clear(); - } - - shower.updateProgress(currentSlideNumber); - shower.updateCurrentAndPassedSlides(currentSlideNumber); - shower.runInnerNavigation(currentSlideNumber); + shower._applyTransform(shower._getTransform()); if (typeof(callback) === 'function') { callback(); } - return shower._applyTransform(shower._getTransform()); + return true; }; /** @@ -307,24 +304,32 @@ window.shower = (function(window, document, undefined) { * @returns {Boolean} */ shower.enterListMode = function(callback) { + // Anyway: change body class (@TODO: refactoring) + body.classList.remove('full'); + body.classList.add('list'); + + shower.clearPresenterNotes(); + + if (shower.isListMode()) { + return false; + } + var currentSlideNumber = shower.getCurrentSlideNumber(); clearTimeout(timer); - body.classList.remove('full'); - body.classList.add('list'); - if (shower.isSlideMode() && isHistoryApiSupported) { history.pushState(null, null, url.pathname + shower.getSlideHash(currentSlideNumber)); } shower.scrollToSlide(currentSlideNumber); + shower._applyTransform('none'); if (typeof(callback) === 'function') { callback(); } - return shower._applyTransform('none'); + return true; }; /** @@ -469,11 +474,22 @@ window.shower = (function(window, document, undefined) { return true; }; + /** + * Clear presenter notes in console. + */ + shower.clearPresenterNotes = function() { + if (window.console && window.console.clear) { + console.clear(); + } + }; + /** * Show presenter notes in console. * @param {Number} slideNumber slide number (sic!). Attention: starts from zero. */ shower.showPresenterNotes = function(slideNumber) { + shower.clearPresenterNotes(); + if (window.console) { slideNumber = shower._normalizeSlideNumber(slideNumber); @@ -481,11 +497,12 @@ window.shower = (function(window, document, undefined) { nextSlideId = slideList[slideNumber + 1] ? slideList[slideNumber + 1].id : null, notes = document.getElementById(slideId).querySelector('footer'); - if (notes) { + if (notes && notes.innerHTML) { console.info(notes.innerHTML.replace(/\n\s+/g,'\n')); } if (nextSlideId) { + var next = document.getElementById(nextSlideId).querySelector('h2'); if (next) { @@ -537,7 +554,7 @@ window.shower = (function(window, document, undefined) { timing); } - return true; + return true; }; /** @@ -567,13 +584,11 @@ window.shower = (function(window, document, undefined) { return false; }; - - - // Event handlers window.addEventListener('DOMContentLoaded', function() { - if (body.classList.contains('full')) { + if (body.classList.contains('full') || shower.isSlideMode()) { + shower.go(shower.getCurrentSlideNumber()); shower.enterSlideMode(); } }, false); @@ -606,8 +621,11 @@ window.shower = (function(window, document, undefined) { if (shower.isListMode()) { var slideNumber = e.shiftKey ? currentSlideNumber : 0; + // Warning: go must be before enterSlideMode. Else there are + // bug in Chrome shower.go(slideNumber); shower.enterSlideMode(); + shower.showPresenterNotes(slideNumber); } else { shower.enterListMode(); } @@ -667,10 +685,17 @@ window.shower = (function(window, document, undefined) { }, false); document.addEventListener('click', function(e) { + e.preventDefault(); + + var slideNumber = shower.getSlideNumber(shower._getSlideIdByEl(e.target)); + + // Click on slide in List mode if (shower.isListMode() && shower._getSlideIdByEl(e.target)) { - e.preventDefault(); - shower.go(shower.getSlideNumber(shower._getSlideIdByEl(e.target))); + // Warning: go must be before enterSlideMode. Else there are + // bug in Chrome + shower.go(slideNumber); shower.enterSlideMode(); + shower.showPresenterNotes(slideNumber); } }, false);