diff --git a/shower.js b/shower.js index ab25d73..202cc33 100755 --- a/shower.js +++ b/shower.js @@ -40,7 +40,7 @@ window.shower = (function(window, document, undefined) { } /** - * Get slide scale value + * Get slide scale value. * @private * @returns {String} */ @@ -54,7 +54,7 @@ window.shower = (function(window, document, undefined) { }; /** - * Set CSS transform with prefixes to body + * Set CSS transform with prefixes to body. * @private * @returns {Boolean} */ @@ -119,9 +119,9 @@ window.shower = (function(window, document, undefined) { }; /** - * For touch devices: check if click on links... + * For touch devices: check if link is clicked. * - * @TODO: add support for textareas/inputs/... + * @TODO: add support for textareas/inputs/etc. * * @private * @param {HTMLElement} e @@ -132,7 +132,7 @@ window.shower = (function(window, document, undefined) { }; /** - * Get slide number by slideId + * Get slide number by slideId. * @param {String} slideId (HTML id or position in slideList) * @returns {Number} */ @@ -156,11 +156,10 @@ window.shower = (function(window, document, undefined) { return slideNumber; }; - /** - * Go to slide number... + * 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 + * @param {Function} [callback] runs only if you not in List mode. * @returns {Number} */ shower.go = function(slideNumber, callback) { @@ -172,7 +171,7 @@ window.shower = (function(window, document, undefined) { url.hash = shower.getSlideHash(slideNumber); shower.updateProgress(slideNumber); - shower.updateCurrentAndPassedSlides(slideNumber); + shower.updateActiveAndVisitedSlides(slideNumber); if (shower.isSlideMode()) { shower.showPresenterNotes(slideNumber); @@ -187,9 +186,9 @@ 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. - * @param {Function} [callback] runs only if shower.next() complete successfully + * Show next slide or show next Inner navigation item. + * Returns false on a last slide, otherwise returns shown slide number. + * @param {Function} [callback] runs only if shower.next() is successfully completed. * @returns {Number|Boolean} */ shower.next = function(callback) { @@ -225,9 +224,8 @@ window.shower = (function(window, document, undefined) { }; /** - * Show previous slide. If slide is first returns false, otherwise return slide - * number which been shown. - * @param {Function} [callback] runs only if shower.previous() complete successfully + * Show previous slide. Returns false on a first slide, otherwise returns shown slide number. + * @param {Function} [callback] runs only if shower.previous() is successfully completed. * @returns {Number|Boolean} */ shower.previous = function(callback) { @@ -274,7 +272,7 @@ window.shower = (function(window, document, undefined) { /** * Switch to slide view. - * @param {Function} [callback] runs only if shower.enterSlideMode() complete successfully + * @param {Function} [callback] runs only if shower.enterSlideMode() is successfully completed. * @returns {Boolean} */ shower.enterSlideMode = function(callback) { @@ -300,7 +298,7 @@ window.shower = (function(window, document, undefined) { /** * Switch to list view. - * @param {Function} [callback] runs only if shower.enterListMode() complete successfully + * @param {Function} [callback] runs only if shower.enterListMode() is successfully completed. * @returns {Boolean} */ shower.enterListMode = function(callback) { @@ -333,7 +331,7 @@ window.shower = (function(window, document, undefined) { }; /** - * Toggle Mode: Slide and List + * Toggle Mode: Slide and List. * @param {Function} [callback] */ shower.toggleMode = function(callback) { @@ -351,9 +349,9 @@ window.shower = (function(window, document, undefined) { }; /** - * Get current slide number. Starts from zero. Warning: when in url you have - * slide number 1 this method will return 0. - * If something wrong return -1. + * Get current slide number. Starts from zero. Warning: when you have + * slide number 1 in URL this method will return 0. + * If something is wrong return -1. * @returns {Number} */ shower.getCurrentSlideNumber = function() { @@ -441,11 +439,11 @@ window.shower = (function(window, document, undefined) { }; /** - * Update current and passed slides. + * Update active and visited slides. * @param {Number} slideNumber slide number (sic!) * @returns {Boolean} */ - shower.updateCurrentAndPassedSlides = function(slideNumber) { + shower.updateActiveAndVisitedSlides = function(slideNumber) { var i, slide, l = slideList.length; @@ -570,7 +568,7 @@ window.shower = (function(window, document, undefined) { throw new Error('Gimme slide number as Number, baby!'); } - // If inner navigation in this slide... + // If inner navigation in this slide if (slideList[slideNumber].hasInnerNavigation) { nextNodes = document.getElementById(slideList[slideNumber].id).querySelectorAll('.next:not(.active)'); @@ -621,8 +619,8 @@ 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 + // Warning: go must be before enterSlideMode. + // Otherwise there is a bug in Chrome shower.go(slideNumber); shower.enterSlideMode(); shower.showPresenterNotes(slideNumber); @@ -648,8 +646,8 @@ window.shower = (function(window, document, undefined) { case 33: // PgUp case 38: // Up case 37: // Left - case 72: // h - case 75: // k + case 72: // H + case 75: // K e.preventDefault(); shower.previous(); break; @@ -657,8 +655,8 @@ window.shower = (function(window, document, undefined) { case 34: // PgDown case 40: // Down case 39: // Right - case 76: // l - case 74: // j + case 76: // L + case 74: // J e.preventDefault(); shower.next(); break; @@ -685,14 +683,12 @@ 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)) { - // Warning: go must be before enterSlideMode. Else there are - // bug in Chrome + // Warning: go must be before enterSlideMode. + // Otherwise there is a bug in Chrome shower.go(slideNumber); shower.enterSlideMode(); shower.showPresenterNotes(slideNumber); @@ -716,7 +712,6 @@ window.shower = (function(window, document, undefined) { shower.enterSlideMode(); } } - }, false); @@ -728,4 +723,4 @@ window.shower = (function(window, document, undefined) { return shower; -})(this, this.document); +})(this, this.document); \ No newline at end of file diff --git a/shower.min.js b/shower.min.js index fd312a4..8f1d202 100644 --- a/shower.min.js +++ b/shower.min.js @@ -3,4 +3,4 @@ * @copyright 2010–2013 Vadim Makeev, pepelsbey.net * @license MIT license: github.com/shower/shower/wiki/MIT-License */ -window.shower=function(e,t,r){var i={},n=e.location,s=t.body,o=t.querySelectorAll(".slide"),a=t.querySelector("div.progress div"),l=[],u,d=!!(e.history&&history.pushState),f=o.length,c;i._getData=function(e,t){return e.dataset?e.dataset[t]:e.getAttribute("data-"+t)};for(c=0;c=l.length){e=l.length-1}return e};i._getSlideIdByEl=function(e){while("BODY"!==e.nodeName&&"HTML"!==e.nodeName){if(e.classList.contains("slide")){return e.id}else{e=e.parentNode}}return""};i._checkInteractiveElement=function(e){return"A"===e.target.nodeName};i.getSlideNumber=function(e){var t=l.length-1,r;if(e===""){r=0}for(;t>=0;--t){if(e===l[t].id){r=t;break}}return r};i.go=function(e,t){if(!i._isNumber(e)){throw new Error("Gimme slide number as Number, baby!")}n.hash=i.getSlideHash(e);i.updateProgress(e);i.updateCurrentAndPassedSlides(e);if(i.isSlideMode()){i.showPresenterNotes(e);i.runInnerNavigation(e)}if(typeof t==="function"){t()}return e};i.next=function(e){var t=i.getCurrentSlideNumber(),r=false;if((-1===t||!l[t].hasInnerNavigation||!i.increaseInnerNavigation(t))&&t+2<=l.length){i.go(t+1);r=t+2}if(i.isSlideMode()){i.runInnerNavigation(t+1)}if(typeof e==="function"){e()}return r};i.previous=function(e){var t=i.getCurrentSlideNumber(),r=false;if(t>0){r=t;i.go(t-1);if(typeof e==="function"){e()}}return r};i.first=function(e){if(typeof e==="function"){e()}return i.go(0)};i.last=function(e){if(typeof e==="function"){e()}return i.go(l.length-1)};i.enterSlideMode=function(e){var t=i.getCurrentSlideNumber();s.classList.remove("list");s.classList.add("full");if(i.isListMode()&&d){history.pushState(null,null,n.pathname+"?full"+i.getSlideHash(t))}i._applyTransform(i._getTransform());if(typeof e==="function"){e()}return true};i.enterListMode=function(e){s.classList.remove("full");s.classList.add("list");i.clearPresenterNotes();if(i.isListMode()){return false}var t=i.getCurrentSlideNumber();clearTimeout(u);if(i.isSlideMode()&&d){history.pushState(null,null,n.pathname+i.getSlideHash(t))}i.scrollToSlide(t);i._applyTransform("none");if(typeof e==="function"){e()}return true};i.toggleMode=function(e){if(i.isListMode()){i.enterSlideMode()}else{i.enterListMode()}if(typeof e==="function"){e()}return true};i.getCurrentSlideNumber=function(){var e=l.length-1,t=n.hash.substr(1);for(;e>=0;--e){if(t===l[e].id){return e}}return-1};i.scrollToSlide=function(r){var n,s=false;if(!i._isNumber(r)){throw new Error("Gimme slide number as Number, baby!")}if(i.isSlideMode()){throw new Error("You can't scroll to because you in slide mode. Please, switch to list mode.")}if(-1===r){return s}if(l[r]){n=t.getElementById(l[r].id);e.scrollTo(0,n.offsetTop);s=true}else{throw new Error("There is no slide with number "+r)}return s};i.isListMode=function(){return d?!/^full.*/.test(n.search.substr(1)):s.classList.contains("list")};i.isSlideMode=function(){return d?/^full.*/.test(n.search.substr(1)):s.classList.contains("full")};i.updateProgress=function(e){if(null===a){return false}if(!i._isNumber(e)){throw new Error("Gimme slide number as Number, baby!")}a.style.width=(100/(l.length-1)*i._normalizeSlideNumber(e)).toFixed(2)+"%";return true};i.updateCurrentAndPassedSlides=function(e){var r,n,s=l.length;e=i._normalizeSlideNumber(e);if(!i._isNumber(e)){throw new Error("Gimme slide number as Number, baby!")}for(r=0;re){n.classList.remove("visited");n.classList.remove("active")}else{n.classList.remove("visited");n.classList.add("active")}}return true};i.clearPresenterNotes=function(){if(e.console&&e.console.clear){console.clear()}};i.showPresenterNotes=function(r){i.clearPresenterNotes();if(e.console){r=i._normalizeSlideNumber(r);var n=l[r].id,s=l[r+1]?l[r+1].id:null,o=t.getElementById(n).querySelector("footer");if(o&&o.innerHTML){console.info(o.innerHTML.replace(/\n\s+/g,"\n"))}if(s){var a=t.getElementById(s).querySelector("h2");if(a){a=a.innerHTML.replace(/^\s+|<[^>]+>/g,"");console.info("NEXT: "+a)}}}};i.getSlideHash=function(e){if(!i._isNumber(e)){throw new Error("Gimme slide number as Number, baby!")}e=i._normalizeSlideNumber(e);return"#"+l[e].id};i.runInnerNavigation=function(e){if(!i._isNumber(e)){throw new Error("Gimme slide number as Number, baby!")}e=i._normalizeSlideNumber(e);clearTimeout(u);if(l[e].hasTiming){var r=i._getData(t.getElementById(l[e].id),"timing").split(":");r=parseInt(r[0],10)*60*1e3+parseInt(r[1],10)*1e3;u=setTimeout(function(){i.next()},r)}return true};i.increaseInnerNavigation=function(e){var r,n;if(!i._isNumber(e)){throw new Error("Gimme slide number as Number, baby!")}if(l[e].hasInnerNavigation){r=t.getElementById(l[e].id).querySelectorAll(".next:not(.active)");if(0!==r.length){n=r[0];n.classList.add("active");return true}}return false};e.addEventListener("DOMContentLoaded",function(){if(s.classList.contains("full")||i.isSlideMode()){i.go(i.getCurrentSlideNumber());i.enterSlideMode()}},false);e.addEventListener("popstate",function(){if(i.isListMode()){i.enterListMode()}else{i.enterSlideMode()}},false);e.addEventListener("resize",function(){if(i.isSlideMode()){i._applyTransform(i._getTransform())}},false);t.addEventListener("keydown",function(e){if(e.altKey||e.ctrlKey||e.metaKey){return}var t=i.getCurrentSlideNumber(),r=true;switch(e.which){case 116:e.preventDefault();if(i.isListMode()){var n=e.shiftKey?t:0;i.go(n);i.enterSlideMode();i.showPresenterNotes(n)}else{i.enterListMode()}break;case 13:if(i.isListMode()&&-1!==t){e.preventDefault();i.enterSlideMode()}break;case 27:if(i.isSlideMode()){e.preventDefault();i.enterListMode()}break;case 33:case 38:case 37:case 72:case 75:e.preventDefault();i.previous();break;case 34:case 40:case 39:case 76:case 74:e.preventDefault();i.next();break;case 36:e.preventDefault();i.first();break;case 35:e.preventDefault();i.last();break;case 9:case 32:e.preventDefault();i[e.shiftKey?"previous":"next"]();break;default:}},false);t.addEventListener("click",function(e){e.preventDefault();var t=i.getSlideNumber(i._getSlideIdByEl(e.target));if(i.isListMode()&&i._getSlideIdByEl(e.target)){i.go(t);i.enterSlideMode();i.showPresenterNotes(t)}},false);t.addEventListener("touchstart",function(t){if(i._getSlideIdByEl(t.target)){if(i.isSlideMode()&&!i._checkInteractiveElement(t)){var r=t.touches[0].pageX;if(r>e.innerWidth/2){i.next()}else{i.previous()}}if(i.isListMode()){i.go(i.getSlideNumber(i._getSlideIdByEl(t.target)));i.enterSlideMode()}}},false);t.addEventListener("touchmove",function(e){if(i.isSlideMode()){e.preventDefault()}},false);return i}(this,this.document); \ No newline at end of file +window.shower=function(e,t,r){var i={},n=e.location,s=t.body,o=t.querySelectorAll(".slide"),a=t.querySelector("div.progress div"),l=[],u,d=!!(e.history&&history.pushState),f=o.length,c;i._getData=function(e,t){return e.dataset?e.dataset[t]:e.getAttribute("data-"+t)};for(c=0;c=l.length){e=l.length-1}return e};i._getSlideIdByEl=function(e){while("BODY"!==e.nodeName&&"HTML"!==e.nodeName){if(e.classList.contains("slide")){return e.id}else{e=e.parentNode}}return""};i._checkInteractiveElement=function(e){return"A"===e.target.nodeName};i.getSlideNumber=function(e){var t=l.length-1,r;if(e===""){r=0}for(;t>=0;--t){if(e===l[t].id){r=t;break}}return r};i.go=function(e,t){if(!i._isNumber(e)){throw new Error("Gimme slide number as Number, baby!")}n.hash=i.getSlideHash(e);i.updateProgress(e);i.updateActiveAndVisitedSlides(e);if(i.isSlideMode()){i.showPresenterNotes(e);i.runInnerNavigation(e)}if(typeof t==="function"){t()}return e};i.next=function(e){var t=i.getCurrentSlideNumber(),r=false;if((-1===t||!l[t].hasInnerNavigation||!i.increaseInnerNavigation(t))&&t+2<=l.length){i.go(t+1);r=t+2}if(i.isSlideMode()){i.runInnerNavigation(t+1)}if(typeof e==="function"){e()}return r};i.previous=function(e){var t=i.getCurrentSlideNumber(),r=false;if(t>0){r=t;i.go(t-1);if(typeof e==="function"){e()}}return r};i.first=function(e){if(typeof e==="function"){e()}return i.go(0)};i.last=function(e){if(typeof e==="function"){e()}return i.go(l.length-1)};i.enterSlideMode=function(e){var t=i.getCurrentSlideNumber();s.classList.remove("list");s.classList.add("full");if(i.isListMode()&&d){history.pushState(null,null,n.pathname+"?full"+i.getSlideHash(t))}i._applyTransform(i._getTransform());if(typeof e==="function"){e()}return true};i.enterListMode=function(e){s.classList.remove("full");s.classList.add("list");i.clearPresenterNotes();if(i.isListMode()){return false}var t=i.getCurrentSlideNumber();clearTimeout(u);if(i.isSlideMode()&&d){history.pushState(null,null,n.pathname+i.getSlideHash(t))}i.scrollToSlide(t);i._applyTransform("none");if(typeof e==="function"){e()}return true};i.toggleMode=function(e){if(i.isListMode()){i.enterSlideMode()}else{i.enterListMode()}if(typeof e==="function"){e()}return true};i.getCurrentSlideNumber=function(){var e=l.length-1,t=n.hash.substr(1);for(;e>=0;--e){if(t===l[e].id){return e}}return-1};i.scrollToSlide=function(r){var n,s=false;if(!i._isNumber(r)){throw new Error("Gimme slide number as Number, baby!")}if(i.isSlideMode()){throw new Error("You can't scroll to because you in slide mode. Please, switch to list mode.")}if(-1===r){return s}if(l[r]){n=t.getElementById(l[r].id);e.scrollTo(0,n.offsetTop);s=true}else{throw new Error("There is no slide with number "+r)}return s};i.isListMode=function(){return d?!/^full.*/.test(n.search.substr(1)):s.classList.contains("list")};i.isSlideMode=function(){return d?/^full.*/.test(n.search.substr(1)):s.classList.contains("full")};i.updateProgress=function(e){if(null===a){return false}if(!i._isNumber(e)){throw new Error("Gimme slide number as Number, baby!")}a.style.width=(100/(l.length-1)*i._normalizeSlideNumber(e)).toFixed(2)+"%";return true};i.updateActiveAndVisitedSlides=function(e){var r,n,s=l.length;e=i._normalizeSlideNumber(e);if(!i._isNumber(e)){throw new Error("Gimme slide number as Number, baby!")}for(r=0;re){n.classList.remove("visited");n.classList.remove("active")}else{n.classList.remove("visited");n.classList.add("active")}}return true};i.clearPresenterNotes=function(){if(e.console&&e.console.clear){console.clear()}};i.showPresenterNotes=function(r){i.clearPresenterNotes();if(e.console){r=i._normalizeSlideNumber(r);var n=l[r].id,s=l[r+1]?l[r+1].id:null,o=t.getElementById(n).querySelector("footer");if(o&&o.innerHTML){console.info(o.innerHTML.replace(/\n\s+/g,"\n"))}if(s){var a=t.getElementById(s).querySelector("h2");if(a){a=a.innerHTML.replace(/^\s+|<[^>]+>/g,"");console.info("NEXT: "+a)}}}};i.getSlideHash=function(e){if(!i._isNumber(e)){throw new Error("Gimme slide number as Number, baby!")}e=i._normalizeSlideNumber(e);return"#"+l[e].id};i.runInnerNavigation=function(e){if(!i._isNumber(e)){throw new Error("Gimme slide number as Number, baby!")}e=i._normalizeSlideNumber(e);clearTimeout(u);if(l[e].hasTiming){var r=i._getData(t.getElementById(l[e].id),"timing").split(":");r=parseInt(r[0],10)*60*1e3+parseInt(r[1],10)*1e3;u=setTimeout(function(){i.next()},r)}return true};i.increaseInnerNavigation=function(e){var r,n;if(!i._isNumber(e)){throw new Error("Gimme slide number as Number, baby!")}if(l[e].hasInnerNavigation){r=t.getElementById(l[e].id).querySelectorAll(".next:not(.active)");if(0!==r.length){n=r[0];n.classList.add("active");return true}}return false};e.addEventListener("DOMContentLoaded",function(){if(s.classList.contains("full")||i.isSlideMode()){i.go(i.getCurrentSlideNumber());i.enterSlideMode()}},false);e.addEventListener("popstate",function(){if(i.isListMode()){i.enterListMode()}else{i.enterSlideMode()}},false);e.addEventListener("resize",function(){if(i.isSlideMode()){i._applyTransform(i._getTransform())}},false);t.addEventListener("keydown",function(e){if(e.altKey||e.ctrlKey||e.metaKey){return}var t=i.getCurrentSlideNumber(),r=true;switch(e.which){case 116:e.preventDefault();if(i.isListMode()){var n=e.shiftKey?t:0;i.go(n);i.enterSlideMode();i.showPresenterNotes(n)}else{i.enterListMode()}break;case 13:if(i.isListMode()&&-1!==t){e.preventDefault();i.enterSlideMode()}break;case 27:if(i.isSlideMode()){e.preventDefault();i.enterListMode()}break;case 33:case 38:case 37:case 72:case 75:e.preventDefault();i.previous();break;case 34:case 40:case 39:case 76:case 74:e.preventDefault();i.next();break;case 36:e.preventDefault();i.first();break;case 35:e.preventDefault();i.last();break;case 9:case 32:e.preventDefault();i[e.shiftKey?"previous":"next"]();break;default:}},false);t.addEventListener("click",function(e){var t=i.getSlideNumber(i._getSlideIdByEl(e.target));if(i.isListMode()&&i._getSlideIdByEl(e.target)){i.go(t);i.enterSlideMode();i.showPresenterNotes(t)}},false);t.addEventListener("touchstart",function(t){if(i._getSlideIdByEl(t.target)){if(i.isSlideMode()&&!i._checkInteractiveElement(t)){var r=t.touches[0].pageX;if(r>e.innerWidth/2){i.next()}else{i.previous()}}if(i.isListMode()){i.go(i.getSlideNumber(i._getSlideIdByEl(t.target)));i.enterSlideMode()}}},false);t.addEventListener("touchmove",function(e){if(i.isSlideMode()){e.preventDefault()}},false);return i}(this,this.document); \ No newline at end of file