bmstu-mt-wp/shower.min.js

6 lines
9.2 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-11-08 15:13:18 +04:00
window.shower=window.shower||function(e,i,t){var r={},n=e.location,s=i.body,l=[],o=[],a,u=!!(e.history&&e.history.pushState);function d(e){for(var i in e){if(e.hasOwnProperty(i)){this[i]=e[i]}}}d.prototype={getSlideNumber:function(){return this.number},isLast:function(){return r.slideList.length===this.number+1},isFinished:function(){return this.innerComplete>=this.innerLength},process:function(e){if(this.timing){this.initTimer(e);return this}this.next(e);return this},initTimer:function(e){var i=this;if(!i.timing){return false}i.stopTimer();if(i.isFinished()){a=setInterval(function(){i.stopTimer();e.next()},i.timing*(i.innerLength||1))}else{a=setInterval(function(){if(i.isFinished()){i.stopTimer();e.next()}else{i.next(e)}},i.timing)}return this},stopTimer:function(){if(a){clearInterval(a);a=false}return this},prev:function(e){var t,r=this;if(!r.hasInnerNavigation||r.isFinished()||r.innerComplete===0){e.prev();return false}t=i.getElementById(r.id).querySelectorAll(".next.active");if(!t||t.length<1){return false}if(r.innerComplete>0){r.innerComplete--;t[t.length-1].classList.remove("active")}else{e.prev()}return this},next:function(e){var t,r=this;if(!r.hasInnerNavigation||r.isFinished()){e.next();return false}if(!r.isFinished()){t=i.getElementById(r.id).querySelectorAll(".next:not(.active)");t[0].classList.add("active");r.innerComplete++}return this}};r._getData=function(e,i){return e.dataset?e.dataset[i]:e.getAttribute("data-"+i)};r.slideList=[];r.init=function(e,t){var n;e=e||".slide";t=t||"div.progress div";l=i.querySelectorAll(e);o=i.querySelector(t);for(var s=0;s<l.length;s++){if(!l[s].id){l[s].id=s+1}n=r._getData(l[s],"timing");if(n&&/^(\d{1,2}:)?\d{1,3}$/.test(n)){if(n.indexOf(":")!==-1){n=n.split(":");n=(parseInt(n[0],10)*60+parseInt(n[1],10))*1e3}else{n=parseInt(n,10)*1e3}if(n===0){n=false}}else{n=false}r.slideList.push(new d({id:l[s].id,number:s,hasInnerNavigation:null!==l[s].querySelector(".next"),timing:n,innerLength:l[s].querySelectorAll(".next").length,innerComplete:0}))}return r};r._getTransform=function(){var i=Math.max(s.clientWidth/e.innerWidth,s.clientHeight/e.innerHeight);return"scale("+1/i+")"};r._applyTransform=function(e){["WebkitTransform","MozTransform","msTransform","OTransform","transform"].forEach(function(i){s.style[i]=e});return true};r._isNumber=function(e){return!isNaN(parseFloat(e))&&isFinite(e)};r._normalizeSlideNumber=function(e){if(!r._isNumber(e)){throw new Error("Gimme slide number as Number, baby!")}if(e<0){e=0}if(e>=r.slideList.length){e=r.slideList.length-1}return e};r._getSlideIdByEl=function(e){while("BODY"!==e.nodeName&&"HTML"!==e.nodeName){if(e.classList.contains("slide")){return e.id}else{e=e.parentNode}}return""};r._checkInteractiveElement=function(e){return"A"===e.target.nodeName};r.getSlideNumber=function(e){var i=r.slideList.length-1,t;if(e===""){t=0}for(;i>=0;--i){if(e===r.slideList[i].id){t=i;break}}return t};r.go=function(e,i){var t;if(!r._isNumber(e)){throw new Error("Gimme slide number as Number, baby!")}if(!r.slideList[e]){return false}n.hash=r.getSlideHash(e);r.updateProgress(e);r.updateActiveAndVisitedSlides(e);if(r.isSlideMode()){r.showPresenterNotes(e);t=r.slideList[e];if(t.timing){t.initTimer(r)}}if(typeof i==="function"){i()}return e};r.next=function(e){var i=r.getCurrentSlideNumber(),t=r.slideList[i+1];if(!t){return false}r.go(i+1);if(typeof e==="function"){e()}return this};r._turnNextSlide=function(e){var i=r.getCurrentSlideNumber(),t=r.slideList[i];if(r.isSlideMode()){t.stopTimer();t.next(r)}else{r.go(i+1)}if(typeof e==="function"){e()}return};r.prev=r.previous=function(e){var i=r.getCurrentSlideNumber();if(i<1){return false}r.go(i-1);if(typeof e==="function"){e()}return true};r._turnPreviousSlide=function(e){var i=r.getCurrentSlideNumber(),t=r.slideList[i];t.stopTimer();if(r.isSlideMode()){t.prev(r)}else{r.go(i-1)}if(typeof e==="function"){e()}return true};r.first=function(e){var i=r.slideList[r.getCurrentSlideNumber()];i.timing&&i.stopTimer();r.go(0);if(typeof e==="function"){e()}};r.last=function(e){var i=r.slideList[r.getCurrentSlideNumber()];i.timing&&