tz-better-scroll-pull-up
Version:
pull up to load more data
2 lines (1 loc) • 3.61 kB
JavaScript
((t,o)=>{"object"==typeof exports&&"undefined"!=typeof module?module.exports=o():"function"==typeof define&&define.amd?define(o):(t="undefined"!=typeof globalThis?globalThis:t||self).PullUp=o()})(this,function(){var i="undefined"!=typeof window,t=i&&navigator.userAgent.toLowerCase();t&&/wechatdevtools/.test(t),t&&t.indexOf("android"),"string"==typeof t&&(t=/os (\d\d?_\d(_\d)?)/.exec(t))&&13===(t=t[1].split("_").map(function(t){return parseInt(t,10)}))[0]&&t[1];if(i)try{var o={};Object.defineProperty(o,"passive",{get:function(){}}),window.addEventListener("test-passive",function(){},o)}catch(t){}var n=i&&document.createElement("div").style,s=(()=>{if(i)for(var t=0,o=[{key:"standard",value:"transform"},{key:"webkit",value:"webkitTransform"},{key:"Moz",value:"MozTransform"},{key:"O",value:"OTransform"},{key:"ms",value:"msTransform"}];t<o.length;t++){var s=o[t];if(void 0!==n[s.value])return s.key}return!1})();function e(t){return!1===s?t:"standard"===s?"transitionEnd"===t?"transitionend":t:s+t.charAt(0).toUpperCase()+t.substr(1)}s&&"standard"!==s&&s.toLowerCase();e("transform"),e("transition"),i&&e("perspective")in n,e("transitionTimingFunction"),e("transitionDuration"),e("transitionDelay"),e("transformOrigin"),e("transitionEnd"),e("transitionProperty");var l=[{key:"finishPullUp",name:"finishPullUp"},{key:"openPullUp",name:"openPullUp"},{key:"closePullUp",name:"closePullUp"},{key:"autoPullUpLoad",name:"autoPullUpLoad"}].map(function(t){return{key:t.key,sourceKey:"plugins.pullUpLoad."+t.name}}),r="pullingUp";function c(t){this.scroll=t,this.pulling=!1,this.watching=!1,this.init()}return c.prototype.init=function(){this.handleBScroll(),this.handleOptions(this.scroll.options.pullUpLoad),this.handleHooks(),this.watch()},c.prototype.handleBScroll=function(){this.scroll.registerType([r]),this.scroll.proxy(l)},c.prototype.handleOptions=function(t){this.options=((t,o)=>{for(var s in o)t[s]=o[s];return t})({threshold:0},t=!0===(t=void 0===t?{}:t)?{}:t),this.scroll.options.probeType=3},c.prototype.handleHooks=function(){var t=this,o=(this.hooksFn=[],this.scroll.scroller.scrollBehaviorY);this.registerHooks(this.scroll.hooks,this.scroll.hooks.eventTypes.contentChanged,function(){t.finishPullUp()}),this.registerHooks(o.hooks,o.hooks.eventTypes.computeBoundary,function(t){0<t.maxScrollPos&&(t.maxScrollPos=-1)})},c.prototype.registerHooks=function(t,o,s){t.on(o,s,this),this.hooksFn.push([t,o,s])},c.prototype.watch=function(){this.watching||(this.watching=!0,this.registerHooks(this.scroll,this.scroll.eventTypes.scroll,this.checkPullUp))},c.prototype.unwatch=function(){this.watching=!1,this.scroll.off(this.scroll.eventTypes.scroll,this.checkPullUp)},c.prototype.checkPullUp=function(t){var o=this,s=this.options.threshold;1===this.scroll.movingDirectionY&&t.y<=this.scroll.maxScrollY+s&&(this.pulling=!0,this.scroll.once(this.scroll.eventTypes.scrollEnd,function(){o.pulling=!1}),this.unwatch(),this.scroll.trigger(r))},c.prototype.finishPullUp=function(){var t=this;this.scroll.scroller.scrollBehaviorY.setMovingDirection(0),this.pulling?this.scroll.once(this.scroll.eventTypes.scrollEnd,function(){t.watch()}):this.watch()},c.prototype.openPullUp=function(t){this.handleOptions(t=void 0===t?{}:t),this.watch()},c.prototype.closePullUp=function(){this.unwatch()},c.prototype.autoPullUpLoad=function(){var t=this.options.threshold,o=this.scroll.scroller.scrollBehaviorY;!this.pulling&&this.watching&&(o=o.maxScrollPos+t+-1,this.scroll.scroller.scrollBehaviorY.setMovingDirection(-1),this.scroll.scrollTo(this.scroll.x,o,this.scroll.options.bounceTime))},c.pluginName="pullUpLoad",c});