Gildas 7 лет назад
Родитель
Сommit
6158ba3442
1 измененных файлов с 9 добавлено и 5 удалено
  1. 9 5
      lib/single-file/frame-tree.js

+ 9 - 5
lib/single-file/frame-tree.js

@@ -27,7 +27,7 @@ this.frameTree = this.frameTree || (() => {
 	const INIT_REQUEST_MESSAGE = "initRequest";
 	const INIT_RESPONSE_MESSAGE = "initResponse";
 	const TIMEOUT_INIT_REQUEST_MESSAGE = 500;
-	const TOP_WINDOW = window == top;
+	const TOP_WINDOW = isTopWindow(window);
 
 	let sessionId, sessions, windowId;
 
@@ -62,7 +62,7 @@ this.frameTree = this.frameTree || (() => {
 		const sessionId = message.sessionId;
 		windowId = message.windowId;
 		const frameElements = document.querySelectorAll(FRAMES_CSS_SELECTOR);
-		if (window != top) {
+		if (!TOP_WINDOW) {
 			const docData = docHelper.preProcessDoc(document, window, message.options);
 			const content = docHelper.serialize(document);
 			docHelper.postProcessDoc(document, window, message.options);
@@ -109,9 +109,9 @@ this.frameTree = this.frameTree || (() => {
 		}
 	}
 
-	function processFrames(frameElements, options, windowId, sessionId, win) {
-		if (win != top) {
-			win.postMessage(MESSAGE_PREFIX + "::" + JSON.stringify({ method: INIT_RESPONSE_MESSAGE, windowId, sessionId }), "*");
+	function processFrames(frameElements, options, windowId, sessionId, window) {
+		if (!isTopWindow(window)) {
+			window.postMessage(MESSAGE_PREFIX + "::" + JSON.stringify({ method: INIT_RESPONSE_MESSAGE, windowId, sessionId }), "*");
 		}
 		let framesData = [];
 		frameElements.forEach((frameElement, frameIndex) => {
@@ -162,4 +162,8 @@ this.frameTree = this.frameTree || (() => {
 		}
 	}
 
+	function isTopWindow(win) {
+		return win == top;
+	}
+
 })();