define(function(t,r,e){"use strict";function o(t){o.superclass.constructor.call(this,t)}var n=t("./util"),i=(t("./base"),t("./core")),s=t("./animate"),l=t("./hammer"),u=t("./components/scrollbar"),a=t("./components/controller"),c=.382,f=5e-4,h=.03,d=n.prefixStyle("transformOrigin"),g=n.prefixStyle("transform");return n.extend(o,i,{init:function(){var t=this,r={preventDefault:!0,preventTouchMove:!0};return o.superclass.init.call(this),t.userConfig=n.mix(r,t.userConfig),t.SCROLL_ACCELERATION=t.userConfig.SCROLL_ACCELERATION||f,t.BOUNDRY_ACCELERATION=t.userConfig.BOUNDRY_ACCELERATION||h,t._initContainer(),t.resetSize(),t._setOverflowBehavior(),t.defaltConfig={lockY:t.userConfig.lockY,lockX:t.userConfig.lockX},t},destroy:function(){var t=this;o.superclass.destroy.call(this),t.renderTo.style.overflow="",t.renderTo.style.touchAction="",t.container.style.transform="",t.container.style.transformOrigin="",t.content.style.transform="",t.content.style.transformOrigin="",t.off("touchstart mousedown",t._ontouchstart),t.off("touchmove",t._ontouchmove),window.removeEventListener("resize",t.resizeHandler,t),t.destroyScrollBars()},_setOverflowBehavior:function(){var t=this,r=t.renderTo,e=getComputedStyle(r);return t.userConfig.lockX=void 0===t.userConfig.lockX?"hidden"==e["overflow-x"]||t.width==t.containerWidth:t.userConfig.lockX,t.userConfig.lockY=void 0===t.userConfig.lockY?"hidden"==e["overflow-y"]||t.height==t.containerHeight:t.userConfig.lockY,t.userConfig.scrollbarX=void 0===t.userConfig.scrollbarX?!t.userConfig.lockX:t.userConfig.scrollbarX,t.userConfig.scrollbarY=void 0===t.userConfig.scrollbarY?!t.userConfig.lockY:t.userConfig.scrollbarY,t},_resetLockConfig:function(){var t=this;return t.userConfig.lockX=t.defaltConfig.lockX,t.userConfig.lockY=t.defaltConfig.lockY,t},_initContainer:function(){var t=this;if(o.superclass._initContainer.call(t),!t.__isContainerInited&&t.container&&t.content)return t.container.style[d]="0 0",t.content.style[d]="0 0",t.translate(0,0),t.__isContainerInited=!0,t},getScrollTop:function(){var t=window.getComputedStyle(this.container)[g].match(/[-\d\.*\d*]+/g);return t?0===Math.round(t[5])?0:-Math.round(t[5]):0},getScrollLeft:function(){var t=window.getComputedStyle(this.content)[g].match(/[-\d\.*\d*]+/g);return t?0===Math.round(t[4])?0:-Math.round(t[4]):0},scrollLeft:function(t,r,e,o){if(!this.userConfig.lockX){var n=this.userConfig.gpuAcceleration?" translateZ(0) ":"";return this.x=void 0===t||isNaN(t)||0===t?0:-Math.round(t),this._animate("x","translateX("+this.x+"px) scale("+this.scale+")"+n,r,e,o),this}},scrollTop:function(t,r,e,o){if(!this.userConfig.lockY){var n=this.userConfig.gpuAcceleration?" translateZ(0) ":"";return this.y=void 0===t||isNaN(t)||0===t?0:-Math.round(t),this._animate("y","translateY("+this.y+"px) "+n,r,e,o),this}},translate:function(t,r,e){var o=this.userConfig.gpuAcceleration?" translateZ(0) ":"";return this.x=t||this.x||0,this.y=r||this.y||0,this.scale=e||this.scale||1,this.content.style[g]="translate("+this.x+"px,0px) scale("+this.scale+") "+o,this.container.style[g]="translate(0px,"+this.y+"px) "+o,this},_animate:function(t,r,e,o,n){var i=this,e=e||0,o=o||"quadratic",l="y"==t?i.container:i.content,u={css:{transform:r},duration:e,easing:o,run:function(t){i.trigger("scroll",{scrollTop:i.getScrollTop(),scrollLeft:i.getScrollLeft(),type:"scroll"})},useTransition:i.userConfig.useTransition,end:function(r){n&&n(),0!==i["_bounce"+t]&&void 0!==i["_bounce"+t]||"linear"==o||(i["isScrolling"+t.toUpperCase()]=!1,i["isRealScrolling"+t.toUpperCase()]=!1,i.trigger("scrollend",{type:"scrollend",scrollTop:i.getScrollTop(),scrollLeft:i.getScrollLeft(),zoomType:t,duration:e,easing:o}))}},a=i.__timers[t]=i.__timers[t]||new s(l,u);return a.stop(),a.reset(u),a.run(),i.trigger("scrollanimate",{type:"scrollanimate",scrollTop:-i.y,scrollLeft:-i.x,duration:e,easing:o,zoomType:t}),this},_ontap:function(t){var r=this;r.boundryCheck(),!r.isRealScrollingX&&!r.isRealScrollingY,r.isRealScrollingY=!1,r.isRealScrollingY=!1},_bindEvt:function(){o.superclass._bindEvt.call(this);var t=this;if(!t.__isEvtBind){t.__isEvtBind=!0;var r=new l.Pinch;return t.mc.add(r),t.on("touchstart mousedown",t._ontouchstart,t),t.on("touchmove",t._ontouchmove,t),t.on("tap",t._ontap,t),t.on("panstart",t._onpanstart,t),t.on("pan",t._onpan,t),t.on("panend",t._onpanend,t),t.resizeHandler=function(r){setTimeout(function(){t.resetSize(),t.boundryCheck(0),t.render()},100)},window.addEventListener("resize",t.resizeHandler,t),this}},_ontouchstart:function(t){var r=this;!/(SELECT|INPUT|TEXTAREA)/i.test(t.target.tagName)&&r.userConfig.preventDefault&&t.preventDefault(),r.stop()},_ontouchmove:function(t){this.userConfig.preventTouchMove&&t.preventDefault()},_onpanstart:function(t){this.userConfig.preventTouchMove&&t.preventDefault();var r=this,e=r.getScrollLeft(),o=r.getScrollTop();r.stop(),r.translate(-e,-o);var n=r.mc.get("pan").options.threshold;return r.thresholdY="8"==t.direction?n:"16"==t.direction?-n:0,r.thresholdX="2"==t.direction?n:"4"==t.direction?-n:0,r},_onpan:function(t){this.userConfig.preventTouchMove&&t.preventDefault();var r=this,e=r.boundry,o=r.userConfig,n=o.boundryCheck,i=o.bounce,s=r.__topstart||(r.__topstart=-r.getScrollTop()),l=r.__leftstart||(r.__leftstart=-r.getScrollLeft()),u=o.lockY?Number(s):Number(s)+(t.deltaY+r.thresholdY),a=o.lockX?Number(l):Number(l)+(t.deltaX+r.thresholdX),f=r.containerWidth,h=r.containerHeight;return n&&(u=u>e.top?i?(u-e.top)*c+e.top:e.top:u,u=ue.left?i?(a-e.left)*c+e.left:e.left:a,a=a0},isBoundryOutRight:function(){return this.getBoundryOutRight()>0},isBoundryOutTop:function(){return this.getBoundryOutTop()>0},isBoundryOutBottom:function(){return this.getBoundryOutBottom()>0},getBoundryOutTop:function(){return-this.boundry.top-this.getScrollTop()},getBoundryOutLeft:function(){return-this.boundry.left-this.getScrollLeft()},getBoundryOutBottom:function(){return this.boundry.bottom-this.containerHeight+this.getScrollTop()},getBoundryOutRight:function(){return this.boundry.right-this.containerWidth+this.getScrollLeft()},computeScroll:function(t,r){var e=this,o=e.userConfig,n=e.boundry,i="x"==t?e.getScrollLeft():e.getScrollTop(),s="x"==t?n.left:n.top,l="x"==t?n.right:n.bottom,u="x"==t?e.containerWidth:e.containerHeight,a=o.maxSpeed||2,c=o.boundryCheck,f=o.bounce,h={},d="inside";if(c){if("x"==t&&(e.isBoundryOutLeft()||e.isBoundryOutRight()))return void e.boundryCheckX();if("y"==t&&(e.isBoundryOutTop()||e.isBoundryOutBottom()))return void e.boundryCheckY()}if(!("x"==t&&e.userConfig.lockX||"y"==t&&e.userConfig.lockY)){r=r>a?a:r<-a?-a:r;var g=e.SCROLL_ACCELERATION*(r/(Math.abs(r)||1)),p=e.BOUNDRY_ACCELERATION,C=isNaN(r/g)?0:r/g,y=Number(i)+C*r/2;if(y<-s&&c){var v=-s-i,_=(Math.sqrt(-2*g*v+r*r)+r)/g,b=r-g*_,m=Math.abs(b/p),T=b/2*m;C=_+m,y=f?-s+T:-s,d="outside"}else if(y>u-l&&c){var v=l-u+i,_=(Math.sqrt(-2*g*v+r*r)-r)/g,b=r-g*_,m=Math.abs(b/p),T=b/2*m;C=_+m,y=f?u-l+T:u-l,d="outside"}if(!isNaN(y)&&!isNaN(C)){h.pos=y,h.duration=C,h.easing=Math.abs(r)>2?"circular":"quadratic",h.status=d;var S=t.toUpperCase();return e["isScrolling"+S]=!0,e["isRealScrolling"+S]=!0,h}}},boundryCheckX:function(t,r,e){var o=this;if(o.userConfig.boundryCheck&&("function"==typeof arguments[0]?(e=arguments[0],t=o.userConfig.BOUNDRY_CHECK_DURATION,r=o.userConfig.BOUNDRY_CHECK_EASING):(t=0===t?0:o.userConfig.BOUNDRY_CHECK_DURATION,r=r||o.userConfig.BOUNDRY_CHECK_EASING),o.userConfig.bounce&&!o.userConfig.lockX)){var n=o.boundry;return o.isBoundryOutLeft()?o.scrollLeft(-n.left,t,r,e):o.isBoundryOutRight()&&o.scrollLeft(o.containerWidth-n.right,t,r,e),o}},boundryCheckY:function(t,r,e){var o=this;if(o.userConfig.boundryCheck&&("function"==typeof arguments[0]?(e=arguments[0],t=o.userConfig.BOUNDRY_CHECK_DURATION,r=o.userConfig.BOUNDRY_CHECK_EASING):(t=0===t?0:o.userConfig.BOUNDRY_CHECK_DURATION,r=r||o.userConfig.BOUNDRY_CHECK_EASING),o.userConfig.boundryCheck&&!o.userConfig.lockY)){var n=o.boundry;return o.isBoundryOutTop()?o.scrollTop(-n.top,t,r,e):o.isBoundryOutBottom()&&o.scrollTop(o.containerHeight-n.bottom,t,r,e),o}},boundryCheck:function(t,r,e){return this.boundryCheckX(t,r,e),this.boundryCheckY(t,r,e),this},stop:function(){var t=this;if(t.__timers.x&&t.__timers.x.stop(),t.__timers.y&&t.__timers.y.stop(),t.isScrollingX||t.isScrollingY){var r=t.getScrollTop(),e=t.getScrollLeft();t.trigger("scrollend",{scrollTop:r,scrollLeft:e}),t.trigger("stop",{scrollTop:r,scrollLeft:e}),t.isScrollingX=!1,t.isScrollingY=!1}return t},render:function(){var t=this;return o.superclass.render.call(this),"static"==getComputedStyle(t.renderTo).position&&(t.renderTo.style.position="relative"),t.renderTo.style.overflow="hidden",t.initScrollBars(),t.initController(),t},initScrollBars:function(){var t=this;if(t.userConfig.boundryCheck){var r=t.userConfig.indicatorInsets;return t.userConfig.scrollbarX&&(t.scrollbarX=t.scrollbarX||new u({xscroll:t,type:"x",spacing:r.spacing}),t.scrollbarX.render(),t.scrollbarX._update(),t.scrollbarX.hide()),t.userConfig.scrollbarY&&(t.scrollbarY=t.scrollbarY||new u({xscroll:t,type:"y",spacing:r.spacing}),t.scrollbarY.render(),t.scrollbarY._update(),t.scrollbarY.hide()),t}},destroyScrollBars:function(){return this.scrollbarX&&this.scrollbarX.destroy(),this.scrollbarY&&this.scrollbarY.destroy(),this},initController:function(){var t=this;return t.controller=t.controller||new a({xscroll:t}),t},_unPreventHref:function(t){var r=n.findParentEl(t.target,"a",this.renderTo);if(r&&"a"==r.tagName.toLowerCase()){var e=r.getAttribute("data-xs-href");e&&r.setAttribute("href",e)}},_preventHref:function(t){var r=n.findParentEl(t.target,"a",this.renderTo);if(r&&"a"==r.tagName.toLowerCase()){var e=r.getAttribute("href");e&&r.setAttribute("href","javascript:void(0)"),e&&r.setAttribute("data-xs-href",e)}},_triggerClick:function(t){var r=t.target;if(!/(SELECT|INPUT|TEXTAREA)/i.test(r.tagName)){var e=document.createEvent("MouseEvents");e.initMouseEvent("click",!0,!0,t.view,1,r.screenX,r.screenY,r.clientX,r.clientY,t.ctrlKey,t.altKey,t.shiftKey,t.metaKey,0,null),r.dispatchEvent(e)}}}),"object"==typeof e&&e.exports?void(e.exports=o):o});