!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i():"function"==typeof define&&define.amd?define(i):t.BScroll=i()}(this,function(){"use strict";function t(t){return!1!==w&&("standard"===w?t:w+t.charAt(0).toUpperCase()+t.substr(1))}function i(t,i,e,s){t.addEventListener(i,e,{passive:!1,capture:!!s})}function e(t,i,e,s){t.removeEventListener(i,e,{passive:!1,capture:!!s})}function s(t){for(var i=0,e=0;t;)i-=t.offsetLeft,e-=t.offsetTop,t=t.offsetParent;return{left:i,top:e}}function o(t){if(t instanceof window.SVGElement){var i=t.getBoundingClientRect();return{top:i.top,left:i.left,width:i.width,height:i.height}}return{top:t.offsetTop,left:t.offsetLeft,width:t.offsetWidth,height:t.offsetHeight}}function n(t,i){for(var e in i)if(i[e].test(t[e]))return!0;return!1}function r(t,i){var e=document.createEvent("Event");e.initEvent(i,!0,!0),e.pageX=t.pageX,e.pageY=t.pageY,t.target.dispatchEvent(e)}function h(t){var i=t.target;if(!/(SELECT|INPUT|TEXTAREA)/i.test(i.tagName)){var e=document.createEvent(window.MouseEvent?"MouseEvents":"Event");e.initEvent("click",!0,!1),e._constructed=!0,i.dispatchEvent(e)}}function a(t,i){i.firstChild?l(t,i.firstChild):i.appendChild(t)}function l(t,i){i.parentNode.insertBefore(t,i)}function c(){return window.performance&&window.performance.now?window.performance.now()+window.performance.timing.navigationStart:+new Date}function p(t){for(var i=arguments.length,e=Array(i>1?i-1:0),s=1;s0&&(m=o?o/u*h:0,d=c),{destination:Math.round(m),duration:d}}function u(t){var i=document.createElement("div"),e=document.createElement("div");return i.style.cssText="position:absolute;z-index:9999;pointerEvents:none",e.style.cssText="box-sizing:border-box;position:absolute;background:rgba(0,0,0,0.5);border:1px solid rgba(255,255,255,0.9);border-radius:3px;",e.className="bscroll-indicator","horizontal"===t?(i.style.cssText+=";height:7px;left:2px;right:2px;bottom:0",e.style.height="100%",i.className="bscroll-horizontal-scrollbar"):(i.style.cssText+=";width:7px;bottom:2px;top:2px;right:1px",e.style.width="100%",i.className="bscroll-vertical-scrollbar"),i.style.cssText+=";overflow:hidden",i.appendChild(e),i}function m(t,i){this.wrapper=i.el,this.wrapperStyle=this.wrapper.style,this.indicator=this.wrapper.children[0],this.indicatorStyle=this.indicator.style,this.scroller=t,this.direction=i.direction,i.fade?(this.visible=0,this.wrapperStyle.opacity="0"):this.visible=1}function f(t){console.error("[BScroll warn]: "+t)}function g(t,i){this.wrapper="string"==typeof t?document.querySelector(t):t,this.wrapper||f("can not resolve the wrapper dom"),this.scroller=this.wrapper.children[0],this.scroller||f("the wrapper need at least one child element to be scroller"),this.scrollerStyle=this.scroller.style,this._init(t,i)}var v=function(){function t(t,i){var e=[],s=!0,o=!1,n=void 0;try{for(var r,h=t[Symbol.iterator]();!(s=(r=h.next()).done)&&(e.push(r.value),!i||e.length!==i);s=!0);}catch(t){o=!0,n=t}finally{try{!s&&h.return&&h.return()}finally{if(o)throw n}}return e}return function(i,e){if(Array.isArray(i))return i;if(Symbol.iterator in Object(i))return t(i,e);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),y=function(t){if(Array.isArray(t)){for(var i=0,e=Array(t.length);ithis.maxPosY){this.transitionTime(500);var e=Math.max(this.indicatorHeight-3*(t-this.maxPosY),8);this.indicatorStyle.height=e+"px",t=this.maxPosY+this.indicatorHeight-e}else this.indicatorStyle.height=this.indicatorHeight+"px";this.y=t,this.scroller.options.useTransform?this.indicatorStyle[X.transform]="translateY("+t+"px)"+this.scroller.translateZ:this.indicatorStyle.top=t+"px"}else{var s=Math.round(this.sizeRatioX*this.scroller.x);if(s<0){this.transitionTime(500);var o=Math.max(this.indicatorWidth+3*s,8);this.indicatorStyle.width=o+"px",s=0}else if(s>this.maxPosX){this.transitionTime(500);var n=Math.max(this.indicatorWidth-3*(s-this.maxPosX),8);this.indicatorStyle.width=n+"px",s=this.maxPosX+this.indicatorWidth-n}else this.indicatorStyle.width=this.indicatorWidth+"px";this.x=s,this.scroller.options.useTransform?this.indicatorStyle[X.transform]="translateX("+s+"px)"+this.scroller.translateZ:this.indicatorStyle.left=s+"px"}},m.prototype.transitionTime=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;this.indicatorStyle[X.transitionDuration]=t+"ms"},m.prototype.transitionTimingFunction=function(t){this.indicatorStyle[X.transitionTimingFunction]=t},m.prototype.remove=function(){this.wrapper.parentNode.removeChild(this.wrapper)},m.prototype._calculate=function(){if("vertical"===this.direction){var t=this.wrapper.clientHeight;this.indicatorHeight=Math.max(Math.round(t*t/(this.scroller.scrollerHeight||t||1)),8),this.indicatorStyle.height=this.indicatorHeight+"px",this.maxPosY=t-this.indicatorHeight,this.sizeRatioY=this.maxPosY/this.scroller.maxScrollY}else{var i=this.wrapper.clientWidth;this.indicatorWidth=Math.max(Math.round(i*i/(this.scroller.scrollerWidth||i||1)),8),this.indicatorStyle.width=this.indicatorWidth+"px",this.maxPosX=i-this.indicatorWidth,this.sizeRatioX=this.maxPosX/this.scroller.maxScrollX}},function(t){t.prototype._init=function(t,i){this._handleOptions(i),this._events={},this.x=0,this.y=0,this.directionX=0,this.directionY=0,this._addDOMEvents(),this._initExtFeatures(),this.refresh(),this.options.snap||this.scrollTo(this.options.startX,this.options.startY),this.enable()},t.prototype._handleOptions=function(t){this.options=p({},E,t),this.translateZ=this.options.HWCompositing&&b?" translateZ(0)":"",this.options.useTransition=this.options.useTransition&&Y,this.options.useTransform=this.options.useTransform&&P,this.options.preventDefault=!this.options.eventPassthrough&&this.options.preventDefault,this.options.scrollX="horizontal"!==this.options.eventPassthrough&&this.options.scrollX,this.options.scrollY="vertical"!==this.options.eventPassthrough&&this.options.scrollY,this.options.freeScroll=this.options.freeScroll&&!this.options.eventPassthrough,this.options.directionLockThreshold=this.options.eventPassthrough?0:this.options.directionLockThreshold,!0===this.options.tap&&(this.options.tap="tap")},t.prototype._addDOMEvents=function(){var t=i;this._handleDOMEvents(t)},t.prototype._removeDOMEvents=function(){var t=e;this._handleDOMEvents(t)},t.prototype._handleDOMEvents=function(t){var i=this.options.bindToWrapper?this.wrapper:window;t(window,"orientationchange",this),t(window,"resize",this),this.options.click&&t(this.wrapper,"click",this,!0),this.options.disableMouse||(t(this.wrapper,"mousedown",this),t(i,"mousemove",this),t(i,"mousecancel",this),t(i,"mouseup",this)),S&&!this.options.disableTouch&&(t(this.wrapper,"touchstart",this),t(i,"touchmove",this),t(i,"touchcancel",this),t(i,"touchend",this)),t(this.scroller,X.transitionEnd,this)},t.prototype._initExtFeatures=function(){this.options.snap&&this._initSnap(),this.options.scrollbar&&this._initScrollbar(),this.options.pullUpLoad&&this._initPullUp(),this.options.pullDownRefresh&&this._initPullDown()},t.prototype.handleEvent=function(t){switch(t.type){case"touchstart":case"mousedown":this._start(t);break;case"touchmove":case"mousemove":this._move(t);break;case"touchend":case"mouseup":case"touchcancel":case"mousecancel":this._end(t);break;case"orientationchange":case"resize":this._resize();break;case"transitionend":case"webkitTransitionEnd":case"oTransitionEnd":case"MSTransitionEnd":this._transitionEnd(t);break;case"click":this.enabled&&!t._constructed&&(n(t.target,this.options.preventDefaultException)||t.preventDefault(),t.stopPropagation())}},t.prototype.refresh=function(){var t=o(this.wrapper);this.wrapperWidth=t.width,this.wrapperHeight=t.height;var i=o(this.scroller);this.scrollerWidth=i.width,this.scrollerHeight=i.height;var e=this.options.wheel;e?(this.items=this.scroller.children,this.options.itemHeight=this.itemHeight=this.items.length?this.scrollerHeight/this.items.length:0,void 0===this.selectedIndex&&(this.selectedIndex=e.selectedIndex),this.options.startY=-this.selectedIndex*this.itemHeight,this.maxScrollX=0,this.maxScrollY=-this.itemHeight*(this.items.length-1)):(this.maxScrollX=this.wrapperWidth-this.scrollerWidth,this.maxScrollY=this.wrapperHeight-this.scrollerHeight),this.hasHorizontalScroll=this.options.scrollX&&this.maxScrollX<0,this.hasVerticalScroll=this.options.scrollY&&this.maxScrollY<0,this.hasHorizontalScroll||(this.maxScrollX=0,this.scrollerWidth=this.wrapperWidth),this.hasVerticalScroll||(this.maxScrollY=0,this.scrollerHeight=this.wrapperHeight),this.endTime=0,this.directionX=0,this.directionY=0,this.wrapperOffset=s(this.wrapper),this.trigger("refresh"),this.resetPosition()},t.prototype.enable=function(){this.enabled=!0},t.prototype.disable=function(){this.enabled=!1}}(g),function(t){t.prototype._start=function(t){var i=_[t.type];if((i===M||0===t.button)&&!(!this.enabled||this.destroyed||this.initiated&&this.initiated!==i)){this.initiated=i,this.options.preventDefault&&!n(t.target,this.options.preventDefaultException)&&t.preventDefault(),this.moved=!1,this.distX=0,this.distY=0,this.directionX=0,this.directionY=0,this.movingDirectionX=0,this.movingDirectionY=0,this.directionLocked=0,this._transitionTime(),this.startTime=c(),this.options.wheel&&(this.target=t.target),this.stop();var e=t.touches?t.touches[0]:t;this.startX=this.x,this.startY=this.y,this.absStartX=this.x,this.absStartY=this.y,this.pointX=e.pageX,this.pointY=e.pageY,this.trigger("beforeScrollStart")}},t.prototype._move=function(t){if(this.enabled&&!this.destroyed&&_[t.type]===this.initiated){this.options.preventDefault&&t.preventDefault();var i=t.touches?t.touches[0]:t,e=i.pageX-this.pointX,s=i.pageY-this.pointY;this.pointX=i.pageX,this.pointY=i.pageY,this.distX+=e,this.distY+=s;var o=Math.abs(this.distX),n=Math.abs(this.distY),r=c();if(!(r-this.endTime>this.options.momentumLimitTime&&nn+this.options.directionLockThreshold?this.directionLocked="h":n>=o+this.options.directionLockThreshold?this.directionLocked="v":this.directionLocked="n"),"h"===this.directionLocked){if("vertical"===this.options.eventPassthrough)t.preventDefault();else if("horizontal"===this.options.eventPassthrough)return void(this.initiated=!1);s=0}else if("v"===this.directionLocked){if("horizontal"===this.options.eventPassthrough)t.preventDefault();else if("vertical"===this.options.eventPassthrough)return void(this.initiated=!1);e=0}e=this.hasHorizontalScroll?e:0,s=this.hasVerticalScroll?s:0,this.movingDirectionX=e>0?-1:e<0?1:0,this.movingDirectionY=s>0?-1:s<0?1:0;var h=this.x+e,a=this.y+s;(h>0||h0?0:this.maxScrollX),(a>0||a0?0:this.maxScrollY),this.moved||(this.moved=!0,this.trigger("scrollStart")),this._translate(h,a),r-this.startTime>this.options.momentumLimitTime&&(this.startTime=r,this.startX=this.x,this.startY=this.y,1===this.options.probeType&&this.trigger("scroll",{x:this.x,y:this.y})),this.options.probeType>1&&this.trigger("scroll",{x:this.x,y:this.y});var l=document.documentElement.scrollLeft||window.pageXOffset||document.body.scrollLeft,p=document.documentElement.scrollTop||window.pageYOffset||document.body.scrollTop,d=this.pointX-l,u=this.pointY-p;(d>document.documentElement.clientWidth-this.options.momentumLimitDistance||ddocument.documentElement.clientHeight-this.options.momentumLimitDistance)&&this._end(t)}}},t.prototype._end=function(t){if(this.enabled&&!this.destroyed&&_[t.type]===this.initiated&&(this.initiated=!1,this.options.preventDefault&&!n(t.target,this.options.preventDefaultException)&&t.preventDefault(),this.trigger("touchEnd",{x:this.x,y:this.y}),!(this.options.pullDownRefresh&&this._checkPullDown()||this.resetPosition(this.options.bounceTime,D.bounce)))){this.isInTransition=!1;var i=Math.round(this.x),e=Math.round(this.y);if(this.moved){this.scrollTo(i,e);var o=i-this.absStartX,a=e-this.absStartY;this.directionX=o>0?-1:o<0?1:0,this.directionY=a>0?-1:a<0?1:0,this.endTime=c();var l=this.endTime-this.startTime,p=Math.abs(i-this.startX),u=Math.abs(e-this.startY);if(this._events.flick&&lthis.options.momentumLimitDistance||p>this.options.momentumLimitDistance)){var f=this.hasHorizontalScroll?d(this.x,this.startX,l,this.maxScrollX,this.options.bounce?this.wrapperWidth:0,this.options):{destination:i,duration:0},g=this.hasVerticalScroll?d(this.y,this.startY,l,this.maxScrollY,this.options.bounce?this.wrapperHeight:0,this.options):{destination:e,duration:0};i=f.destination,e=g.destination,m=Math.max(f.duration,g.duration),this.isInTransition=1}else this.options.wheel&&(e=Math.round(e/this.itemHeight)*this.itemHeight,m=this.options.wheel.adjustTime||400);var v=D.swipe;if(this.options.snap){var y=this._nearestSnap(i,e);this.currentPage=y,m=this.options.snapSpeed||Math.max(Math.max(Math.min(Math.abs(i-y.x),1e3),Math.min(Math.abs(e-y.y),1e3)),300),i=y.x,e=y.y,this.directionX=0,this.directionY=0,v=D.bounce}if(i!==this.x||e!==this.y)return(i>0||i0||e0&&void 0!==arguments[0]?arguments[0]:0;if(this.scrollerStyle[X.transitionDuration]=t+"ms",this.options.wheel)for(var i=0;i=l)return n.isAnimating=!1,n._translate(t,i),void(n.pulling||n.resetPosition(n.options.bounceTime)||n.trigger("scrollEnd",{x:n.x,y:n.y}));var d=s(p=(p-a)/e),u=(t-r)*d+r,m=(i-h)*d+h;n._translate(u,m),n.isAnimating&&(n.animateTimer=H(o)),3===n.options.probeType&&n.trigger("scroll",{x:this.x,y:this.y})}var n=this,r=this.x,h=this.y,a=c(),l=a+e;this.isAnimating=!0,k(this.animateTimer),o()},t.prototype.scrollBy=function(t,i){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:D.bounce;t=this.x+t,i=this.y+i,this.scrollTo(t,i,e,s)},t.prototype.scrollTo=function(t,i){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:D.bounce;this.isInTransition=this.options.useTransition&&e>0&&(t!==this.x||i!==this.y),!e||this.options.useTransition?(this._transitionTimingFunction(s.style),this._transitionTime(e),this._translate(t,i),e&&3===this.options.probeType&&this._startProbe(),this.options.wheel&&(i>0?this.selectedIndex=0:i0?0:r.left0?0:r.top0&&void 0!==arguments[0]?arguments[0]:0,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:D.bounce,e=this.x;!this.hasHorizontalScroll||e>0?e=0:e0?s=0:s2&&void 0!==arguments[2]?arguments[2]:this;this._events[t]||(this._events[t]=[]),this._events[t].push([i,e])},t.prototype.once=function(t,i){function e(){this.off(t,e),o||(o=!0,i.apply(s,arguments))}var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this,o=!1;this.on(t,e)},t.prototype.off=function(t,i){var e=this._events[t];if(e)for(var s=e.length;s--;)e[s][0]===i&&(e[s][0]=void 0)},t.prototype.trigger=function(t){var i=this._events[t];if(i)for(var e=i.length,s=[].concat(y(i)),o=0;o0&&(a(e[e.length-1].cloneNode(!0),this.scroller),this.scroller.appendChild(e[1].cloneNode(!0)))}var s=i.el;"string"==typeof s&&(s=this.scroller.querySelectorAll(s)),this.on("refresh",function(){if(t.pages=[],t.wrapperWidth&&t.wrapperHeight&&t.scrollerWidth&&t.scrollerHeight){var e=i.stepX||t.wrapperWidth,n=i.stepY||t.wrapperHeight,r=0,h=void 0,a=void 0,l=void 0,c=0,p=void 0,d=0,u=void 0,m=void 0;if(s)for(p=s.length,u=-1;ct.maxScrollX&&d++;else for(a=Math.round(e/2),l=Math.round(n/2);r>-t.scrollerWidth;){for(t.pages[c]=[],p=0,h=0;h>-t.scrollerHeight;)t.pages[c][p]={x:Math.max(r,t.maxScrollX),y:Math.max(h,t.maxScrollY),width:e,height:n,cx:r-a,cy:h-l},h-=n,p++;r-=e,c++}var f=i.loop?1:0;t.goToPage(t.currentPage.pageX||f,t.currentPage.pageY||0,0);var g=i.threshold;g%1==0?(t.snapThresholdX=g,t.snapThresholdY=g):(t.snapThresholdX=Math.round(t.pages[t.currentPage.pageX][t.currentPage.pageY].width*g),t.snapThresholdY=Math.round(t.pages[t.currentPage.pageX][t.currentPage.pageY].height*g))}}),this.on("scrollEnd",function(){i.loop&&(0===t.currentPage.pageX&&t.goToPage(t.pages.length-2,t.currentPage.pageY,0),t.currentPage.pageX===t.pages.length-1&&t.goToPage(1,t.currentPage.pageY,0))}),!1!==i.listenFlick&&this.on("flick",function(){var e=i.speed||Math.max(Math.max(Math.min(Math.abs(t.x-t.startX),1e3),Math.min(Math.abs(t.y-t.startY),1e3)),300);t.goToPage(t.currentPage.pageX+t.directionX,t.currentPage.pageY+t.directionY,e)})},t.prototype._nearestSnap=function(t,i){if(!this.pages.length)return{x:0,y:0,pageX:0,pageY:0};var e=0;if(Math.abs(t-this.absStartX)<=this.snapThresholdX&&Math.abs(i-this.absStartY)<=this.snapThresholdY)return this.currentPage;t>0?t=0:t0?i=0:i=this.pages[e][0].cx){t=this.pages[e][0].x;break}s=this.pages[e].length;for(var o=0;o=this.pages[0][o].cy){i=this.pages[0][o].y;break}return e===this.currentPage.pageX&&((e+=this.directionX)<0?e=0:e>=this.pages.length&&(e=this.pages.length-1),t=this.pages[e][0].x),o===this.currentPage.pageY&&((o+=this.directionY)<0?o=0:o>=this.pages[0].length&&(o=this.pages[0].length-1),i=this.pages[0][o].y),{x:t,y:i,pageX:e,pageY:o}},t.prototype.goToPage=function(t,i,e){var s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:D.bounce,o=this.options.snap;t>=this.pages.length?t=this.pages.length-1:t<0&&(t=0),i>=this.pages[t].length?i=this.pages[t].length-1:i<0&&(i=0);var n=this.pages[t][i].x,r=this.pages[t][i].y;e=void 0===e?o.speed||Math.max(Math.max(Math.min(Math.abs(n-this.x),1e3),Math.min(Math.abs(r-this.y),1e3)),300):e,this.currentPage={x:n,y:r,pageX:t,pageY:i},this.scrollTo(n,r,e,s)},t.prototype.next=function(t,i){var e=this.currentPage.pageX,s=this.currentPage.pageY;++e>=this.pages.length&&this.hasVerticalScroll&&(e=0,s++),this.goToPage(e,s,t,i)},t.prototype.prev=function(t,i){var e=this.currentPage.pageX,s=this.currentPage.pageY;--e<0&&this.hasVerticalScroll&&(e=0,s--),this.goToPage(e,s,t,i)},t.prototype.getCurrentPage=function(){return this.options.snap&&this.currentPage}}(g),function(t){t.prototype.wheelTo=function(t){this.options.wheel&&(this.y=-t*this.itemHeight,this.scrollTo(0,this.y))},t.prototype.getSelectedIndex=function(){return this.options.wheel&&this.selectedIndex}}(g),function(t){t.prototype._initScrollbar=function(){var t=this,i=this.options.scrollbar.fade,e=void 0===i||i;this.indicators=[];var s=void 0;this.options.scrollX&&(s={el:u("horizontal"),direction:"horizontal",fade:e},this._insertScrollBar(s.el),this.indicators.push(new m(this,s))),this.options.scrollY&&(s={el:u("vertical"),direction:"vertical",fade:e},this._insertScrollBar(s.el),this.indicators.push(new m(this,s))),this.on("refresh",function(){for(var i=0;ie&&!this.pulling&&(this.pulling=!0,this.trigger("pullingDown"),this.scrollTo(this.x,o,this.options.bounceTime,D.bounce)),this.pulling},t.prototype.finishPullDown=function(){this.pulling=!1,this.resetPosition(this.options.bounceTime,D.bounce)}}(g),function(t){t.prototype._initPullUp=function(){this.options.probeType=3,this.pullupWatching=!1,this._watchPullUp()},t.prototype._watchPullUp=function(){function t(i){1===this.movingDirectionY&&i.y<=this.maxScrollY+e&&(this.trigger("pullingUp"),this.pullupWatching=!1,this.off("scroll",t))}if(!this.pullupWatching){this.pullupWatching=!0;var i=this.options.pullUpLoad.threshold,e=void 0===i?0:i;this.on("scroll",t)}},t.prototype.finishPullUp=function(){var t=this;this.isInTransition?this.once("scrollEnd",function(){t._watchPullUp()}):this._watchPullUp()}}(g),g.Version="1.3.1",g});