2023-02-11 19:21:26 +00:00
|
|
|
if(function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).PullToRefresh=t()}(this,function(){"use strict";var e={pullStartY:null,pullMoveY:null,handlers:[],styleEl:null,events:null,dist:0,state:"pending",timeout:null,distResisted:0,supportsPassive:!1,supportsPointerEvents:"undefined"!=typeof window&&!!window.PointerEvent};try{window.addEventListener("test",null,{get passive(){e.supportsPassive=!0}})}catch(e){}var t,i={setupDOM:function(t){if(!t.ptrElement){var i=document.createElement("div");t.mainElement!==document.body?t.mainElement.parentNode.insertBefore(i,t.mainElement):document.body.insertBefore(i,document.body.firstChild),i.classList.add(t.classPrefix+"ptr"),i.innerHTML=t.getMarkup().replace(/__PREFIX__/g,t.classPrefix),t.ptrElement=i,"function"==typeof t.onInit&&t.onInit(t),e.styleEl||(e.styleEl=document.createElement("style"),e.styleEl.setAttribute("id","pull-to-refresh-js-style"),document.head.appendChild(e.styleEl)),e.styleEl.textContent=t.getStyles().replace(/__PREFIX__/g,t.classPrefix).replace(/\s+/g," ")}return t},onReset:function(t){t.ptrElement&&(t.ptrElement.classList.remove(t.classPrefix+"refresh"),t.ptrElement.style[t.cssProp]="0px",setTimeout(function(){t.ptrElement&&t.ptrElement.parentNode&&(t.ptrElement.parentNode.removeChild(t.ptrElement),t.ptrElement=null),e.state="pending"},t.refreshTimeout))},update:function(t){var i=t.ptrElement.querySelector("."+t.classPrefix+"icon"),n=t.ptrElement.querySelector("."+t.classPrefix+"text");i&&("refreshing"===e.state?i.innerHTML=t.iconRefreshing:i.innerHTML=t.iconArrow),n&&("releasing"===e.state&&(n.innerHTML=t.instructionsReleaseToRefresh),"pulling"!==e.state&&"pending"!==e.state||(n.innerHTML=t.instructionsPullToRefresh),"refreshing"===e.state&&(n.innerHTML=t.instructionsRefreshing))}},n=function(t){return e.pointerEventsEnabled&&e.supportsPointerEvents?t.screenY:t.touches[0].screenY},a=function(){var a;function r(t){var r=e.handlers.filter(function(e){return e.contains(t.target)})[0];e.enable=!!r,r&&"pending"===e.state&&(a=i.setupDOM(r),r.shouldPullToRefresh()&&(e.pullStartY=n(t)),clearTimeout(e.timeout),i.update(r))}function o(t){a&&a.ptrElement&&e.enable&&(e.pullStartY?e.pullMoveY=n(t):a.shouldPullToRefresh()&&(e.pullStartY=n(t)),"refreshing"!==e.state?("pending"===e.state&&(a.ptrElement.classList.add(a.classPrefix+"pull"),e.state="pulling",i.update(a)),e.pullStartY&&e.pullMoveY&&(e.dist=e.pullMoveY-e.pullStartY),e.distExtra=e.dist-a.distIgnore,e.distExtra>0&&(t.cancelable&&t.preventDefault(),a.ptrElement.style[a.cssProp]=e.distResisted+"px",e.distResisted=a.resistanceFunction(e.distExtra/a.distThreshold)*Math.min(a.distMax,e.distExtra),"pulling"===e.state&&e.distResisted>a.distThreshold&&(a.ptrElement.classList.add(a.classPrefix+"release"),e.state="releasing",i.update(a)),"releasing"===e.state&&e.distResisted<a.distThreshold&&(a.ptrElement.classList.remove(a.classPrefix+"release"),e.state="pulling",i.update(a)))):t.cancelable&&a.shouldPullToRefresh()&&e.pullStartY<e.pullMoveY&&t.preventDefault())}function s(){if(a&&a.ptrElement&&e.enable){if(clearTimeout(t),t=setTimeout(function(){a&&a.ptrElement&&"pending"===e.state&&i.onReset(a)},500),"releasing"===e.state&&e.distResisted>a.distThreshold)e.state="refreshing",a.ptrElement.style[a.cssProp]=a.distReload+"px",a.ptrElement.classList.add(a.classPrefix+"refresh"),e.timeout=setTimeout(function(){var e=a.onRefresh(function(){return i.onReset(a)});e&&"function"==typeof e.then&&e.then(function(){return i.onReset(a)}),e||a.onRefresh.length||i.onReset(a)},a.refreshTimeout);else{if("refreshing"===e.state)return;a.ptrElement.style[a.cssProp]="0px",e.state="pending"}i.update(a),a.ptrElement.classList.remove(a.classPrefix+"release"),a.ptrElement.classList.remove(a.classPrefix+"pull"),e.pullStartY=e.pullMoveY=null,e.dist=e.distResisted=0}}function l(){a&&a.mainElement.classList.toggle(a.classPrefix+"top",a.shouldPullToRefresh())}var u=e.supportsPassive?{passive:e.passive||!1}:void 0;return e.pointerEventsEnabled&&e.supportsPointerEv
|