commit 2305023c5d000f902e6ddaa3c67e10c0d17103ea
parent f70d0c0b2955bb97580f869cbe503914f8c16e58
Author: aurimasv <aurimas.dev@gmail.com>
Date: Thu, 17 Apr 2014 15:59:41 -0500
For detectWeb, ignore translators targeting iframes with same URL
Addresses https://forums.zotero.org/discussion/36104/wall-street-journal-translator-not-working/
Diffstat:
2 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/chrome/content/zotero/browser.js b/chrome/content/zotero/browser.js
@@ -812,8 +812,10 @@ Zotero_Browser.Tab.prototype._translatorsAvailable = function(translate, transla
//and the page is still there
&& this.page.document.defaultView && !this.page.document.defaultView.closed
//this set of translators is not targeting the same URL as a previous set of translators,
- // because otherwise we want to use the newer set
- && this.page.document.location.href != translate.document.location.href
+ // because otherwise we want to use the newer set,
+ // but only if it's not in a subframe of the previous set
+ && (this.page.document.location.href != translate.document.location.href ||
+ Zotero.Utilities.Internal.isIframeOf(translate.document.defaultView, this.page.document.defaultView))
//the best translator we had was of higher priority than the new set
&& (this.page.translators[0].priority < translators[0].priority
//or the priority was the same, but...
@@ -823,11 +825,15 @@ Zotero_Browser.Tab.prototype._translatorsAvailable = function(translate, transla
|| translate.document.defaultView !== this.page.document.defaultView.top)
))
) {
+ Zotero.debug("Translate: a better translator was already found for this page");
return; //keep what we had
} else {
this.clear(); //clear URL bar icon
}
+ Zotero.debug("Translate: found translators for page\n"
+ + "Best translator: " + translators[0].label + " with priority " + translators[0].priority);
+
this.page.translate = translate;
this.page.translators = translators;
this.page.document = translate.document;
@@ -839,6 +845,8 @@ Zotero_Browser.Tab.prototype._translatorsAvailable = function(translate, transla
this._attemptLocalFileImport(translate.document);
}
+ if(!translators || !translators.length) Zotero.debug("Translate: No translators found");
+
Zotero_Browser.updateStatus();
}
diff --git a/chrome/content/zotero/xpcom/utilities_internal.js b/chrome/content/zotero/xpcom/utilities_internal.js
@@ -301,6 +301,19 @@ Zotero.Utilities.Internal = {
return null;
}
return str;
+ },
+
+ /**
+ * Determine if one Window is a descendant of another Window
+ * @param {DOMWindow} suspected child window
+ * @param {DOMWindow} suspected parent window
+ * @return {boolean}
+ */
+ "isIframeOf":function isIframeOf(childWindow, parentWindow) {
+ while(childWindow.parent !== childWindow) {
+ childWindow = childWindow.parent;
+ if(childWindow === parentWindow) return true;
+ }
}
}