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
4.2 KiB

!function(o,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(o="undefined"!=typeof globalThis?globalThis:o||self).PullDown=t()}(this,function(){"use strict";var i="undefined"!=typeof window,n=i&&navigator.userAgent.toLowerCase(),s=(n&&/wechatdevtools/.test(n),n&&n.indexOf("android"),function(){if("string"!=typeof n)return;var o=/os (\d\d?_\d(_\d)?)/.exec(n);if(!o)return;var t=o[1].split("_").map(function(o){return parseInt(o,10)});13<=t[0]&&t[1]}(),i&&document.createElement("div").style),t=function(){if(!i)return!1;for(var o=0,t=[{key:"standard",value:"transform"},{key:"webkit",value:"webkitTransform"},{key:"Moz",value:"MozTransform"},{key:"O",value:"OTransform"},{key:"ms",value:"msTransform"}];o<t.length;o++){var n=t[o];if(void 0!==s[n.value])return n.key}return!1}();function o(o){return!1===t?o:"standard"===t?"transitionEnd"===o?"transitionend":o:t+o.charAt(0).toUpperCase()+o.substr(1)}t&&"standard"!==t&&t.toLowerCase();var e=o("transform"),r=o("transition"),l=(i&&o("perspective")in s,o("transitionTimingFunction"),o("transitionDuration"),o("transitionDelay"),o("transformOrigin"),o("transitionEnd"),o("transitionProperty"),{style:"cubic-bezier(0.165, 0.84, 0.44, 1)",fn:function(o){return 1- --o*o*o*o}}),h=[{key:"finishPullDown",name:"finishPullDown"},{key:"openPullDown",name:"openPullDown"},{key:"closePullDown",name:"closePullDown"},{key:"autoPullDownRefresh",name:"autoPullDownRefresh"}].map(function(o){return{key:o.key,sourceKey:"plugins.pullDownRefresh."+o.name}}),c="pullingDown";function u(o){this.scroll=o,this.pulling=!1,this.init()}return u.prototype.init=function(){this.handleBScroll(),this.handleOptions(this.scroll.options.pullDownRefresh),this.handleHooks(),this.watch()},u.prototype.handleBScroll=function(){this.scroll.registerType([c]),this.scroll.proxy(h)},u.prototype.handleOptions=function(o){void 0===o&&(o={}),o=!0===o?{}:o;this.options=function(o,t){for(var n in t)o[n]=t[n];return o}({threshold:90,stop:40},o),this.scroll.options.probeType=3},u.prototype.handleHooks=function(){var t=this;this.hooksFn=[];var o=this.scroll.scroller,n=o.scrollBehaviorY;this.currentMinScrollY=this.cachedOriginanMinScrollY=n.minScrollPos,this.registerHooks(this.scroll.hooks,this.scroll.hooks.eventTypes.contentChanged,function(){t.finishPullDown()}),this.registerHooks(n.hooks,n.hooks.eventTypes.computeBoundary,function(o){0<o.maxScrollPos&&(o.maxScrollPos=-1),o.minScrollPos=t.currentMinScrollY}),this.scroll.eventTypes.alterOptions&&(this.registerHooks(this.scroll,this.scroll.eventTypes.alterOptions,function(o){o.discreteTime=300,o.easeTime=350}),this.registerHooks(this.scroll,this.scroll.eventTypes.mousewheelEnd,function(){o.hooks.trigger(o.hooks.eventTypes.end)}))},u.prototype.registerHooks=function(o,t,n){o.on(t,n,this),this.hooksFn.push([o,t,n])},u.prototype.watch=function(){var o=this.scroll.scroller;this.watching=!0,this.registerHooks(o.hooks,o.hooks.eventTypes.end,this.checkPullDown)},u.prototype.unwatch=function(){var o=this.scroll.scroller;this.watching=!1,o.hooks.off(o.hooks.eventTypes.end,this.checkPullDown)},u.prototype.checkPullDown=function(){var o=this.options,t=o.threshold,n=o.stop;return!(this.scroll.y<t)&&(this.pulling||(this.modifyBehaviorYBoundary(n),this.pulling=!0,this.scroll.trigger(c)),this.scroll.scrollTo(this.scroll.x,n,this.scroll.options.bounceTime,l),this.pulling)},u.prototype.modifyBehaviorYBoundary=function(o){var t=this.scroll.scroller.scrollBehaviorY;this.cachedOriginanMinScrollY=t.minScrollPos,this.currentMinScrollY=o,t.computeBoundary()},u.prototype.finishPullDown=function(){var o;!0===this.pulling&&(o=this.scroll.scroller.scrollBehaviorY,this.currentMinScrollY=this.cachedOriginanMinScrollY,o.computeBoundary(),this.pulling=!1,this.scroll.resetPosition(this.scroll.options.bounceTime,l))},u.prototype.openPullDown=function(o){void 0===o&&(o={}),this.handleOptions(o),this.watching||this.watch()},u.prototype.closePullDown=function(){this.unwatch()},u.prototype.autoPullDownRefresh=function(){var o=this.options,t=o.threshold,n=o.stop;!this.pulling&&this.watching&&(this.pulling=!0,this.modifyBehaviorYBoundary(n),this.scroll.scrollTo(this.scroll.x,t),this.scroll.trigger(c),this.scroll.scrollTo(this.scroll.x,n,this.scroll.options.bounceTime,l))},u.pluginName="pullDownRefresh",u});