From 08eefa5903c7a87d143ff621069e65b7f12de795 Mon Sep 17 00:00:00 2001 From: Vadim Makeev Date: Sat, 19 Jan 2013 05:22:25 +0400 Subject: [PATCH] Minified shower.js --- shower.min.js | 1 + 1 file changed, 1 insertion(+) create mode 100644 shower.min.js diff --git a/shower.min.js b/shower.min.js new file mode 100644 index 0000000..d7c1571 --- /dev/null +++ b/shower.min.js @@ -0,0 +1 @@ +window.shower=function(window,document,undefined){var shower={},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){return element.dataset?element.dataset[name]:element.getAttribute("data-"+name)};for(i=0;i=slideList.length){slideNumber=slideList.length-1}return slideNumber};shower._getContainingSlideId=function(el){while("BODY"!==el.nodeName&&"HTML"!==el.nodeName){if(el.classList.contains("slide")){return el.id}else{el=el.parentNode}}return""};shower._dispatchSingleSlideMode=function(e){if("A"===e.target.nodeName){e.preventDefault();window.open(e.target.getAttribute("href"));return}var slideId=shower._getContainingSlideId(e.target);if(""!==slideId&&shower.isListMode()){e.preventDefault();url.hash="#"+slideId;if(isHistoryApiSupported){history.replaceState(null,null,url.pathname+"?full#"+slideId)}shower.enterSlideMode();shower.updateProgress(shower.getCurrentSlideNumber());shower.updateCurrentAndPassedSlides(shower.getCurrentSlideNumber());shower.runSlideshowIfPresented(shower.getCurrentSlideNumber())}return};shower.next=function(callback){var currentSlideNumber=shower.getCurrentSlideNumber(),ret;if(-1===currentSlideNumber||!slideList[currentSlideNumber].hasInnerNavigation||-1===shower.increaseInnerNavigation(currentSlideNumber)){shower.go(currentSlideNumber+1);ret=currentSlideNumber+2;if(typeof callback==="function"){callback()}}else{ret=false}return ret};shower.previous=function(callback){var currentSlideNumber=shower.getCurrentSlideNumber(),ret;if(currentSlideNumber>0){ret=currentSlideNumber;shower.go(currentSlideNumber-1);if(typeof callback==="function"){callback()}}else{ret=false}return ret};shower.first=function(callback){if(typeof callback==="function"){callback()}return shower.go(0)};shower.last=function(callback){if(typeof callback==="function"){callback()}return shower.go(slideList.length-1)};shower.enterSlideMode=function(callback){if(body.classList.contains("full")){return false}body.classList.remove("list");body.classList.add("full");if(window.console&&window.console.clear){console.clear()}shower.showPresenterNotes(shower.getCurrentSlideNumber());if(typeof callback==="function"){callback()}return shower._applyTransform(shower._getTransform())};shower.enterListMode=function(callback){if(body.classList.contains("list")){return false}body.classList.remove("full");body.classList.add("list");if(typeof callback==="function"){callback()}return shower._applyTransform("none")};shower.getCurrentSlideNumber=function(){var i=slideList.length-1,currentSlideId=url.hash.substr(1);for(;i>=0;--i){if(currentSlideId===slideList[i].id){return i}}return-1};shower.scrollToSlide=function(slideNumber){var currentSlide,ret;if(!shower._isNumber(slideNumber)){throw new Error("Gimme slide number as Number, baby!")}if(!shower.isListMode()){throw new Error("You can't scroll to because you in slide mode. Please, switch to list mode.")}if(-1===slideNumber){return}if(slideList[slideNumber]){currentSlide=document.getElementById(slideList[slideNumber].id);window.scrollTo(0,currentSlide.offsetTop);ret=true}else{throw new Error("There is no slide with number "+slideNumber)}return ret};shower.isListMode=function(){return isHistoryApiSupported?!/^full.*/.test(url.search.substr(1)):body.classList.contains("list")};shower.updateProgress=function(slideNumber){if(null===progress){return false}if(!shower._isNumber(slideNumber)){throw new Error("Gimme slide number as Number, baby!")}progress.style.width=(100/(slideList.length-1)*shower._normalizeSlideNumber(slideNumber)).toFixed(2)+"%";return true};shower.updateCurrentAndPassedSlides=function(slideNumber){var i,slide,l=slideList.length;slideNumber=shower._normalizeSlideNumber(slideNumber);if(!shower._isNumber(slideNumber)){throw new Error("Gimme slide number as Number, baby!")}for(i=0;islideNumber){slide.classList.remove("passed");slide.classList.remove("current")}else{slide.classList.remove("passed");slide.classList.add("current")}}return true};shower.showPresenterNotes=function(slideNumber){if(window.console){slideNumber=shower._normalizeSlideNumber(slideNumber);var slideId=slideList[slideNumber].id;var nextSlideId=slideList[slideNumber+1]?slideList[slideNumber+1].id:null;var notes=document.getElementById(slideId).querySelector("footer");if(notes){console.info(notes.innerHTML.replace(/\n\s+/g,"\n"))}if(nextSlideId){var next=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)){throw new Error("Gimme slide number as Number, baby!")}slideNumber=shower._normalizeSlideNumber(slideNumber);return"#"+slideList[slideNumber].id};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.isListMode()){shower.updateProgress(slideNumber);shower.updateCurrentAndPassedSlides(slideNumber);shower.showPresenterNotes(slideNumber);if(typeof callback==="function"){callback()}}return slideNumber};shower.runSlideshowIfPresented=function(slideNumber){if(!shower._isNumber(slideNumber)){throw new Error("Gimme slide number as Number, baby!")}slideNumber=shower._normalizeSlideNumber(slideNumber);clearTimeout(timer);if(slideList[slideNumber].hasTiming){var timing=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)}};shower.increaseInnerNavigation=function(slideNumber){var nextNodes,node,ret=-1;if(!shower._isNumber(slideNumber)){throw new Error("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}}return ret};window.addEventListener("DOMContentLoaded",function(){if(!shower.isListMode()){if(-1===shower.getCurrentSlideNumber()){if(isHistoryApiSupported){history.replaceState(null,null,url.pathname+"?full"+shower.getSlideHash(0))}}shower.enterSlideMode();shower.updateProgress(shower.getCurrentSlideNumber());shower.updateCurrentAndPassedSlides(shower.getCurrentSlideNumber());shower.runSlideshowIfPresented(shower.getCurrentSlideNumber())}},false);window.addEventListener("popstate",function(e){if(shower.isListMode()){shower.enterListMode();shower.scrollToSlide(shower.getCurrentSlideNumber())}else{shower.enterSlideMode()}},false);window.addEventListener("resize",function(e){if(!shower.isListMode()){shower._applyTransform(shower._getTransform())}},false);document.addEventListener("keydown",function(e){if(e.altKey||e.ctrlKey||e.metaKey){return}var currentSlideNumber=shower.getCurrentSlideNumber(),innerNavigationCompleted=true;switch(e.which){case 116:e.preventDefault();if(shower.isListMode()){var slideNumber=e.shiftKey?currentSlideNumber:0;shower.go(slideNumber);if(isHistoryApiSupported){history.pushState(null,null,url.pathname+"?full"+shower.getSlideHash(slideNumber))}shower.enterSlideMode();shower.updateProgress(slideNumber);shower.updateCurrentAndPassedSlides(slideNumber);shower.runSlideshowIfPresented(slideNumber)}else{if(isHistoryApiSupported){history.pushState(null,null,url.pathname+shower.getSlideHash(currentSlideNumber))}shower.enterListMode();shower.scrollToSlide(currentSlideNumber)}break;case 13:if(shower.isListMode()&&-1!==currentSlideNumber){e.preventDefault();if(isHistoryApiSupported){history.pushState(null,null,url.pathname+"?full"+shower.getSlideHash(currentSlideNumber))}shower.enterSlideMode();shower.updateProgress(currentSlideNumber);shower.updateCurrentAndPassedSlides(currentSlideNumber);shower.runSlideshowIfPresented(currentSlideNumber)}break;case 27:if(!shower.isListMode()){e.preventDefault();if(isHistoryApiSupported){history.pushState(null,null,url.pathname+shower.getSlideHash(currentSlideNumber))}shower.enterListMode();shower.scrollToSlide(currentSlideNumber)}break;case 33:case 38:case 37:case 72:case 75:e.preventDefault();shower.previous();break;case 34:case 40:case 39:case 76:case 74:e.preventDefault();if(!shower.isListMode()){innerNavigationCompleted=!slideList[currentSlideNumber].hasInnerNavigation||-1===shower.increaseInnerNavigation(currentSlideNumber)}else{innerNavigationCompleted=true}if(-1===currentSlideNumber||innerNavigationCompleted){currentSlideNumber++;shower.go(currentSlideNumber);if(!shower.isListMode()){shower.runSlideshowIfPresented(currentSlideNumber)}}break;case 36:e.preventDefault();shower.first();break;case 35:e.preventDefault();shower.last();break;case 9:case 32:e.preventDefault();shower[e.shiftKey?"previous":"next"]();break;default:}},false);document.addEventListener("click",shower._dispatchSingleSlideMode,false);document.addEventListener("touchend",shower._dispatchSingleSlideMode,false);document.addEventListener("touchstart",function(e){if(!shower.isListMode()){var currentSlideNumber=shower.getCurrentSlideNumber(),x=e.touches[0].pageX;if(x>window.innerWidth/2){currentSlideNumber++}else{currentSlideNumber--}shower.go(currentSlideNumber)}},false);document.addEventListener("touchmove",function(e){if(!shower.isListMode()){e.preventDefault()}},false);return shower}(this,this.document); \ No newline at end of file