2023-03-25 19:57:12 +00:00
|
|
|
!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},s=function(){var s;function a(t){var a=e.handlers.filter(function(e){return e.contains(t.target)})[0];e.enable=!!a,a&&"pending"===e.state&&(s=i.setupDOM(a),a.shouldPullToRefresh()&&(e.pullStartY=n(t)),clearTimeout(e.timeout),i.update(a))}function r(t){s&&s.ptrElement&&e.enable&&(e.pullStartY?e.pullMoveY=n(t):s.shouldPullToRefresh()&&(e.pullStartY=n(t)),"refreshing"!==e.state?("pending"===e.state&&(s.ptrElement.classList.add(s.classPrefix+"pull"),e.state="pulling",i.update(s)),e.pullStartY&&e.pullMoveY&&(e.dist=e.pullMoveY-e.pullStartY),e.distExtra=e.dist-s.distIgnore,e.distExtra>0&&(t.cancelable&&t.preventDefault(),s.ptrElement.style[s.cssProp]=e.distResisted+"px",e.distResisted=s.resistanceFunction(e.distExtra/s.distThreshold)*Math.min(s.distMax,e.distExtra),"pulling"===e.state&&e.distResisted>s.distThreshold&&(s.ptrElement.classList.add(s.classPrefix+"release"),e.state="releasing",i.update(s)),"releasing"===e.state&&e.distResisted<s.distThreshold&&(s.ptrElement.classList.remove(s.classPrefix+"release"),e.state="pulling",i.update(s)))):t.cancelable&&s.shouldPullToRefresh()&&e.pullStartY<e.pullMoveY&&t.preventDefault())}function o(){if(s&&s.ptrElement&&e.enable){if(clearTimeout(t),t=setTimeout(function(){s&&s.ptrElement&&"pending"===e.state&&i.onReset(s)},500),"releasing"===e.state&&e.distResisted>s.distThreshold)e.state="refreshing",s.ptrElement.style[s.cssProp]=s.distReload+"px",s.ptrElement.classList.add(s.classPrefix+"refresh"),e.timeout=setTimeout(function(){var e=s.onRefresh(function(){return i.onReset(s)});e&&"function"==typeof e.then&&e.then(function(){return i.onReset(s)}),e||s.onRefresh.length||i.onReset(s)},s.refreshTimeout);else{if("refreshing"===e.state)return;s.ptrElement.style[s.cssProp]="0px",e.state="pending"}i.update(s),s.ptrElement.classList.remove(s.classPrefix+"release"),s.ptrElement.classList.remove(s.classPrefix+"pull"),e.pullStartY=e.pullMoveY=null,e.dist=e.distResisted=0}}function c(){s&&s.mainElement.classList.toggle(s.classPrefix+"top",s.shouldPullToRefresh())}var l=e.supportsPassive?{passive:e.passive||!1}:void 0;return e.pointerEventsEnabled&&e.supportsPointerEven
|