web-lazy-loader-before.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Copyright 2018 Gildas Lormeau
  3. * contact : gildas.lormeau <at> gmail.com
  4. *
  5. * This file is part of SingleFile.
  6. *
  7. * SingleFile is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * SingleFile is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public License
  18. * along with SingleFile. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /* global screen, window, document, dispatchEvent, UIEvent, CustomEvent, Element */
  21. (() => {
  22. const LOAD_OBSERVED_ELEMENTS_EVENT = "single-file-load-observed-elements";
  23. window.__defineGetter__("innerHeight", () => document.documentElement.scrollHeight);
  24. window.__defineGetter__("innerWidth", () => document.documentElement.scrollWidth);
  25. document.documentElement.__defineGetter__("clientHeight", () => document.documentElement.scrollHeight);
  26. document.documentElement.__defineGetter__("clientWidth", () => document.documentElement.scrollWidth);
  27. screen.__defineGetter__("height", () => document.documentElement.scrollHeight);
  28. screen.__defineGetter__("width", () => document.documentElement.scrollWidth);
  29. window._singleFile_getBoundingClientRect = Element.prototype.getBoundingClientRect;
  30. Element.prototype.getBoundingClientRect = function () {
  31. const boundingRect = window._singleFile_getBoundingClientRect.call(this);
  32. if (this == document.documentElement) {
  33. boundingRect.__defineGetter__("height", () => document.documentElement.scrollHeight);
  34. boundingRect.__defineGetter__("bottom", () => document.documentElement.scrollHeight + boundingRect.top);
  35. boundingRect.__defineGetter__("width", () => document.documentElement.scrollWidth);
  36. boundingRect.__defineGetter__("right", () => document.documentElement.scrollWidth + boundingRect.left);
  37. }
  38. return boundingRect;
  39. };
  40. dispatchEvent(new UIEvent("resize"));
  41. dispatchEvent(new CustomEvent(LOAD_OBSERVED_ELEMENTS_EVENT));
  42. })();