فهرست منبع

return a fake clienr rect for document.documentElement

Gildas 7 سال پیش
والد
کامیت
f95b843c69
2فایلهای تغییر یافته به همراه18 افزوده شده و 2 حذف شده
  1. 5 1
      lib/lazy/web/web-lazy-loader-after.js
  2. 13 1
      lib/lazy/web/web-lazy-loader-before.js

+ 5 - 1
lib/lazy/web/web-lazy-loader-after.js

@@ -18,7 +18,7 @@
  *   along with SingleFile.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-/* global screen, window, document, dispatchEvent, UIEvent */
+/* global screen, window, document, dispatchEvent, UIEvent, Element */
 
 (() => {
 
@@ -28,6 +28,10 @@
 	delete document.documentElement.clientWidth;
 	delete screen.height;
 	delete screen.width;
+	if (window._singleFile_getBoundingClientRect) {
+		Element.prototype.getBoundingClientRect = window._singleFile_getBoundingClientRect;
+		delete window._singleFile_getBoundingClientRect;
+	}
 	dispatchEvent(new UIEvent("resize"));
 	dispatchEvent(new UIEvent("scroll"));
 

+ 13 - 1
lib/lazy/web/web-lazy-loader-before.js

@@ -18,7 +18,7 @@
  *   along with SingleFile.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-/* global screen, window, document, dispatchEvent, UIEvent, CustomEvent */
+/* global screen, window, document, dispatchEvent, UIEvent, CustomEvent, Element */
 
 (() => {
 
@@ -30,6 +30,18 @@
 	document.documentElement.__defineGetter__("clientWidth", () => document.documentElement.scrollWidth);
 	screen.__defineGetter__("height", () => document.documentElement.scrollHeight);
 	screen.__defineGetter__("width", () => document.documentElement.scrollWidth);
+	window._singleFile_getBoundingClientRect = Element.prototype.getBoundingClientRect;
+	Element.prototype.getBoundingClientRect = function () {
+		const boundingRect = window._singleFile_getBoundingClientRect.call(this);
+		if (this == document.documentElement) {
+			boundingRect.__defineGetter__("height", () => document.documentElement.scrollHeight);
+			boundingRect.__defineGetter__("bottom", () => document.documentElement.scrollHeight + boundingRect.top);
+			boundingRect.__defineGetter__("width", () => document.documentElement.scrollWidth);
+			boundingRect.__defineGetter__("right", () => document.documentElement.scrollWidth + boundingRect.left);
+		}
+		return boundingRect;
+	};
+	dispatchEvent(new UIEvent("scroll"));
 	dispatchEvent(new UIEvent("resize"));
 	dispatchEvent(new UIEvent("scroll"));
 	dispatchEvent(new CustomEvent(LOAD_OBSERVED_ELEMENTS_EVENT));