2 lines
3.0 KiB
JavaScript
2 lines
3.0 KiB
JavaScript
import t,{Component as e}from"react";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}function r(t,e){return r=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},r(t,e)}function i(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&r(t,e)}function u(t){return u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},u(t)}function c(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function l(t,e){if(e&&("object"===u(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return c(t)}function a(t){return a=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},a(t)}function f(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}var s,d,p,y=function(r){i(h,e);var u,c,s,d,p,y=(u=h,c=f(),function(){var t,e=a(u);if(c){var n=a(this).constructor;t=Reflect.construct(e,arguments,n)}else t=e.apply(this,arguments);return l(this,t)});function h(t){var e;return n(this,h),(e=y.call(this,t)).state={loaded:!1},e}return s=h,(d=[{key:"componentDidMount",value:function(){this.state.loaded||(this.shouldLoad()?this.load():this.bindScrollListener())}},{key:"bindScrollListener",value:function(){var t=this;this.documentScrollListener=function(){t.shouldLoad()&&(t.load(),t.unbindScrollListener())},window.addEventListener("scroll",this.documentScrollListener)}},{key:"unbindScrollListener",value:function(){this.documentScrollListener&&(window.removeEventListener("scroll",this.documentScrollListener),this.documentScrollListener=null)}},{key:"shouldLoad",value:function(){if(this.state.loaded)return!1;var t=this.container.getBoundingClientRect();return document.documentElement.clientHeight>=t.top}},{key:"load",value:function(t){this.setState({loaded:!0}),this.props.onLoad&&this.props.onLoad(t)}},{key:"componentWillUnmount",value:function(){this.unbindScrollListener()}},{key:"render",value:function(){var e=this;return t.createElement("div",{ref:function(t){return e.container=t}},this.state.loaded?this.props.children:null)}}])&&o(s.prototype,d),p&&o(s,p),Object.defineProperty(s,"prototype",{writable:!1}),h}();p={onload:null},(d="defaultProps")in(s=y)?Object.defineProperty(s,d,{value:p,enumerable:!0,configurable:!0,writable:!0}):s[d]=p;export{y as DeferredContent};
|