Merge pull request #470 from aurimasv/detect-iframe

For detectWeb, ignore translators targeting iframes with same URL
This commit is contained in:
Simon Kornblith 2014-04-27 18:03:08 -04:00
commit 1a76e32806
2 changed files with 23 additions and 2 deletions

View file

@ -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();
}

View file

@ -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;
}
}
}