Merge pull request #470 from aurimasv/detect-iframe
For detectWeb, ignore translators targeting iframes with same URL
This commit is contained in:
commit
1a76e32806
2 changed files with 23 additions and 2 deletions
|
@ -812,8 +812,10 @@ Zotero_Browser.Tab.prototype._translatorsAvailable = function(translate, transla
|
||||||
//and the page is still there
|
//and the page is still there
|
||||||
&& this.page.document.defaultView && !this.page.document.defaultView.closed
|
&& 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,
|
//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
|
// because otherwise we want to use the newer set,
|
||||||
&& this.page.document.location.href != translate.document.location.href
|
// 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
|
//the best translator we had was of higher priority than the new set
|
||||||
&& (this.page.translators[0].priority < translators[0].priority
|
&& (this.page.translators[0].priority < translators[0].priority
|
||||||
//or the priority was the same, but...
|
//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)
|
|| 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
|
return; //keep what we had
|
||||||
} else {
|
} else {
|
||||||
this.clear(); //clear URL bar icon
|
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.translate = translate;
|
||||||
this.page.translators = translators;
|
this.page.translators = translators;
|
||||||
this.page.document = translate.document;
|
this.page.document = translate.document;
|
||||||
|
@ -839,6 +845,8 @@ Zotero_Browser.Tab.prototype._translatorsAvailable = function(translate, transla
|
||||||
this._attemptLocalFileImport(translate.document);
|
this._attemptLocalFileImport(translate.document);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!translators || !translators.length) Zotero.debug("Translate: No translators found");
|
||||||
|
|
||||||
Zotero_Browser.updateStatus();
|
Zotero_Browser.updateStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -301,6 +301,19 @@ Zotero.Utilities.Internal = {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return str;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue