-
Notifications
You must be signed in to change notification settings - Fork 4
/
slides.min.js
1 lines (1 loc) · 2.78 KB
/
slides.min.js
1
(function(d,e){var a=d.document,b=a.location;var f=function(j,h){if(h){for(var g in j){if((typeof h[g])==="undefined"){h[g]=j[g]}}return h}else{return j}};var c=function(g){if(!(this instanceof c)){return new c(g)}g=f({container:"#slides",pages:".page",hashPrefix:"slide-",prev:"#prev",next:"#next",changeBtn:"#changeType",changeTypes:["slides","slides2"],typeArr:["p-current","p-past","p-past-far","p-next","p-next-far"],typeCount:0},g);this.container=a.querySelector(g.container);this.pages=this.container.querySelectorAll(g.pages);this.prevBtn=a.querySelector(g.prev);this.nextBtn=a.querySelector(g.next);this.hashPrefix=g.hashPrefix;this.currentPage=null;this.totalPages=this.pages.length;this.changeBtn=a.querySelector(g.changeBtn);this.changeTypes=g.changeTypes;this.typeCount=g.typeCount;this.curType=this.changeTypes[this.typeCount];this.typeArr=g.typeArr;this.init()};c.prototype={constructor:c,init:function(){var g=this;g.bindUI();g.container.className=g.curType;g.currentPage=g._getPageFromHash();g._emptyClass();g.gotoPage(g.currentPage);g._setPageToHash(g.currentPage)},bindUI:function(){var g=this;this.prevBtn.addEventListener("click",function(h){h.preventDefault();g.prev()},false);this.nextBtn.addEventListener("click",function(h){h.preventDefault();g.next()},false);d.addEventListener("hashchange",function(i){var h=g._getPageFromHash();g.currentPage=h;g._emptyClass();g.gotoPage(h)},false);this.changeBtn.addEventListener("click",function(h){h.preventDefault();g._changeType();g.container.className=g.curType},false);d.addEventListener("keydown",function(h){switch(h.keyCode){case 39:case 40:case 13:case 32:case 34:g.next();break;case 37:case 38:case 33:case 27:g.prev();break}},false)},_changeType:function(){var g=this;g.typeCount=(g.typeCount===g.changeTypes.length-1)?0:g.typeCount+1;g.curType=g.changeTypes[g.typeCount]},_getPageFromHash:function(){var h=this,g=h.hashPrefix,l=h.totalPages,k=b.hash.slice(1),j=g===""?k:k.split(g)[1],i=parseInt(j,10);if(isNaN(i)||i<1){i=1}else{if(i>l){i=l}}return i},_setPageToHash:function(i){var h=this,g=h.hashPrefix;b.hash="#"+g+i},_emptyClass:function(){var p=this.typeArr,n=0,h=this.totalPages,k=p.length,g=this.pages;for(;n<h;n++){var o=g[n];for(var m=0;m<k;m++){o.classList.remove(p[m])}}},gotoPage:function(g){var t=this,h=t.pages,s=g-1,r=g-2,q=g-3,m=g,k=g+1,l=0,o=t.totalPages,j=this.typeArr;for(;l<o;l++){var p=h[l];switch(l){case s:p.classList.add(j[0]);break;case r:p.classList.add(j[1]);break;case q:p.classList.add(j[2]);break;case m:p.classList.add(j[3]);break;case k:p.classList.add(j[4]);break}}},prev:function(){var g=this.currentPage;if(g===1){return}this.currentPage--;this._setPageToHash(this.currentPage)},next:function(){var h=this.totalPages,g=this.currentPage;if(g===h){return}this.currentPage++;this._setPageToHash(this.currentPage)}};d.Slides=c})(window);