You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2 lines
3.5 KiB

!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,i=s&&navigator.userAgent.toLowerCase(),n=(i&&/wechatdevtools/.test(i),i&&i.indexOf("android"),function(){if("string"!=typeof i)return;var t=/os (\d\d?_\d(_\d)?)/.exec(i);if(!t)return;var o=t[1].split("_").map(function(t){return parseInt(t,10)});13<=o[0]&&o[1]}(),s&&document.createElement("div").style),o=function(){if(!s)return!1;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 t(t){return!1===o?t:"standard"===o?"transitionEnd"===t?"transitionend":t:o+t.charAt(0).toUpperCase()+t.substr(1)}o&&"standard"!==o&&o.toLowerCase();var e=t("transform"),l=t("transition"),r=(s&&t("perspective")in n,t("transitionTimingFunction"),t("transitionDuration"),t("transitionDelay"),t("transformOrigin"),t("transitionEnd"),t("transitionProperty"),[{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}})),c="pullingUp";function h(t){this.scroll=t,this.pulling=!1,this.watching=!1,this.init()}return h.prototype.init=function(){this.handleBScroll(),this.handleOptions(this.scroll.options.pullUpLoad),this.handleHooks(),this.watch()},h.prototype.handleBScroll=function(){this.scroll.registerType([c]),this.scroll.proxy(r)},h.prototype.handleOptions=function(t){void 0===t&&(t={}),t=!0===t?{}:t;this.options=function(t,o){for(var i in o)t[i]=o[i];return t}({threshold:0},t),this.scroll.options.probeType=3},h.prototype.handleHooks=function(){var t=this;this.hooksFn=[];var o=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)})},h.prototype.registerHooks=function(t,o,i){t.on(o,i,this),this.hooksFn.push([t,o,i])},h.prototype.watch=function(){this.watching||(this.watching=!0,this.registerHooks(this.scroll,this.scroll.eventTypes.scroll,this.checkPullUp))},h.prototype.unwatch=function(){this.watching=!1,this.scroll.off(this.scroll.eventTypes.scroll,this.checkPullUp)},h.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(c))},h.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()},h.prototype.openPullUp=function(t){void 0===t&&(t={}),this.handleOptions(t),this.watch()},h.prototype.closePullUp=function(){this.unwatch()},h.prototype.autoPullUpLoad=function(){var t,o=this.options.threshold,i=this.scroll.scroller.scrollBehaviorY;!this.pulling&&this.watching&&(t=i.maxScrollPos+o+-1,this.scroll.scroller.scrollBehaviorY.setMovingDirection(-1),this.scroll.scrollTo(this.scroll.x,t,this.scroll.options.bounceTime))},h.pluginName="pullUpLoad",h});