size-sensor.min.js 2.2 KB

1
  1. !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).sizeSensor={})}(this,function(e){"use strict";function s(o){var r=1<arguments.length&&void 0!==arguments[1]?arguments[1]:60,u=null;return function(){for(var e=this,t=arguments.length,n=new Array(t),i=0;i<t;i++)n[i]=arguments[i];clearTimeout(u),u=setTimeout(function(){o.apply(e,n)},r)}}function o(e){var t=e.getAttribute(u);if(t&&c[t])return c[t];var n="".concat(r++);e.setAttribute(u,n);var i=d(e);return c[n]=i}var r=1,u="size-sensor-id",d="undefined"!=typeof ResizeObserver?function(n){function i(){o.disconnect(),r=[],o=void 0}var o=void 0,r=[],u=s(function(){r.forEach(function(e){e(n)})});return{element:n,bind:function(e){var t;o||((t=new ResizeObserver(u)).observe(n),u(),o=t),-1===r.indexOf(e)&&r.push(e)},destroy:i,unbind:function(e){var t=r.indexOf(e);-1!==t&&r.splice(t,1),0===r.length&&o&&i()}}}:function(t){function n(){i&&i.parentNode&&(i.contentDocument&&i.contentDocument.defaultView.removeEventListener("resize",r),i.parentNode.removeChild(i),i=void 0,o=[])}var i=void 0,o=[],r=s(function(){o.forEach(function(e){e(t)})});return{element:t,bind:function(e){i=i||function(){"static"===getComputedStyle(t).position&&(t.style.position="relative");var e=document.createElement("object");return e.onload=function(){e.contentDocument.defaultView.addEventListener("resize",r),r()},e.style.display="block",e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.height="100%",e.style.width="100%",e.style.overflow="hidden",e.style.pointerEvents="none",e.style.zIndex="-1",e.style.opacity="0",e.setAttribute("class","size-sensor-object"),e.setAttribute("tabindex","-1"),e.type="text/html",t.appendChild(e),e.data="about:blank",e}(),-1===o.indexOf(e)&&o.push(e)},destroy:n,unbind:function(e){var t=o.indexOf(e);-1!==t&&o.splice(t,1),0===o.length&&i&&n()}}},c={};e.bind=function(e,t){var n=o(e);return n.bind(t),function(){n.unbind(t)}},e.clear=function(e){var t,n,i=o(e);n=(t=i).element.getAttribute(u),t.element.removeAttribute(u),t.destroy(),n&&c[n]&&delete c[n]},e.ver="1.0.1",Object.defineProperty(e,"__esModule",{value:!0})});