1 | "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function a(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}(),_Utils=require("./Utils"),_Utils2=_interopRequireDefault(_Utils);function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var OrcaSlide=function(){function a(b){_classCallCheck(this,a),this.configSlide=b,this.autoPlayTimer=null,this.initSlider()}var b=Math.ceil;return _createClass(a,[{key:"animateSlide",value:function(){var a=this,b=!(0<arguments.length&&void 0!==arguments[0])||arguments[0],c=this.configSlide,d=c.active,e=c.contentItem,f=c.itemWidth,g=c.items,h=c.moveTo,i=c.time,j=c.position,k=c.isInfinite,l=b?h:-h,m=b?j+1:j-1,n=g<m||0>m;if(d)if(this.callbacks(b,m),k&&n)this.isInfinite=m;else if(!n){this.configSlide.position+=b?1:-1,this.configSlide.active=!1,this.isInfinite=m;var o=0,p=setInterval(function(){if(_Utils2.default.moveToScroll(l,e),o+=h,o>=f){clearInterval(p);var b=f*a.configSlide.position;_Utils2.default.moveToScroll(b,e,!1),a.configSlide.active=!0}},i)}}},{key:"autoPlay",value:function a(){var b=!(0<arguments.length&&void 0!==arguments[0])||arguments[0];this.configSlide.autoPlay=b;var c=this.configSlide,a=c.autoPlay,d=c.timeAutoPlay;b||a?b&&a&&(this.autoPlayTimer=setInterval(function(){this.animateSlide()},d)):clearInterval(this.autoPlayTimer)}},{key:"callbacks",value:function c(a,b){var d=this.configSlide,c=d.callbacks,e=d.items,f=a?b-1:b+1,g=c["Slide"+f]||null;if(g){var h=g.next===a||g.previus&&!a,i=g.next===a?"next":"previus",j="next"===i?f+1:f-1;j=0>j?e:j,j=j>e?0:j;try{var k={action:i,slide:j,lastSlide:f};h&&g.callback(k)}catch(a){console.groupCollapsed("%c \uD83D\uDEAB [OrcaSlide => Error]","color:#FFF;"),console.error(a),console.groupEnd("[OrcaSlide => Error]")}}}},{key:"displayArrow",value:function(a){var b=this.configSlide,c=b.autoPlay,d=b.arrowNext,e=b.arrowPrevious,f=b.items,g=b.isInfinite,h=0<a?"":"none",i=f===a?"none":"";_Utils2.default.displayToggle(d,i),_Utils2.default.displayToggle(e,h),c&&!g&&"none"===i&&this.autoPlay(!1)}},{key:"initSlider",value:function(){return this.validateConfig.setActionButton.resizeSlide.startTouch(),this.configSlide.autoPlay&&this.autoPlay(),0}},{key:"startTouch",value:function(){var a=this,b=_Utils2.default.isMobile,c=this.configSlide,d=c.contentItem,e=c.swipeConfig;if("desktop"!==b){var f=e,g=void 0;d.addEventListener("touchstart",function(a){var b=_Utils2.default.existFields(a,"touches.0",null);g=0,b&&(f.startX=b.screenX,f.startY=b.screenY)},!1),d.addEventListener("touchmove",function(a){var b=_Utils2.default.existFields(a,"touches.0",null);b&&(f.endX=b.screenX,g=0<=f.startX-f.endX?f.startX-f.endX:-1*(f.startX-f.endX),f.endY=b.screenY,f.direction=_Utils2.default.getDirecctionSlide(f))},!1),d.addEventListener("touchend",function(){var b="left"===f.direction;a.autoPlay(!1),60<g&&a.animateSlide(b)},!1)}}},{key:"isInfinite",set:function(a){var b=this.configSlide,c=b.contentItem,d=b.isInfinite,e=b.items,f=b.itemWidth,g=(0>a||a>e)&&a;if(d){if(0>a||a>e){c.style.scrollBehavior="smooth";var h=0>g?e*f:0;_Utils2.default.moveToScroll(h,c,!1),this.configSlide.position=0>g?e:0,this.configSlide.active=!0,c.removeAttribute("style")}}else this.displayArrow(a)}},{key:"resizeSlide",get:function(){var a=this,c=this.configSlide,d=_Utils2.default.existFields(c,"item",null),e=_Utils2.default.existFields(c,"content",null),f="desktop"===_Utils2.default.isMobile?128:c.jump;return null!==d&&null!==e&&window.addEventListener("resize",function(){a.configSlide.scrollWidth=e.scrollWidth,a.configSlide.moveTo=b(d.offsetWidth/f),a.configSlide.itemWidth=d.offsetWidth;var g=d.offsetWidth*a.configSlide.position;_Utils2.default.moveToScroll(g,c.contentItem,!1)}),this}},{key:"setActionButton",get:function(){var a=this;return["arrowNext","arrowPrevious","ctrlStop","ctrlPlay"].forEach(function(b){var c=a.configSlide[b],d=function(){};b.includes("ctrl")?(d=function(){a.autoPlay("ctrlPlay"===b)},_Utils2.default.actionButton(c,d)):(d=function(){a.animateSlide("arrowNext"===b),a.autoPlay(!1)},_Utils2.default.actionButton(c,d))}),this}},{key:"validateConfig",get:function(){var a=this,c=this.configSlide,d=c.callbacks,e=c.jump,f=window.devicePixelRatio;return["arrowNext","arrowPrevious","contentItem"].forEach(function(c){var d=a.configSlide[c],f=_Utils2.default.getElementDom(d),g="desktop"===_Utils2.default.isMobile?128:e;if(f&&(a.configSlide[c]=f,"contentItem"===c)){var h=f.children[0]||{},i=h.offsetWidth||0,j=b(i/g),k={items:f.children.length-1,itemWidth:i,moveTo:j,scrollWidth:f.scrollWidth||0,time:1e3*a.configSlide.time/512,item:h,content:f};a.configSlide.active=0<k.items&&0<k.moveTo,Object.assign(a.configSlide,k),a.configSlide.isInfinite||_Utils2.default.displayToggle(a.configSlide.arrowPrevious,"none")}}),this.configSlide.callbacks=_Utils2.default.getCallbacksConfig(d),this.validateConfigAutoPlay}},{key:"validateConfigAutoPlay",get:function(){var a=this.configSlide,b=a.active,c=a.ctrlPlay,d=a.ctrlStop,e=a.timeAutoPlay;if(b){var f={timeAutoPlay:1e3*e,ctrlPlay:_Utils2.default.getElementDom(c),ctrlStop:_Utils2.default.getElementDom(d)};Object.assign(this.configSlide,f)}return this}}]),a}();exports.default=OrcaSlide; |