bmstu-mt-wp/shower.min.js

6 lines
10 KiB
JavaScript
Raw Normal View History

2013-01-20 01:52:56 +04:00
/**
* Shower HTML presentation engine: github.com/shower/shower
* @copyright 20102013 Vadim Makeev, pepelsbey.net
* @license MIT license: github.com/shower/shower/wiki/MIT-License
*/
2013-01-20 14:38:53 +04:00
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<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(){var denominator=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;return true};shower._isNumber=function(arg){return!isNaN(parseFloat(arg))&&isFinite(arg)};shower._normalizeSlideNumber=function(slideNumber){if(!shower._isNumber(slideNumber)){throw new Error("Gimme slide number as Number, baby!")}if(slideNumber<0){slideNumber=0}if(slideNumber>=slideList.length){slideNumber=slideList.length-1}return slideNumber};shower._getSlideIdByEl=function(el){while("BODY"!==el.nodeName&&"HTML"!==el.nodeName){if(el.classList.contains("slide")){return el.id}else{el=el.parentNode}}return""};shower._checkInteractiveElement=function(e){return"A"===e.target.nodeName};shower.getSlideNumber=function(slideId){var i=slideList.length-1,slideNumber;if(slideId===""){slideNumber=0}for(;i>=0;--i){if(slideId===slideList[i].id){slideNumber=i;break}}return slideNumber};shower.next=function(callback){var currentSlideNumber=shower.getCurrentSlideNumber(),ret=false;if(-1===currentSlideNumber||!slideList[currentSlideNumber].hasInnerNavigation||-1===shower.increaseInnerNavigation(currentSlideNumber)){shower.go(currentSlideNumber+1);ret=currentSlideNumber+2;if(typeof callback==="function"){callback()}}return ret};shower.previous=function(callback){var currentSlideNumber=shower.getCurrentSlideNumber(),ret=false;if(currentSlideNumber>0){ret=currentSlideNumber;shower.go(currentSlideNumber-1);if(typeof callback==="function"){callback()}}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){var currentSlideNumber=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(typeof callback==="function"){callback()}return shower._applyTransform(shower._getTransform())};shower.enterListMode=function(callback){var currentSlideNumber=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(typeof callback==="function"){callback()}return shower._applyTransform("none")};shower.toggleMode=function(callback){if(shower.isListMode()){shower.enterSlideMode()}else{shower.enterListMode()}if(typeof callback==="function"){callback()}return true};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