bmstu-mt-wp/shower.min.js

6 lines
7.3 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-02-05 22:06:51 +04:00
window.shower=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<f;c++){if(!o[c].id){o[c].id=c+1}l.push({id:o[c].id,hasInnerNavigation:null!==o[c].querySelector(".next"),hasTiming:i._getData(o[c],"timing")&&i._getData(o[c],"timing").indexOf(":")!==-1})}i._getTransform=function(){var t=Math.max(s.clientWidth/e.innerWidth,s.clientHeight/e.innerHeight);return"scale("+1/t+")"};i._applyTransform=function(e){s.style.WebkitTransform=e;s.style.MozTransform=e;s.style.msTransform=e;s.style.OTransform=e;s.style.transform=e;return true};i._isNumber=function(e){return!isNaN(parseFloat(e))&&isFinite(e)};i._normalizeSlideNumber=function(e){if(!i._isNumber(e)){throw new Error("Gimme slide number as Number, baby!")}if(e<0){e=0}if(e>=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;r<s;++r){n=t.getElementById(l[r].id);if(r<e){n.classList.remove("active");n.classList.add("visited")}else if(r>e){