1 |
- "use strict";function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _defineProperties(t,e){for(var i=0;i<e.length;i++){var s=e[i];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(t,s.key,s)}}function _createClass(t,e,i){return e&&_defineProperties(t.prototype,e),i&&_defineProperties(t,i),t}function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}!function(t,e){"object"===("undefined"==typeof exports?"undefined":_typeof(exports))&&"object"===("undefined"==typeof module?"undefined":_typeof(module))?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"===("undefined"==typeof exports?"undefined":_typeof(exports))?exports.slidePage=e():t.slidePage=e()}(window,function(){return function(){var t=!1;try{var e=Object.defineProperty({},"passive",{get:function(){t=!0}});window.addEventListener("test",null,e)}catch(t){}var n=function(t){var e=(0<arguments.length&&void 0!==t?t:location.href).match(/([^?=&]+)(=([^&]*))/g);return!!e&&e.reduce(function(t,e){return t[e.slice(0,e.indexOf("="))]=e.slice(e.indexOf("=")+1),t},{})},a=function(t,e){for(var i in e)t[i]=e[i];return t},o=function(t,e){var i=t.nodeName===e.nodeName,s=t.nodeType===e.nodeType,n=t.innerHTML===e.innerHTML;return t.className.replace(/ transition/g,"")===e.className.replace(/ transition/g,"")&&i&&s&&n},r=function(t){if(t instanceof NodeList||t instanceof HTMLCollection&&0<t.length){for(var e=0,i=t.length,s=0;s<i;s++)t[s]instanceof Element&&e++;return e===i}return t instanceof Element},s={},l=(new Date).getTime(),h={wheelFunc:function(t){t=t||window.event;if(!this.isScroll){var e=(new Date).getTime(),i=e-l;l=e,i<=200||(t.wheelDeltaY<0||t.wheelDelta<0||0<t.detail?this.canSlide&&this.canNext&&this.slideNext():(0<t.wheelDeltaY||0<t.wheelDelta||t.detail<0)&&this.canSlide&&this.canPrev&&this.slidePrev())}},touchStart:function(t){this.canSlide?s.startpoint=t.targetTouches[0].clientY:s.startpoint=-1},touchMove:function(t){if(-1===s.startpoint)return t.preventDefault(),!1;var e=t.targetTouches[0].clientY-s.startpoint;!this.canPrev&&5<e&&(this.isScroll=!0),!this.canNext&&e<-5&&(this.isScroll=!0),this.isScroll||t.preventDefault(),this.opt.dragMode&&this.canSlide&&1!=this.isScroll&&(e<-5&&this.count>this.page&&this.canNext&&(this.items[this.page-1].style.transform="translate3d(0, "+e.toFixed(2)+"px, 0)",this.items[this.page].style.transform="translate3d(0, "+(window.innerHeight+e).toFixed(2)+"px, 0)",s.endpoint=t.targetTouches[0].clientY),5<e&&1<this.page&&this.canPrev&&(this.items[this.page-2].style.transform="translate3d(0, -"+(window.innerHeight-e).toFixed(2)+"px, 0)",this.items[this.page-1].style.transform="translate3d(0, "+e.toFixed(2)+"px, 0)",s.endpoint=t.targetTouches[0].clientY)),this.opt.dragMode||(s.endpoint=t.targetTouches[0].clientY)},touchEnd:function(t){if(0===s.endpoint||-1===s.startpoint)return!1;var e=s.endpoint-s.startpoint;if(this.opt.dragMode){var i=window.innerHeight/4;e<-1*i?this.canSlide&&this.canNext&&this.slideNext():i<e?this.canSlide&&this.canPrev&&this.slidePrev():-1*i<e&&e<i&&c.resetSlideForDrag()}else s.endpoint-s.startpoint<-60?this.canSlide&&this.canNext&&this.slideNext():60<s.endpoint-s.startpoint&&this.canSlide&&this.canPrev&&this.slidePrev();s.startpoint=0,s.endpoint=0},transitionEnd:function(t){o(t.target,this.items[this.page-1])&&(this.opt.dragMode&&(this.items[this.page-1].classList.remove("transition"),this.items[this.page-2]&&this.items[this.page-2].classList.remove("transition"),this.items[this.page]&&this.items[this.page].classList.remove("transition")),"next"==this.direction?(this.opt.after(this.page-1,this.direction,this.page),this.opt.refresh&&c.resetAnimation.call(this,this.page-2)):"prev"==this.direction&&(this.opt.after(this.page+1,this.direction,this.page),this.opt.refresh&&c.resetAnimation.call(this,this.page)),this.canSlide=!0)}},c={slideScroll:function(t,e){var n=this.items[t].children[0].offsetHeight,i=window.innerHeight,s=function(t){var e=window.innerHeight,i=n<=this.items[t].scrollTop+e,s=0==this.items[t].scrollTop;this.canPrev=s&&!i,this.canNext=i&&!s,this.isScroll=!(i||s)}.bind(this,t);"removeListener"!=e?10<n-i?(this.items[t].children[0].children[0].focus(),s(),"next"==this.direction?this.items[t].scrollTop=0:"prev"==this.direction&&(this.items[t].scrollTop=n-i),this.items[t].addEventListener("scroll",s)):(this.canPrev=!0,this.canNext=!0,this.isScroll=!1):this.items[t].removeEventListener("scroll",s)},resetSlideForDrag:function(){this.canSlide=!1,this.items[this.page-1].classList.add("transition"),this.items[this.page-1].style.transform="translate3d(0, 0, 0)",this.items[this.page-2]&&(this.items[this.page-2].classList.add("transition"),this.items[this.page-2].style.transform="translate3d(0, -100%, 0)"),this.items[this.page]&&(this.items[this.page].classList.add("transition"),this.items[this.page].style.transform="translate3d(0, 100%, 0)")},resetAnimation:function(t){if(this.opt.useAnimation&&this.opt.refresh){if(!this.items[t])return!1;console.log(t);var e=Array.prototype.slice.call(this.items[t].querySelectorAll(".step")),i=Array.prototype.slice.call(this.items[t].querySelectorAll(".lazy"));e.map(function(t){t.style.visibility="hidden",t.style.animationName="__"+window.getComputedStyle(t).animationName}),i.map(function(t){t.style.visibility="hidden",t.style.animationName="__"+window.getComputedStyle(t).animationName})}},runAnimation:function(t,e){if(this.opt.useAnimation){var i=this.items[t].querySelectorAll(e||".step");Array.prototype.slice.call(i).map(function(t){!function(t){var e=t.getAttribute("data-delay")||100,i=setTimeout(function(){t.style.visibility="",t.style.animationName="",clearTimeout(i)},e)}(t)})}},initAnimation:function(t,s){var n=this;if(this.opt.useAnimation){var e=Array.prototype.slice.call(this.container.querySelectorAll(".step")),i=Array.prototype.slice.call(this.container.querySelectorAll(".lazy"));e.map(function(t){t.style.visibility="hidden",t.style.animationName="__"+window.getComputedStyle(t).animationName}),i.map(function(t){t.style.visibility="hidden",t.style.animationName="__"+window.getComputedStyle(t).animationName}),c.runAnimation.call(this,s)}for(var a,o=function(t,e){if(e.style.transform="translate3d(0, "+(t<s?"-100%":s<t?"100%":"0")+", 0)",!n.opt.dragMode)var i=setTimeout(function(){e.classList.add("transition"),clearTimeout(i)})},r=0;a=this.items[r];r++)o(r,a)},initEvent:function(){this.opt.useWheel&&(document.addEventListener("DOMMouseScroll",this.eventHandler.wheelFunc,!!t&&{passive:!0}),document.addEventListener("mousewheel",this.eventHandler.wheelFunc,!!t&&{passive:!0})),this.opt.useSwipe&&(s={startpoint:0,endpoint:0},this.container.addEventListener("touchstart",this.eventHandler.touchStart,!!t&&{passive:!0}),this.container.addEventListener("touchmove",this.eventHandler.touchMove),this.container.addEventListener("touchend",this.eventHandler.touchEnd,!!t&&{passive:!0})),this.container.addEventListener("transitionend",this.eventHandler.transitionEnd)}};return function(){function s(t){_classCallCheck(this,s);var e={page:1*n("page")||1,slidePages:".slide-page",slideContainer:".slide-container",after:function(){},before:function(){},refresh:!1,useWheel:!0,useSwipe:!0,useAnimation:!0,dragMode:!1};for(var i in this.canSlide=!0,this.canNext=!0,this.canPrev=!0,this.isScroll=!1,this.opt=a(e,t),this.page=this.opt.page,this.container=r(this.opt.slideContainer)?this.opt.slideContainer:document.querySelector(this.opt.slideContainer),this.items=r(this.opt.slidePages)?this.opt.slidePages:document.querySelectorAll(this.opt.slidePages),this.count=this.items.length,this.direction="",this.eventHandler={},h)this.eventHandler[i]=h[i].bind(this);c.initEvent.call(this),c.slideScroll.call(this,this.page-1),c.initAnimation.call(this,this.items,this.page-1),this.slideTo(this.page)}return _createClass(s,[{key:"slideNext",value:function(t){if(this.count<=this.page)return!1;this.opt.dragMode&&(this.items[this.page-1].classList.add("transition"),this.items[this.page].classList.add("transition")),this.direction="next",c.slideScroll.call(this,this.page-1,"removeListener"),c.slideScroll.call(this,this.page),this.items[this.page-1].style.transform="translate3d(0, -100%, 0)",this.items[this.page].style.transform="translate3d(0, 0, 0)",this.page++,this.opt.before(this.page-1,this.direction,this.page),t?c.resetAnimation.call(this,this.page-2):(this.canSlide=!1,c.runAnimation.call(this,this.page-1))}},{key:"slidePrev",value:function(t){if(this.page<=1)return!1;this.opt.dragMode&&(this.items[this.page-2].classList.add("transition"),this.items[this.page-1].classList.add("transition")),this.direction="prev",c.slideScroll.call(this,this.page-1,"removeListener"),c.slideScroll.call(this,this.page-2),this.items[this.page-2].style.transform="translate3d(0, 0, 0)",this.items[this.page-1].style.transform="translate3d(0, 100%, 0)",this.page--,this.opt.before(this.page+1,this.direction,this.page),t?c.resetAnimation.call(this,this.page):(this.canSlide=!1,c.runAnimation.call(this,this.page-1))}},{key:"slideTo",value:function(t){if(1<=t&&t<=this.count){if(t==this.page)return!1;if(t>this.page){for(var e=this.page+1;e<t;e++)this.slideNext("optimize");this.slideNext()}else if(t<this.page){for(e=this.page-1;t<e;e--)this.slidePrev("optimize");this.slidePrev()}}}},{key:"slideFire",value:function(t){var e=t?t-1:this.page-1;c.runAnimation.call(this,e,".lazy")}},{key:"destroy",value:function(){if(this.opt.useAnimation){this.items.length;var t=Array.prototype.slice.call(this.container.querySelectorAll(".step")),e=Array.prototype.slice.call(this.container.querySelectorAll(".lazy"));t.map(function(t){t.style.visibility=""}),e.map(function(t){t.style.visibility=""}),c.runAnimation.call(this,0)}if(this.opt.useWheel&&(document.removeEventListener("DOMMouseScroll",this.eventHandler.wheelFunc),document.removeEventListener("mousewheel",this.eventHandler.wheelFunc),this.items[this.page-1].style.transform="translate3d(0, 0, 0)"),this.opt.useSwipe){this.container.removeEventListener("touchstart",this.eventHandler.touchStart),this.container.removeEventListener("touchmove",this.eventHandler.touchMove),this.container.removeEventListener("touchend",this.eventHandler.touchEnd)}this.container.removeEventListener("transitionend",this.eventHandler.transitionEnd)}},{key:"update",value:function(t){this.canSlide=!0,this.canNext=!0,this.canPrev=!0;for(var e=r(t)?t:document.querySelectorAll(this.opt.slidePages),i=0,s=e.length;i<s;i++){if(this.items[this.page-1]&&o(this.items[this.page-1],e[i])){this.page=i+1;break}i===s-1&&(this.page=1)}this.items=e,this.count=this.items.length,this.slideTo(this.page),c.initAnimation.call(this,this.items,this.page-1),c.slideScroll.call(this,this.page-1)}}]),s}()}()});
|