* @license MIT license: github.com/shower/shower/wiki/MIT-License
* @license MIT license: github.com/shower/shower/wiki/MIT-License
*/
*/
window.shower=function(window,document,undefined){varshower={},url=window.location,body=document.body,slides=document.querySelectorAll(".slide"),progress=document.querySelector("div.progress div"),slideList=[],timer,isHistoryApiSupported=!!(window.history&&history.pushState),l=slides.length,i;shower._getData=function(element,name){returnelement.dataset?element.dataset[name]:element.getAttribute("data-"+name)};for(i=0;i<l;i++){if(!slides[i].id){slides[i].id=i+1}slideList.push({id:slides[i].id,hasInnerNavigation:null!==slides[i].querySelector(".next"),hasTiming:shower._getData(slides[i],"timing")&&shower._getData(slides[i],"timing").indexOf(":")!==-1})}shower._getTransform=function(){vardenominator=Math.max(body.clientWidth/window.innerWidth,body.clientHeight/window.innerHeight);return"scale("+1/denominator+")"};shower._applyTransform=function(transform){body.style.WebkitTransform=transform;body.style.MozTransform=transform;body.style.msTransform=transform;body.style.OTransform=transform;body.style.transform=transform;returntrue};shower._isNumber=function(arg){return!isNaN(parseFloat(arg))&&isFinite(arg)};shower._normalizeSlideNumber=function(slideNumber){if(!shower._isNumber(slideNumber)){thrownewError("Gimme slide number as Number, baby!")}if(slideNumber<0){slideNumber=0}if(slideNumber>=slideList.length){slideNumber=slideList.length-1}returnslideNumber};shower._getSlideIdByEl=function(el){while("BODY"!==el.nodeName&&"HTML"!==el.nodeName){if(el.classList.contains("slide")){returnel.id}else{el=el.parentNode}}return""};shower._checkInteractiveElement=function(e){return"A"===e.target.nodeName};shower.getSlideNumber=function(slideId){vari=slideList.length-1,slideNumber;if(slideId===""){slideNumber=0}for(;i>=0;--i){if(slideId===slideList[i].id){slideNumber=i;break}}returnslideNumber};shower.next=function(callback){varcurrentSlideNumber=shower.getCurrentSlideNumber(),ret=false;if(-1===currentSlideNumber||!slideList[currentSlideNumber].hasInnerNavigation||-1===shower.increaseInnerNavigation(currentSlideNumber)){shower.go(currentSlideNumber+1);ret=currentSlideNumber+2;if(typeofcallback==="function"){callback()}}returnret};shower.previous=function(callback){varcurrentSlideNumber=shower.getCurrentSlideNumber(),ret=false;if(currentSlideNumber>0){ret=currentSlideNumber;shower.go(currentSlideNumber-1);if(typeofcallback==="function"){callback()}}returnret};shower.first=function(callback){if(typeofcallback==="function"){callback()}returnshower.go(0)};shower.last=function(callback){if(typeofcallback==="function"){callback()}returnshower.go(slideList.length-1)};shower.enterSlideMode=function(callback){varcurrentSlideNumber=shower.getCurrentSlideNumber();if(currentSlideNumber===-1){currentSlideNumber=0}shower.go(currentSlideNumber);shower.showPresenterNotes(currentSlideNumber);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.runSlideshowIfPresented(currentSlideNumber);if(typeofcallback==="function"){callback()}returnshower._applyTransform(shower._getTransform())};shower.enterListMode=function(callback){varcurrentSlideNumber=shower.getCurrentSlideNumber();body.classList.remove("full");body.classList.add("list");if(shower.isSlideMode()&&isHistoryApiSupported){history.pushState(null,null,url.pathname+shower.getSlideHash(currentSlideNumber))}shower.scrollToSlide(currentSlideNumber);if(typeofcallback==="function"){callback()}returnshower._applyTransform("none")};shower.toggleMode=function(callback){if(shower.isListMode()){shower.enterSlideMode()}else{shower.enterListMode()}if(typeofcallback==="function"){callback()}returntrue};shower.getCurrentSlideNumber=function(){vari=slideList.length-1,currentSlideId=url.hash.substr(1);for(;i>=0;--i){if(currentSlideId===slideList[i].id){returni}}return-1};shower.scrollToSlide=function(slideNumber){varcurrentSlide,ret=false;if(!shower._isNumber(slideNumber)){thrownewError("Gimme slide number as Number, baby!")}if(shower.isSlideMode()){thrownewError("You can't scroll to because you in slide mode. Please, switch to list mode.")}if(-1===slideNumber){returnret}if(slideList[slideNumber]){currentSlide=document.getElementById(slideList[slideNumber].id);window.scrollTo(0,currentSlide.offsetTop);ret=true}else{thrownewError("There is no slide with number "+slideNumber)}returnret};shower.isListMode=function(){returnisHistoryApiSupported?!/^full.*/.test(url.search.substr(1)):body.classList.contains("list")};shower.isSlideMode=function(){returnisHistoryApiSupported?/^full.*/.test(url.search.substr(1)):body.classList.contains("full")};shower.updateProgress=function(slideNumber){if(null===progress){returnfalse}if(!shower._isNumber(slideNumber)){thrownewError("Gimme slide number as Number, baby!")}progress.style.width=(100/(slideList.length-1)*shower._normalizeSlideNumber(slideNumber)).toFixed(2)+"%";returntrue};shower.updateCurrentAndPassedSlides=function(slideNumber){vari,slide,l=slideList.length;slideNumber=shower._normalizeSlideNumber(slideNumber);if(!shower._isNumber(slideNumber)){thrownewError("Gimme slide number as Number, baby!")}for(i=0;i<l;++i){slide=document.getElementById(slideList[i].id);if(i<slideNumber){slide.classList.remove("active");slide.classList.add("visited")}elseif(i>slideNumber){slide.classList.remove("visited");slide.classList.remove("active")}else{slide.classList.remove("visited");slide.classList.add("active")}}returntrue};shower.showPresenterNotes=function(slideNumber){if(window.console){slideNumber=shower._normalizeSlideNumber(slideNumber);varslideId=slideList[slideNumber].id,nextSlideId=slideList[slideNumber+1]?slideList[slideNumber+1].id:null,notes=document.getElementById(slideId).querySelector("footer");if(notes){console.info(notes.innerHTML.replace(/\n\s+/g,"\n"))}if(nextSlideId){varnext=document.getElementById(nextSlideId).querySelector("h2");if(next){next=next.innerHTML.replace(/^\s+|<[^>]+>/g,"");console.info("NEXT: "+next)}}}};shower.getSlideHash=function(slideNumber){if(!shower._isNumber(slideNumber)){thrownewError("Gimme slide number as Number, baby!")}slideNumber=shower._normalizeSlideNumber(slideNumber);return"#"+slideList[slideNumber].id};shower.go=function(slideNumber,callback){if(!shower._isNumber(slideNumber)){thrownewError("Gimme slide number as Number, baby!")}url.hash=shower.getSlideHash(slideNumber);if(shower.isSlideMode()){shower.updateProgress(slideNumber);shower.updateCurrentAndPassedSlides(slideNumber);shower.showPresenterNotes(slideNumber);if(typeofcallback==="function"){callback()}}returnslideNumber};shower.runSlideshowIfPresented=function(slideNumber){if(!shower._isNumber(slideNumber)){thrownewError("Gimme slide number as Number, baby!")}slideNumber=shower._normalizeSlideNumber(slideNumber);clearTimeout(timer);if(slideList[slideNumber].hasTiming){vartiming=shower._getData(document.getElementById(slideList[slideNumber].id),"timing").split(":");timing=parseInt(timing[0],10)*60*1e3+parseInt(timing[1],10)*1e3;timer=setTimeout(function(){shower.go(slideNumber+1);shower.runSlideshowIfPresented(slideNumber+1)},timing)}returntrue};shower.increaseInnerNavigation=function(slideNumber){varnextNodes,node,ret=-1;if(!shower._isNumber(slideNumber)){thrownewError("Gimme slide number as Number, baby!")}if(slideList[slideNumber].hasInnerNavigation){nextNodes=document.getElementById(slideList[slideNumber].id).querySelectorAll(".next:not(.active)");if(0!==nextNodes.length){node=nextNodes[0];node.classList.add("active");ret=nextNodes.length-1}}returnret};window.addEventListener("DOMContentLoaded",function(){if(body.classList.contains("full")){shower.enterSlideMode()}},false);window.addEventListener("popstate",function(){if(shower.isListMode()){shower.enterListMode()}else{shower.enterSlideMode()}},false);window.addEventListener("resize",function(){if(shower.isSlideMode()){shower._applyTransform(shower._getTransform())}},false);document.addEventListener("keydown",function(e){if(e.altKey||e.ctrlKey||e.metaKey){return}varcurrentSlideNumber=shower.getCurrentSlideNumber(),innerNavigationCompleted=true;switch(e.which){case116:e.preventDefault();if(shower.isListMode()){varslideNumber=e.shiftKey?currentSlideNumber:0;shower.go(slideNumber);shower.enterSlideMode()}else{shower.enterListMode()}break;case13:if(shower.isListMode()&&-1!==currentSlideNumber){e.preventDefault();shower.enterSlideMode()}break;case27:if(shower.isSlideMode()){e.preventDefault();shower.enterListMode()}break;case33:case38:case37:case72:case75:e.preventDefault();shower.previous();break;case34:case40:case39:case76:case74:e.preventDefault();if(shower.isSlideMode()){innerNavigationCompleted=!slideList[currentSlideNumber].hasInnerNavigation||-1===shower.increaseInnerNavigation(currentSlideNumber)}else{innerNavigationCompleted=true}if(-1===currentSlideNumber||innerNavigationCompleted){currentSlideNumber++;shower.go(currentSlideNumber);if(shower.isSlideMode()){shower.runSlideshowIfPresented(currentSlideNumber)}}break;case36:e.preventDefault();shower.first();break;case35:e.preventDefault();shower.last();break;case9:case32:e.preventDefault();shower[e.shiftKey?"previous":"next"]();break;default:}},false);document.addEventListener("click",function(e){if(shower.isListMode()&&shower._getSlideIdByEl(e.target)){e.preventDefault();shower.go(shower.getSlideNumber(shower._getSlideIdByEl(e.target)));shower.enterSlideMode()}},false);document.addEventListener("touchstart",function(e){if(shower._getSlideIdByEl(e.target)){if(shower.isSlideMode()&&!shower._checkInteractiveElement(e)){varx=e.touches[0].pageX;if(x>window.innerWidth/2){shower.next()}else{shower.previous()}}if(shower.isListMode()){shower.go(shower.getSlideNumber(shower._getSlideIdByEl(e.target)));shower.enterSlideMode()}}},false);document.addEventListener("touchmove",function(e){if(shower.isSlideMode()){e.preventDefault()}},false);returnshower}(this,this.document);
window.shower=function(e,t,n){varr={},i=e.location,s=t.body,o=t.querySelectorAll(".slide"),u=t.querySelector("div.progress div"),a=[],f,l=!!e.history&&!!history.pushState,c=o.length,h;r._getData=function(e,t){returne.dataset?e.dataset[t]:e.getAttribute("data-"+t)};for(h=0;h<c;h++)o[h].id||(o[h].id=h+1),a.push({id:o[h].id,hasInnerNavigation:null!==o[h].querySelector(".next"),hasTiming:r._getData(o[h],"timing")&&r._getData(o[h],"timing").indexOf(":")!==-1});returnr._getTransform=function(){vart=Math.max(s.clientWidth/e.innerWidth,s.clientHeight/e.innerHeight);return"scale("+1/t+")"},r._applyTransform=function(e){returns.style.WebkitTransform=e,s.style.MozTransform=e,s.style.msTransform=e,s.style.OTransform=e,s.style.transform=e,!0},r._isNumber=function(e){return!isNaN(parseFloat(e))&&isFinite(e)},r._normalizeSlideNumber=function(e){if(!r._isNumber(e))thrownewError("Gimme slide number as Number, baby!");returne<0&&(e=0),e>=a.length&&(e=a.length-1),e},r._getSlideIdByEl=function(e){while("BODY"!==e.nodeName&&"HTML"!==e.nodeName){if(e.classList.contains("slide"))returne.id;e=e.parentNode}return""},r._checkInteractiveElement=function(e){return"A"===e.target.nodeName},r.getSlideNumber=function(e){vart=a.length-1,n;e===""&&(n=0);for(;t>=0;--t)if(e===a[t].id){n=t;break}returnn},r.go=function(e,t){if(!r._isNumber(e))thrownewError("Gimme slide number as Number, baby!");returni.hash=r.getSlideHash(e),r.isSlideMode()&&(r.showPresenterNotes(e),r.updateProgress(e),r.updateCurrentAndPassedSlides(e),r.runInnerNavigation(e)),typeoft=="function"&&t(),e},r.next=function(e){vart=r.getCurrentSlideNumber(),n=!1;return(-1===t||!a[t].hasInnerNavigation||!r.increaseInnerNavigation(t))&&t+2<=a.length&&(r.go(t+1),n=t+2),r.isSlideMode()&&r.runInnerNavigation(t+1),typeofe=="function"&&e(),n},r.previous=function(e){vart=r.getCurrentSlideNumber(),n=!1;returnt>0&&(n=t,r.go(t-1),typeofe=="function"&&e()),n},r.first=function(e){returntypeofe=="function"&&e(),r.go(0)},r.last=function(e){returntypeofe=="function"&&e(),r.go(a.length-1)},r.enterSlideMode=function(e){vart=r.getCurrentSlideNumber();returns.classList.remove("list"),s.classList.add("full"),r.isListMode()&&l&&history.pushState(null,null,i.pathname+"?full"+r.getSlideHash(t)),r._applyTransform(r._getTransform()),typeofe=="function"&&e(),!0},r.enterListMode=function(e){s.classList.remove("full"),s.classList.add("list"),r.clearPresenterNotes();if(r.isListMode())return!1;vart=r.getCurrentSlideNumber();returnclearTimeout(f),r.isSlideMode()&&l&&history.pushState(null,null,i.pathname+r.getSlideHash(t)),r.scrollToSlide(t),r._applyTransform("none"),typeofe=="function"&&e(),!0},r.toggleMode=function(e){returnr.isListMode()?r.enterSlideMode():r.enterListMode(),typeofe=="function"&&e(),!0},r.getCurrentSlideNumber=function(){vare=a.length-1,t=i.hash.substr(1);for(;e>=0;--e)if(t===a[e].id)returne;return-1},r.scrollToSlide=function(n){vari,s=!1;if(!r._isNumber(n))thrownewError("Gimme slide number as Number, baby!");if(r.isSlideMode())thrownewError("You can't scroll to because you in slide mode. Please, switch to list mode.");if(-1===n)returns;if(!a[n])thrownewError("There is no slide with number "+n);returni=t.getElementById(a[n].id),e.scrollTo(0,i.offsetTop),s=!0,s},r.isListMode=function(){returnl?!/^full.*/.test(i.search.substr(1)):s.classList.contains("list")},r.isSlideMode=function(){returnl?/^full.*/.test(i.search.substr(1)):s.classList.contains("full")},r.updateProgress=function(e){if(null===u)return!1;if(!r._isNumber(e))thrownewError("Gimme slide number as Number, baby!");returnu.style.width=(100/(a.length-1)*r._normalizeSlideNumber(e)).toFixed(2)+"%",!0},r.updateCurrentAndPassedSlides=function(e){varn,i,s=a.length;e=r._normalizeSlideNumber(e);if(!r._isNumber(e))thrownewError("Gimme slide number as Number, baby!");for(n=0;n<s;++n)i=t.getElementById(a[n].id),n<e?(i.classList.remove("active"),i.classList.add("visited")):n>e?(i.classList.remove("visited"),i.classList.remove("active")):(i.classList.remove("visited"),i.classList.add("active"));return!0},r.clearPresenterNotes=function(){e.console&&e.console.clear&&console.clear()},r.showPresenterNotes=function(n){r.clearPresenterNotes();if(e.console){n=r._normalizeSlideNumber(n);vari=a[n].id,s=a[n+1]?a[n+1].id:null,o=t.getElementById(i).querySelector("footer");o&&o.innerHTML&&console.info(o.innerHTML.replace(/\n\s+/g,"\n"));if(s){varu=t.getElementById(s).querySelector("h2");u&&(u=u.innerHTML.replace(/^\s+|<[^>]+>/g,""),console.info("NEXT: "+u))}}},r.getSlideHash=function(e){if(!r._isNumber(e))thrownewError("Gimme slide number as Number, baby!");returne=r._normalizeSlideNumber(e),"#"+a[e].id},r.runInnerNavigation=function(e){if(!r._isNumber(e))thrownewError("Gimme slide number as Number, baby!");e=r._normalizeSlideNumber(e),clearTimeout(f);if(a[e].hasTiming){varn=r._getData(t.getElementById(a[e].id),"timing").split(":");n=parseInt(n[0],10)*60*1e3+parseInt(n[1],10)*1e3,f=setTimeout(function(){r.next()},n)}return!0},r.increaseInnerNavigation=function(e){varn,i;if(!r._isNumber(e))thrownewError("Gimme slide number as Number, baby!");if(a[e].hasInnerNavigation){n=t.getElementById(a[e].id).querySelectorAll(".next:not(.active)");if(0!==n.length)returni=n[0],i.classList.add("active"),!0}return!1},e.addEventListener("DOMContentLoaded",function(){if(s.classList.contains("full")||r.isSlideMode())r.go(r.getCurrentSlideNumber()),r.enterSlideMode()},!1),e.addEventListener("popstate",function(){r.isListMode()?r.enterListMode():r.enterSlideMode()},!1),e.addEventListener("resize",function(){r.isSlideMode()&&r._applyTransform(r._getTransform())},!1),t.addEventListener("keydown",function(e){if(e.altKey||e.ctrlKey||e.metaKey)return;vart=r.getCurrentSlideNumber(),n=!0;switch(e.which){case116:e.preventDefault();if(r.isListMode()){vari=e.shiftKey?t:0;r.go(i),r.enterSlideMode(),r.showPresenterNotes(i)}elser.enterListMode();break;case13:r.isListMode()&&-1!==t&&(e.preventDefault(),r.enterSlideMode());break;case27:r.isSlideMode()&&(e.preventDefault(),r.enterListMode());break;case33:case38:case37:case72:case75:e.preventDefault(),r.previous();break;case34:case40:case39:case76:case74:e.preventDefault(),r.next();break;case36:e.preventDefault(),r.first();break;case35:e.preventDefault(),r.last();break;case9:case32:e.preventDefault(),r[e.shiftKey?"previous":"next"]();break;default:}},!1),t.addEventListener("click",function(e){e.preventDefault();vart=r.getSlideNumber(r._getSlideIdByEl(e.target));r.isListMode()&&r._getSlideIdByEl(e.target)&&(r.go(t),r.enterSlideMode(),r.showPresenterNotes(t))},!1),t.addEventListener("touchstart",function(t){if(r._getSlideIdByEl(t.target)){if(r.isSlideMode()&&!r._checkInteractiveElement(t)){varn=t.touches[0].pageX;n>e.innerWidth/2?r.next():r.previous()}r.isListMode()&&(r.go(r.getSlideNumber(r._getSlideIdByEl(t.target))),r.enterSlideMode())}},!1),t.addEventListener("touchmove",function(e){r.isSlideMode()&&e.preventDefault()},!1),r}(this,this.document);