Comparing version 1.0.1 to 1.0.2
@@ -1,1 +0,1 @@ | ||
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var i=e();for(var n in i)("object"==typeof exports?exports:t)[n]=i[n]}}(this,function(){return function(t){function e(n){if(i[n])return i[n].exports;var s=i[n]={i:n,l:!1,exports:{}};return t[n].call(s.exports,s,s.exports,e),s.l=!0,s.exports}var i={};return e.m=t,e.c=i,e.d=function(t,i,n){e.o(t,i)||Object.defineProperty(t,i,{configurable:!1,enumerable:!0,get:n})},e.n=function(t){var i=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(i,"a",i),i},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=2)}([function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.EMPTY_FUNCTION=function(){},e.EMPTY_PAGE=document.createElement("div"),e.OPPSITE={X:"Y",Y:"X"}},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function t(){}return t.register=function(e,i){t._renders[e]=i},t.getRenderInstance=function(e){var i=t._renders[e];if(!i)throw new Error("Missing render : "+e);return new i},t.prototype.sign=function(t){return t=+t,0===t||isNaN(t)?0:t>0?1:-1},t}();n._renders={},e.default=n},function(t,e,i){"use strict";var n=this&&this.__assign||Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++){e=arguments[i];for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&(t[s]=e[s])}return t};Object.defineProperty(e,"__esModule",{value:!0}),i(3);var s=i(4),r=i(0),a=i(5),o=i(6),c=i(1),h=i(7),u=i(8),d=i(9),f=i(10),p=i(11),l=i(12);c.default.register("slide",h.default),c.default.register("rotate",u.default),c.default.register("flip",d.default),c.default.register("card",f.default),c.default.register("fade",p.default),c.default.register("dumi",l.default);var v=function(){function t(e){e=n({},t.DefaultOptions,e),e.transition=n({},t.DefaultOptions.transition,e.transition),this.$container=e.container,this.debug=e.debug,this.data=e.data,this.axis=e.isVertical?"Y":"X",this.isLoop=e.isLoop,this.initIndex=e.initIndex,this.keepDefaultClasses=e.keepDefaultClasses,this.sideLength="X"===this.axis?this.$container.clientWidth:this.$container.clientHeight,this.transition=e.transition,this._listeners={},this.sliding=!1,this.moving=!1,this.pageChange=!1,this.moveDirection=a.Direction.Nonward,this.activePage=r.EMPTY_PAGE,this.lastActivePage=r.EMPTY_PAGE,this.start={X:0,Y:0},this.end={X:0,Y:0},this.offset={X:0,Y:0},this.log=this.debug?console.log.bind(window.console):r.EMPTY_FUNCTION,this.bindEvents(),this.initRender()}return t.prototype.bindEvents=function(){this.$container.addEventListener(t.Device.startEvent,this,{passive:!1}),this.$container.addEventListener(t.Device.moveEvent,this,{passive:!1}),this.$container.addEventListener(t.Device.transitionEvent,this,{passive:!1}),window.addEventListener(t.Device.endEvent,this,{passive:!1}),window.addEventListener(t.Device.resizeEvent,this,!1)},t.prototype.unbindEvents=function(){this.$container.removeEventListener(t.Device.startEvent,this,{passive:!1}),this.$container.removeEventListener(t.Device.moveEvent,this,{passive:!1}),this.$container.removeEventListener(t.Device.transitionEvent,this,{passive:!1}),window.removeEventListener(t.Device.endEvent,this,{passive:!1}),window.removeEventListener(t.Device.resizeEvent,this,!1)},t.prototype.handleEvent=function(e){var i=t.Device.getDeviceEvent(e);switch(i.type){case"mousedown":if(0!==i.button)break;case"touchstart":this.keepDefaultHandler(i),this.startHandler(i.position);break;case t.Device.moveEvent:this.keepDefaultHandler(i),this.moveHandler(i.position);break;case t.Device.endEvent:case t.Device.cancelEvent:this.endHandler();break;case t.Device.resizeEvent:this.resizeHandler();break;case t.Device.transitionEvent:this.transitionEndHandler(i)}},t.prototype.keepDefaultHandler=function(t){if(!t.target||!/^(input|textarea|a|select)$/i.test(t.target.tagName)){for(var e=this.keepDefaultClasses,i=0,n=e;i<n.length;i++){var s=n[i];if(t.target.classList.contains(s))return}t.preventDefault()}},t.prototype.startHandler=function(t){this.sliding||(this.log("start"),this.moving=!0,this.startTime=(new Date).getTime(),this.start=t,this.transition=n({},this.transition,this.currentPage.transition),this.renderInstance=c.default.getRenderInstance(this.transition.name),this.transition.direction!==a.Direction.Nonward&&this.fire("swipeStart"))},t.prototype.moveHandler=function(t){if(!this.sliding&&this.moving&&this.transition.direction!==a.Direction.Nonward){this.log("moving"),this.end=t,this.offset={X:this.end.X-this.start.X,Y:this.end.Y-this.start.Y},this.offset[this.axis]<0?(this.moveDirection=a.Direction.Forward,this.lastActivePage=this.activePage,this.activePage=this.currentPage.next):this.offset[this.axis]>0?(this.moveDirection=a.Direction.Backward,this.lastActivePage=this.activePage,this.activePage=this.currentPage.prev):(this.moveDirection=a.Direction.Nonward,this.lastActivePage=this.activePage,this.activePage=r.EMPTY_PAGE),this.fire("swipeMoving"),this.activePage!==this.lastActivePage&&this.activePage!==r.EMPTY_PAGE&&this.fire("activePageChanged"),this.transition.direction&&this.transition.direction!==this.moveDirection&&(this.offset[this.axis]=0,this.start=this.end);var e={Forward:20,Backward:this.sideLength-20},i=a.Direction[this.moveDirection];if(this.moveDirection*this.end[this.axis]>this.moveDirection*e[i]){var n=this.moveDirection===a.Direction.Forward?"<--- near edge":"near edge ---\x3e";return this.log(n),this.endHandler()}0!==this.transition.duration&&this.render()}},t.prototype.endHandler=function(){if(!this.sliding&&this.moving&&this.transition.direction!==a.Direction.Nonward){this.moving=!1,this.log("end"),this.transition.direction&&this.transition.direction!==this.moveDirection&&(this.offset[this.axis]=0),this.endTime=(new Date).getTime();var t=this.endTime-this.startTime,e=t>300?this.sideLength/3:14,i=(this.offset[this.axis],Math.abs(this.offset[this.axis])),n=Math.abs(this.offset[r.OPPSITE[this.axis]]),s=n<i;i>=e&&s&&this.activePage!==r.EMPTY_PAGE?(this.pageChange=!0,this._swipeTo()):(this.pageChange=!1,this._swipeTo(),this.fire("swipeRestore"))}},t.prototype.resizeHandler=function(){this.sliding||this.moving||(this.sideLength="X"===this.axis?this.$container.clientWidth:this.$container.clientHeight)},t.prototype.transitionEndHandler=function(t){t&&t.target!==this.currentPage||(this.$swiper.style.cssText="",this.currentPage.style.cssText="",this.activePage.style.cssText="",!1===this.pageChange?(this.activePage.classList.remove("active"),this.fire("swipeRestored")):(this.currentPage.classList.remove("current"),this.activePage.classList.remove("active"),this.activePage.classList.add("current"),this.currentPage=this.activePage,this.fire("swipeChanged")),this.activePage=r.EMPTY_PAGE,this.lastActivePage=r.EMPTY_PAGE,this.offset.X=0,this.offset.Y=0,this.sliding=!1,this.pageChange=!1)},t.prototype.swipeTo=function(t,e){if(!this.sliding){var i=this.currentPage.index;this.moveDirection=a.Direction.Nonward,this.pageChange=!0,t>i?this.moveDirection=a.Direction.Forward:t<i&&(this.moveDirection=a.Direction.Backward);var s=this.isLoop?(t+this.data.length)%this.data.length:t;this.activePage=this.$pages[s]||r.EMPTY_PAGE,s!==i&&this.activePage!==r.EMPTY_PAGE||(this.pageChange=!1),this.transition=n({},this.transition,this.currentPage.transition,e),this.renderInstance=c.default.getRenderInstance(this.transition.name),this.fire("activePageChanged"),this.render(),this._swipeTo()}},t.prototype.swipePrev=function(t){var e=this.currentPage.index;this.swipeTo(e-1,t)},t.prototype.swipeNext=function(t){var e=this.currentPage.index;this.swipeTo(e+1,t)},t.prototype.getCurrentIndex=function(){return this.currentPage.index},t.prototype._swipeTo=function(){if(!this.sliding){this.sliding=!0;var t=this.activePage===r.EMPTY_PAGE?300:this.transition.duration,e=Math.abs(this.offset[this.axis])/this.sideLength*t,i=t-e,n=this.pageChange?i:e,s=this.pageChange?this.moveDirection*this.sideLength:0;if(0===n)return this.transitionEndHandler();setTimeout(function(){this.currentPage.style.webkitTransition="ease-out "+n+"ms",this.activePage!==r.EMPTY_PAGE&&(this.activePage.style.webkitTransition="ease-out "+n+"ms"),this.offset[this.axis]=s,this.render()}.bind(this),30)}},t.prototype.initRender=function(){var t=this;this.$swiper=document.createElement("div"),this.$swiper.classList.add("lg-swiper"),this.$pages=this.data.map(function(e,i){var n=document.createElement("div");return n.classList.add("lg-swiper-page"),"string"==typeof e.content?n.innerHTML=e.content:n.appendChild(e.content),n.index=i,n.transition=e.transition,t.initIndex===i&&(n.classList.add("current"),t.currentPage=n),t.$swiper.appendChild(n),n}),this.$pages.forEach(function(e,i,n){var s=t.isLoop?(n.length+i-1)%n.length:i-1,a=t.isLoop?(n.length+i+1)%n.length:i+1;e.prev=t.$pages[s]||r.EMPTY_PAGE,e.next=t.$pages[a]||r.EMPTY_PAGE}),this.$container.style.overflow="hidden",this.$container.appendChild(this.$swiper)},t.prototype.on=function(t,e){for(var i=t.split(" "),n=0,s=i;n<s.length;n++){var r=s[n];this._listeners[r]||(this._listeners[r]=[]),this._listeners[r].push(e)}return this},t.prototype.off=function(t,e){if(this._listeners[t]){var i=this._listeners[t].indexOf(e);i>-1&&this._listeners[t].splice(i,1)}return this},t.prototype.fire=function(t,e){if(void 0===e&&(e={}),this._listeners[t])for(var i=0,s=this._listeners[t];i<s.length;i++){var r=s[i],a=n({},e,{name:t});r.call(this,a)}return this},t.prototype.destroy=function(){this.unbindEvents(),this._listeners={},this.$container.style.overflow="",this.$swiper.parentElement.removeChild(this.$swiper),this.fire("destroy")},t.prototype.render=function(){this.lastActivePage!==this.activePage&&(this.lastActivePage.classList.remove("active"),this.lastActivePage.style.cssText="",this.activePage!==r.EMPTY_PAGE&&this.activePage.classList.add("active")),this.log("offset : "+this.offset[this.axis]);var t=o.default.easeOutQuad;this.activePage===r.EMPTY_PAGE&&(t=o.default.rubberBand),this.renderInstance.doRender({axis:this.axis,moveDirection:this.moveDirection,sideOffset:t(this.offset[this.axis],this.sideLength),sideLength:this.sideLength,$swiper:this.$swiper,currentPage:this.currentPage,activePage:this.activePage})},t}();v.Events=["swipeBeforeStart","swipeStart","swipeMoving","swipeChanged","swipeRestore","swipeRestored","activePageChanged","destroy"],v.Device=new s.Device(window),v.DefaultOptions={container:document.body,data:[],debug:!1,isVertical:!0,isLoop:!1,initIndex:0,keepDefaultClasses:[],transition:{name:"slide",duration:800}},e.Swiper=v},function(t,e){},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function t(t){this.hasTouch=!!("ontouchstart"in t&&!/Mac OS X /.test(t.navigator.userAgent)||t.DocumentTouch&&t.document instanceof t.DocumentTouch),this.startEvent=this.hasTouch?"touchstart":"mousedown",this.moveEvent=this.hasTouch?"touchmove":"mousemove",this.endEvent=this.hasTouch?"touchend":"mouseup",this.cancelEvent=this.hasTouch?"touchcancel":"mouseout",this.transitionEvent=this.getTransitionEvent(),this.resizeEvent="resize"}return t.prototype.getDeviceEvent=function(t){var e=this.hasTouch?this.getTouchPosition(t):this.getMousePosition(t);return{type:t.type,position:e,target:t.target,button:t.button,preventDefault:t.preventDefault.bind(t)}},t.prototype.getTouchPosition=function(t){return t.targetTouches&&t.targetTouches.length>0?{X:t.targetTouches[0].pageX,Y:t.targetTouches[0].pageY}:{X:void 0,Y:void 0}},t.prototype.getMousePosition=function(t){return"pageX"in t?{X:t.pageX,Y:t.pageY}:{X:void 0,Y:void 0}},t.prototype.getTransitionEvent=function(){var t=document.createElement("fakeelement"),e={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(var i in e)if(void 0!==t.style[i])return e[i]},t}();e.Device=n},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});!function(t){t[t.Forward=-1]="Forward",t[t.Nonward=0]="Nonward",t[t.Backward=1]="Backward"}(e.Direction||(e.Direction={}))},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function t(){}return t.easeOutQuad=function(e,i){var n=Math.abs(e/i),s=.5*n*(3-n);return t.sign(e)*s*i},t.rubberBand=function(e,i){var n=Math.abs(e/i),s=1-1/(.55*n+1);return t.sign(e)*s*i},t.sign=function(t){return t=+t,0===t||isNaN(t)?0:t>0?1:-1},t}();e.default=n},function(t,e,i){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])};return function(e,i){function n(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}}();Object.defineProperty(e,"__esModule",{value:!0});var s=i(1),r=i(0),a=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e.prototype.doRender=function(t){var e=t.axis,i=t.sideOffset,n=t.sideLength,s=t.moveDirection,a="translateZ(0) translate"+e+"("+i+"px)",o="translateZ(0) translate"+e+"("+(i-s*n)+"px)";t.currentPage.style.webkitTransform=a,t.activePage!==r.EMPTY_PAGE&&(t.activePage.style.webkitTransform=o)},e}(s.default);e.default=a},function(t,e,i){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])};return function(e,i){function n(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}}();Object.defineProperty(e,"__esModule",{value:!0});var s=i(1),r=i(0),a=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e.prototype.doRender=function(t){var e=t.axis,i=t.sideOffset,n=t.sideLength,s=r.OPPSITE[e],a=t.moveDirection,o="Y"===e?-1:1,c="-webkit-perspective:"+4*n+"px;-webkit-transform-style:preserve-3d;",h="rotate"+s+"("+90*o*i/n+"deg) translateZ("+.889*n/2+"px) scale(0.889)",u="rotate"+s+"("+90*o*(i/n-a)+"deg) translateZ("+.889*n/2+"px) scale(0.889)";t.$swiper.style.cssText=c,t.currentPage.style.webkitTransform=h,t.activePage!==r.EMPTY_PAGE&&(t.activePage.style.webkitTransform=u)},e}(s.default);e.default=a},function(t,e,i){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])};return function(e,i){function n(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}}();Object.defineProperty(e,"__esModule",{value:!0});var s=i(1),r=i(0),a=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e.prototype.doRender=function(t){var e=t.axis,i=t.sideOffset,n=t.sideLength,s=r.OPPSITE[e],a="Y"===e?-1:1,o="-webkit-perspective:"+4*n+"px;-webkit-transform-style:flat;",c="translateZ("+n/2+"px) rotate"+s+"("+180*a*i/n+"deg) scale(0.875)",h="translateZ("+n/2+"px) rotate"+s+"("+180*a*(i/n+1)+"deg) scale(0.875)";t.$swiper.style.cssText=o,t.currentPage.style.webkitBackfaceVisibility="hidden",t.currentPage.style.webkitTransform=c,t.activePage!==r.EMPTY_PAGE&&(t.activePage.style.webkitBackfaceVisibility="hidden",t.activePage.style.webkitTransform=h,t.activePage.style.zIndex=7)},e}(s.default);e.default=a},function(t,e,i){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])};return function(e,i){function n(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}}();Object.defineProperty(e,"__esModule",{value:!0});var s=i(1),r=i(0),a=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e.prototype.doRender=function(t){var e=t.axis,i=t.sideOffset,n=t.sideLength,s=r.OPPSITE[e],a=1-.2*Math.abs(i/n),o=t.moveDirection,c="translateZ(0) scale"+s+"("+a+") translate"+e+"("+i+"px)",h="translateZ(0) translate"+e+"("+(i-o*n)+"px)";t.currentPage.style.webkitTransform=c,t.activePage!==r.EMPTY_PAGE&&(t.activePage.style.webkitTransform=h)},e}(s.default);e.default=a},function(t,e,i){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])};return function(e,i){function n(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}}();Object.defineProperty(e,"__esModule",{value:!0});var s=i(1),r=i(0),a=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e.prototype.doRender=function(t){var e=(t.axis,t.sideOffset),i=t.sideLength;t.currentPage.style.opacity=1-Math.abs(e/i),t.activePage!==r.EMPTY_PAGE&&(t.activePage.style.opacity=Math.abs(e/i))},e}(s.default);e.default=a},function(t,e,i){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])};return function(e,i){function n(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}}();Object.defineProperty(e,"__esModule",{value:!0});var s=i(1),r=i(0),a=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e.prototype.doRender=function(t){var e=t.axis,i=t.sideOffset,n=t.sideLength,s=(r.OPPSITE[e],1-.4*Math.min(Math.abs(i/n),.5)),a=.8+.4*Math.min(Math.abs(i/n),.5),o=t.moveDirection,c="translateZ(0) translate"+e+"("+i+"px) scale("+s+")",h="translateZ(0) translate"+e+"("+(i-o*n)+"px) scale("+a+")";t.currentPage.style.webkitTransform=c,t.activePage!==r.EMPTY_PAGE&&(t.activePage.style.webkitTransform=h)},e}(s.default);e.default=a}])}); | ||
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var i=e();for(var n in i)("object"==typeof exports?exports:t)[n]=i[n]}}(this,function(){return function(t){function e(n){if(i[n])return i[n].exports;var s=i[n]={i:n,l:!1,exports:{}};return t[n].call(s.exports,s,s.exports,e),s.l=!0,s.exports}var i={};return e.m=t,e.c=i,e.d=function(t,i,n){e.o(t,i)||Object.defineProperty(t,i,{configurable:!1,enumerable:!0,get:n})},e.n=function(t){var i=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(i,"a",i),i},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=2)}([function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.EMPTY_FUNCTION=function(){},e.EMPTY_PAGE=document.createElement("div"),e.OPPSITE={X:"Y",Y:"X"}},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function t(){}return t.register=function(e,i){t._renders[e]=i},t.getRenderInstance=function(e){var i=t._renders[e];if(!i)throw new Error("Missing render : "+e);return new i},t.prototype.sign=function(t){return t=+t,0===t||isNaN(t)?0:t>0?1:-1},t}();n._renders={},e.default=n},function(t,e,i){"use strict";var n=this&&this.__assign||Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++){e=arguments[i];for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&(t[s]=e[s])}return t};Object.defineProperty(e,"__esModule",{value:!0}),i(3);var s=i(4),r=i(0),a=i(5),o=i(6),c=i(1),h=i(7),u=i(8),d=i(9),f=i(10),p=i(11),l=i(12);c.default.register("slide",h.default),c.default.register("rotate",u.default),c.default.register("flip",d.default),c.default.register("card",f.default),c.default.register("fade",p.default),c.default.register("dumi",l.default);var v=function(){function t(e){e=n({},t.DefaultOptions,e),e.transition=n({},t.DefaultOptions.transition,e.transition),this.$container=e.container,this.debug=e.debug,this.data=e.data,this.axis=e.isVertical?"Y":"X",this.isLoop=e.isLoop,this.initIndex=e.initIndex,this.keepDefaultClasses=e.keepDefaultClasses,this.sideLength="X"===this.axis?this.$container.clientWidth:this.$container.clientHeight,this.transition=e.transition,this._listeners={},this.sliding=!1,this.moving=!1,this.pageChange=!1,this.moveDirection=a.Direction.Nonward,this.activePage=r.EMPTY_PAGE,this.lastActivePage=r.EMPTY_PAGE,this.start={X:0,Y:0},this.end={X:0,Y:0},this.offset={X:0,Y:0},this.log=this.debug?console.log.bind(window.console):r.EMPTY_FUNCTION,this.bindEvents(),this.initRender()}return t.prototype.bindEvents=function(){this.$container.addEventListener(t.Device.startEvent,this,{passive:!1}),this.$container.addEventListener(t.Device.moveEvent,this,{passive:!1}),this.$container.addEventListener(t.Device.transitionEvent,this,{passive:!1}),window.addEventListener(t.Device.endEvent,this,{passive:!1}),window.addEventListener(t.Device.resizeEvent,this,!1)},t.prototype.unbindEvents=function(){this.$container.removeEventListener(t.Device.startEvent,this,{passive:!1}),this.$container.removeEventListener(t.Device.moveEvent,this,{passive:!1}),this.$container.removeEventListener(t.Device.transitionEvent,this,{passive:!1}),window.removeEventListener(t.Device.endEvent,this,{passive:!1}),window.removeEventListener(t.Device.resizeEvent,this,!1)},t.prototype.handleEvent=function(e){var i=t.Device.getDeviceEvent(e);switch(i.type){case"mousedown":if(0!==i.button)break;case"touchstart":this.keepDefaultHandler(i),this.startHandler(i.position);break;case t.Device.moveEvent:this.keepDefaultHandler(i),this.moveHandler(i.position);break;case t.Device.endEvent:case t.Device.cancelEvent:this.endHandler();break;case t.Device.resizeEvent:this.resizeHandler();break;case t.Device.transitionEvent:this.transitionEndHandler(i)}},t.prototype.keepDefaultHandler=function(t){if(!t.target||!/^(input|textarea|a|select)$/i.test(t.target.tagName)){for(var e=this.keepDefaultClasses,i=0,n=e;i<n.length;i++){var s=n[i];if(t.target.classList.contains(s))return}t.preventDefault()}},t.prototype.startHandler=function(t){this.sliding||(this.log("start"),this.moving=!0,this.startTime=(new Date).getTime(),this.start=t,this.transition=n({},this.transition,this.currentPage.transition),this.renderInstance=c.default.getRenderInstance(this.transition.name),this.transition.direction!==a.Direction.Nonward&&this.fire("swipeStart"))},t.prototype.moveHandler=function(t){if(!this.sliding&&this.moving&&this.transition.direction!==a.Direction.Nonward){this.log("moving"),this.end=t,this.offset={X:this.end.X-this.start.X,Y:this.end.Y-this.start.Y},this.offset[this.axis]<0?(this.moveDirection=a.Direction.Forward,this.lastActivePage=this.activePage,this.activePage=this.currentPage.next):this.offset[this.axis]>0?(this.moveDirection=a.Direction.Backward,this.lastActivePage=this.activePage,this.activePage=this.currentPage.prev):(this.moveDirection=a.Direction.Nonward,this.lastActivePage=this.activePage,this.activePage=r.EMPTY_PAGE),this.fire("swipeMoving"),this.activePage!==this.lastActivePage&&this.activePage!==r.EMPTY_PAGE&&this.fire("activePageChanged"),this.transition.direction&&this.transition.direction!==this.moveDirection&&(this.offset[this.axis]=0,this.start=this.end);var e={Forward:20,Backward:this.sideLength-20},i=a.Direction[this.moveDirection];if(this.moveDirection*this.end[this.axis]>this.moveDirection*e[i]){var n=this.moveDirection===a.Direction.Forward?"<--- near edge":"near edge ---\x3e";return this.log(n),this.endHandler()}0!==this.transition.duration&&this.render()}},t.prototype.endHandler=function(){if(!this.sliding&&this.moving&&this.transition.direction!==a.Direction.Nonward){this.moving=!1,this.log("end"),this.transition.direction&&this.transition.direction!==this.moveDirection&&(this.offset[this.axis]=0),this.endTime=(new Date).getTime();var t=this.endTime-this.startTime,e=t>300?this.sideLength/3:14,i=(this.offset[this.axis],Math.abs(this.offset[this.axis])),n=Math.abs(this.offset[r.OPPSITE[this.axis]]),s=n<i;i>=e&&s&&this.activePage!==r.EMPTY_PAGE?(this.pageChange=!0,this._swipeTo()):(this.pageChange=!1,this._swipeTo(),this.fire("swipeRestore"))}},t.prototype.resizeHandler=function(){this.sliding||this.moving||(this.sideLength="X"===this.axis?this.$container.clientWidth:this.$container.clientHeight)},t.prototype.transitionEndHandler=function(t){t&&t.target!==this.currentPage||(this.$swiper.style.cssText="",this.currentPage.style.cssText="",this.activePage.style.cssText="",!1===this.pageChange?(this.activePage.classList.remove("active"),this.fire("swipeRestored")):(this.currentPage.classList.remove("current"),this.activePage.classList.remove("active"),this.activePage.classList.add("current"),this.currentPage=this.activePage,this.fire("swipeChanged")),this.activePage=r.EMPTY_PAGE,this.lastActivePage=r.EMPTY_PAGE,this.offset.X=0,this.offset.Y=0,this.sliding=!1,this.pageChange=!1)},t.prototype.swipeTo=function(t,e){if(!this.sliding){var i=this.currentPage.index;this.moveDirection=a.Direction.Nonward,this.pageChange=!0,t>i?this.moveDirection=a.Direction.Forward:t<i&&(this.moveDirection=a.Direction.Backward);var s=this.isLoop?(t+this.data.length)%this.data.length:t;this.activePage=this.$pages[s]||r.EMPTY_PAGE,s!==i&&this.activePage!==r.EMPTY_PAGE||(this.pageChange=!1),this.transition=n({},this.transition,this.currentPage.transition,e),this.renderInstance=c.default.getRenderInstance(this.transition.name),this.fire("activePageChanged"),this.render(),this._swipeTo()}},t.prototype.swipePrev=function(t){var e=this.currentPage.index;this.swipeTo(e-1,t)},t.prototype.swipeNext=function(t){var e=this.currentPage.index;this.swipeTo(e+1,t)},t.prototype.getCurrentIndex=function(){return this.currentPage.index},t.prototype._swipeTo=function(){if(!this.sliding){this.sliding=!0;var t=this.activePage===r.EMPTY_PAGE?300:this.transition.duration,e=Math.abs(this.offset[this.axis])/this.sideLength*t,i=t-e,n=this.pageChange?i:e,s=this.pageChange?this.moveDirection*this.sideLength:0;if(0===n)return this.transitionEndHandler();setTimeout(function(){this.currentPage.style.webkitTransition="ease-out "+n+"ms",this.activePage!==r.EMPTY_PAGE&&(this.activePage.style.webkitTransition="ease-out "+n+"ms"),this.offset[this.axis]=s,this.render()}.bind(this),30)}},t.prototype.initRender=function(){var t=this;this.$swiper=document.createElement("div"),this.$swiper.classList.add("lg-swiper"),this.$pages=this.data.map(function(e,i){var n=document.createElement("div");return n.classList.add("lg-swiper-page"),"string"==typeof e.content?n.innerHTML=e.content:n.appendChild(e.content),n.index=i,n.transition=e.transition,t.initIndex===i&&(n.classList.add("current"),t.currentPage=n),t.$swiper.appendChild(n),n}),this.$pages.forEach(function(e,i,n){var s=t.isLoop?(n.length+i-1)%n.length:i-1,a=t.isLoop?(n.length+i+1)%n.length:i+1;e.prev=t.$pages[s]||r.EMPTY_PAGE,e.next=t.$pages[a]||r.EMPTY_PAGE}),this.$container.style.overflow="hidden",this.$container.appendChild(this.$swiper)},t.prototype.on=function(t,e){for(var i=t.split(" "),n=0,s=i;n<s.length;n++){var r=s[n];this._listeners[r]||(this._listeners[r]=[]),this._listeners[r].push(e)}return this},t.prototype.off=function(t,e){if(this._listeners[t]){var i=this._listeners[t].indexOf(e);i>-1&&this._listeners[t].splice(i,1)}return this},t.prototype.fire=function(t,e){if(void 0===e&&(e={}),this._listeners[t])for(var i=0,s=this._listeners[t];i<s.length;i++){var r=s[i],a=n({},e,{name:t});r.call(this,a)}return this},t.prototype.destroy=function(){this.unbindEvents(),this._listeners={},this.$container.style.overflow="",this.$swiper.parentElement.removeChild(this.$swiper),this.fire("destroy")},t.prototype.render=function(){this.lastActivePage!==this.activePage&&(this.lastActivePage.classList.remove("active"),this.lastActivePage.style.cssText="",this.activePage!==r.EMPTY_PAGE&&this.activePage.classList.add("active")),this.log("offset : "+this.offset[this.axis]);var t=o.default.easeOutQuad;this.activePage===r.EMPTY_PAGE&&(t=o.default.rubberBand),this.renderInstance.doRender({axis:this.axis,moveDirection:this.moveDirection,sideOffset:t(this.offset[this.axis],this.sideLength),sideLength:this.sideLength,$swiper:this.$swiper,currentPage:this.currentPage,activePage:this.activePage})},t}();v.Events=["swipeBeforeStart","swipeStart","swipeMoving","swipeChanged","swipeRestore","swipeRestored","activePageChanged","destroy"],v.Device=new s.Device(window),v.DefaultOptions={container:document.body,data:[],debug:!1,isVertical:!0,isLoop:!1,initIndex:0,keepDefaultClasses:[],transition:{name:"slide",duration:800}},e.Swiper=v},function(t,e){},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function t(t){this.hasTouch=!!("ontouchstart"in t||t.DocumentTouch&&t.document instanceof t.DocumentTouch),this.startEvent=this.hasTouch?"touchstart":"mousedown",this.moveEvent=this.hasTouch?"touchmove":"mousemove",this.endEvent=this.hasTouch?"touchend":"mouseup",this.cancelEvent=this.hasTouch?"touchcancel":"mouseout",this.transitionEvent=this.getTransitionEvent(),this.resizeEvent="resize"}return t.prototype.getDeviceEvent=function(t){var e=this.hasTouch?this.getTouchPosition(t):this.getMousePosition(t);return{type:t.type,position:e,target:t.target,button:t.button,preventDefault:t.preventDefault.bind(t)}},t.prototype.getTouchPosition=function(t){return t.targetTouches&&t.targetTouches.length>0?{X:t.targetTouches[0].pageX,Y:t.targetTouches[0].pageY}:{X:void 0,Y:void 0}},t.prototype.getMousePosition=function(t){return"pageX"in t?{X:t.pageX,Y:t.pageY}:{X:void 0,Y:void 0}},t.prototype.getTransitionEvent=function(){var t=document.createElement("fakeelement"),e={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(var i in e)if(void 0!==t.style[i])return e[i]},t}();e.Device=n},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});!function(t){t[t.Forward=-1]="Forward",t[t.Nonward=0]="Nonward",t[t.Backward=1]="Backward"}(e.Direction||(e.Direction={}))},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function t(){}return t.easeOutQuad=function(e,i){var n=Math.abs(e/i),s=.5*n*(3-n);return t.sign(e)*s*i},t.rubberBand=function(e,i){var n=Math.abs(e/i),s=1-1/(.55*n+1);return t.sign(e)*s*i},t.sign=function(t){return t=+t,0===t||isNaN(t)?0:t>0?1:-1},t}();e.default=n},function(t,e,i){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])};return function(e,i){function n(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}}();Object.defineProperty(e,"__esModule",{value:!0});var s=i(1),r=i(0),a=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e.prototype.doRender=function(t){var e=t.axis,i=t.sideOffset,n=t.sideLength,s=t.moveDirection,a="translateZ(0) translate"+e+"("+i+"px)",o="translateZ(0) translate"+e+"("+(i-s*n)+"px)";t.currentPage.style.webkitTransform=a,t.activePage!==r.EMPTY_PAGE&&(t.activePage.style.webkitTransform=o)},e}(s.default);e.default=a},function(t,e,i){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])};return function(e,i){function n(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}}();Object.defineProperty(e,"__esModule",{value:!0});var s=i(1),r=i(0),a=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e.prototype.doRender=function(t){var e=t.axis,i=t.sideOffset,n=t.sideLength,s=r.OPPSITE[e],a=t.moveDirection,o="Y"===e?-1:1,c="-webkit-perspective:"+4*n+"px;-webkit-transform-style:preserve-3d;",h="rotate"+s+"("+90*o*i/n+"deg) translateZ("+.889*n/2+"px) scale(0.889)",u="rotate"+s+"("+90*o*(i/n-a)+"deg) translateZ("+.889*n/2+"px) scale(0.889)";t.$swiper.style.cssText=c,t.currentPage.style.webkitTransform=h,t.activePage!==r.EMPTY_PAGE&&(t.activePage.style.webkitTransform=u)},e}(s.default);e.default=a},function(t,e,i){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])};return function(e,i){function n(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}}();Object.defineProperty(e,"__esModule",{value:!0});var s=i(1),r=i(0),a=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e.prototype.doRender=function(t){var e=t.axis,i=t.sideOffset,n=t.sideLength,s=r.OPPSITE[e],a="Y"===e?-1:1,o="-webkit-perspective:"+4*n+"px;-webkit-transform-style:flat;",c="translateZ("+n/2+"px) rotate"+s+"("+180*a*i/n+"deg) scale(0.875)",h="translateZ("+n/2+"px) rotate"+s+"("+180*a*(i/n+1)+"deg) scale(0.875)";t.$swiper.style.cssText=o,t.currentPage.style.webkitBackfaceVisibility="hidden",t.currentPage.style.webkitTransform=c,t.activePage!==r.EMPTY_PAGE&&(t.activePage.style.webkitBackfaceVisibility="hidden",t.activePage.style.webkitTransform=h,t.activePage.style.zIndex=7)},e}(s.default);e.default=a},function(t,e,i){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])};return function(e,i){function n(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}}();Object.defineProperty(e,"__esModule",{value:!0});var s=i(1),r=i(0),a=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e.prototype.doRender=function(t){var e=t.axis,i=t.sideOffset,n=t.sideLength,s=r.OPPSITE[e],a=1-.2*Math.abs(i/n),o=t.moveDirection,c="translateZ(0) scale"+s+"("+a+") translate"+e+"("+i+"px)",h="translateZ(0) translate"+e+"("+(i-o*n)+"px)";t.currentPage.style.webkitTransform=c,t.activePage!==r.EMPTY_PAGE&&(t.activePage.style.webkitTransform=h)},e}(s.default);e.default=a},function(t,e,i){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])};return function(e,i){function n(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}}();Object.defineProperty(e,"__esModule",{value:!0});var s=i(1),r=i(0),a=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e.prototype.doRender=function(t){var e=(t.axis,t.sideOffset),i=t.sideLength;t.currentPage.style.opacity=1-Math.abs(e/i),t.activePage!==r.EMPTY_PAGE&&(t.activePage.style.opacity=Math.abs(e/i))},e}(s.default);e.default=a},function(t,e,i){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])};return function(e,i){function n(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}}();Object.defineProperty(e,"__esModule",{value:!0});var s=i(1),r=i(0),a=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e.prototype.doRender=function(t){var e=t.axis,i=t.sideOffset,n=t.sideLength,s=(r.OPPSITE[e],1-.4*Math.min(Math.abs(i/n),.5)),a=.8+.4*Math.min(Math.abs(i/n),.5),o=t.moveDirection,c="translateZ(0) translate"+e+"("+i+"px) scale("+s+")",h="translateZ(0) translate"+e+"("+(i-o*n)+"px) scale("+a+")";t.currentPage.style.webkitTransform=c,t.activePage!==r.EMPTY_PAGE&&(t.activePage.style.webkitTransform=h)},e}(s.default);e.default=a}])}); |
{ | ||
"name": "fex-swiper", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "a H5 swiper powered by FEX", | ||
@@ -5,0 +5,0 @@ "main": "src/swiper.ts", |
@@ -29,6 +29,12 @@ # Swiper | ||
- [off](#off) | ||
- [贡献代码](#贡献代码) | ||
- [技术栈](#技术栈) | ||
- [目录结构](目录结构) | ||
- [开发步骤](#开发步骤) | ||
## 基本用法 | ||
只需三步即可完成: | ||
1. 引入 js 和 css,构建好的 js 和 css 可以在 [release](https://github.com/fex-team/swiper/releases) 页面下载; | ||
1. 引入 js 和 css,可以按照下面两种方式之一进行: | ||
1. 在 [release](https://github.com/fex-team/swiper/releases) 页面下载构建好的 js 和 css; | ||
2. 通过 npm 或 yarn 安装,命令 `npm install fex-swiper` 或 `yarn add fex-swiper`,目的文件在 `dist` 目录下; | ||
@@ -246,1 +252,29 @@ 2. 创建一个容器 `div`,注意:这个容器必须是有宽度和高度(如 100% 或者 650px); | ||
``` | ||
## 贡献代码 | ||
欢迎大家为 Swiper 共享代码,开始之前,可以了解一下 Swiper 的基本原理,见[这篇文章](http://fex.baidu.com/blog/2017/10/build-a-silky-smooth-slide-library)。 | ||
### 技术栈 | ||
TypeScript + Webpack + Jest | ||
### 目录结构 | ||
├── docs 文档 | ||
├── examples 例子 | ||
├── index.html 开发用到的 demo | ||
├── src 源码 | ||
│ ├── constant.ts 常量定义 | ||
│ ├── device.ts 统一设备 | ||
│ ├── easing.ts 缓动函数 | ||
│ ├── interface.ts 接口定义 | ||
│ ├── render.ts render 抽象类 | ||
│ ├── renders 支持的六种翻页效果 | ||
│ ├── swiper.css 样式文件 | ||
│ └── swiper.ts 主文件 | ||
└── tests 测试文件 | ||
### 开发步骤 | ||
1. Fork 代码至自己的代码库,并 clone 到本地; | ||
2. `yarn`,安装依赖包,主要是开发时用的; | ||
3. `yarn dev`,用到的文件是 `index.html`,开发时修改保存后,会实时将 TypeScript 编译为 Javascript; | ||
4. `yarn test`,运行测试用例,并输出代码覆盖率; | ||
5. 开发完成后,在 Github 上提交 Pull Request。 |
@@ -38,3 +38,3 @@ /** | ||
constructor(global) { | ||
this.hasTouch = !!(('ontouchstart' in global && !/Mac OS X /.test(global.navigator.userAgent)) | ||
this.hasTouch = !!('ontouchstart' in global | ||
|| (global.DocumentTouch && global.document instanceof global.DocumentTouch)); | ||
@@ -41,0 +41,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
256279
279
39