1 |
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).ObserveImage=t()}(this,function(){"use strict";var r="undefined"!=typeof window,t=r&&navigator.userAgent.toLowerCase();t&&/wechatdevtools/.test(t),t&&t.indexOf("android"),function(){if("string"==typeof t){var e=/os (\d\d?_\d(_\d)?)/.exec(t);if(!e)return;e=e[1].split("_").map(function(e){return parseInt(e,10)});13===e[0]&&e[1]}}();var i=!1;if(r)try{var e={};Object.defineProperty(e,"passive",{get:function(){i=!0}}),window.addEventListener("test-passive",function(){},e)}catch(e){}var o=r&&document.createElement("div").style,n=function(){if(!r)return!1;for(var e=0,t=[{key:"standard",value:"transform"},{key:"webkit",value:"webkitTransform"},{key:"Moz",value:"MozTransform"},{key:"O",value:"OTransform"},{key:"ms",value:"msTransform"}];e<t.length;e++){var n=t[e];if(void 0!==o[n.value])return n.key}return!1}();function s(e){return!1===n?e:"standard"===n?"transitionEnd"===e?"transitionend":e:n+e.charAt(0).toUpperCase()+e.substr(1)}function a(e,t,n,r){r=i?{passive:!1,capture:!!r}:!!r;e.addEventListener(t,n,r)}function d(e,t,n,r){e.removeEventListener(t,n,{capture:!!r})}n&&"standard"!==n&&n.toLowerCase();s("transform"),s("transition");r&&s("perspective")in o,s("transitionTimingFunction"),s("transitionDuration"),s("transitionDelay"),s("transformOrigin"),s("transitionEnd"),s("transitionProperty");var u=(f.prototype.destroy=function(){this.removeDOMEvents(),this.events=[]},f.prototype.addDOMEvents=function(){this.handleDOMEvents(a)},f.prototype.removeDOMEvents=function(){this.handleDOMEvents(d)},f.prototype.handleDOMEvents=function(t){var n=this,r=this.wrapper;this.events.forEach(function(e){t(r,e.name,n,!!e.capture)})},f.prototype.handleEvent=function(t){var n=t.type;this.events.some(function(e){return e.name===n&&(e.handler(t),!0)})},f);function f(e,t){this.wrapper=e,this.events=t,this.addDOMEvents()}function p(e){this.scroll=e,this.refreshTimer=0,this.init()}return p.prototype.init=function(){this.handleOptions(this.scroll.options.observeImage),this.bindEventsToWrapper()},p.prototype.handleOptions=function(e){this.options=function(e,t){for(var n in t)e[n]=t[n];return e}({debounceTime:100},e=!0===(e=void 0===e?{}:e)?{}:e)},p.prototype.bindEventsToWrapper=function(){var e=this.scroll.scroller.wrapper;this.imageLoadEventRegister=new u(e,[{name:"load",handler:this.load.bind(this),capture:!0}]),this.imageErrorEventRegister=new u(e,[{name:"error",handler:this.load.bind(this),capture:!0}])},p.prototype.load=function(e){var t=this,n=e.target,e=this.options.debounceTime;n&&"img"===n.tagName.toLowerCase()&&(0===e?this.scroll.refresh():(clearTimeout(this.refreshTimer),this.refreshTimer=window.setTimeout(function(){t.scroll.refresh()},this.options.debounceTime)))},p.pluginName="observeImage",p});
|