@better-scroll/pull-up
Version:
pull up to load more data
2 lines (1 loc) • 3.64 kB
JavaScript
!function(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(){"use strict";var s="undefined"!=typeof window,t=s&&navigator.userAgent.toLowerCase();if(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(s)try{var o={};Object.defineProperty(o,"passive",{get:function(){}}),window.addEventListener("test-passive",function(){},o)}catch(t){}var n=s&&document.createElement("div").style,i=function(){if(s)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 i=o[t];if(void 0!==n[i.value])return i.key}return!1}();function e(t){return!1===i?t:"standard"===i?"transitionEnd"===t?"transitionend":t:i+t.charAt(0).toUpperCase()+t.substr(1)}i&&"standard"!==i&&i.toLowerCase();e("transform"),e("transition"),s&&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=function(t,o){for(var i in o)t[i]=o[i];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,i){t.on(o,i,this),this.hooksFn.push([t,o,i])},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,i=this.options.threshold;1===this.scroll.movingDirectionY&&t.y<=this.scroll.maxScrollY+i&&(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});