commit a0bc26713ea7488a40c7b3a4fec04227f694d747
parent bafad27311f3e51daf35d6ced23cd30a3c3de256
Author: Aurimas Vinckevicius <aurimas.dev@gmail.com>
Date: Mon, 15 Apr 2013 17:26:13 -0500
Revise translator binding rules for clarity & to favor top frame translators
Diffstat:
1 file changed, 17 insertions(+), 10 deletions(-)
diff --git a/chrome/content/zotero/browser.js b/chrome/content/zotero/browser.js
@@ -804,16 +804,23 @@ Zotero_Browser.Tab.prototype._selectItems = function(obj, itemList, callback) {
*/
Zotero_Browser.Tab.prototype._translatorsAvailable = function(translate, translators) {
if(translators && translators.length) {
- // if there's already a scrapable page in the browser window, and it's
- // still there, ensure it is actually part of the page, then return
- if(this.page.translators && this.page.translators.length && this.page.document.location) {
- if(this.page.document.defaultView && !this.page.document.defaultView.closed
- && this.page.document.location.href != translate.document.location.href) {
- // if it is still there, switch translation to take place on
- if(!translators.length || this.page.translators[0].priority <= translators[0].priority) return;
- } else {
- this.clear();
- }
+ //see if we should keep the previous set of translators
+ if(//we already have a translator for part of this page
+ this.page.translators && this.page.translators.length && this.page.document.location
+ //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
+ //the previous set of translators targets the top frame or the current one does not either
+ && (this.page.document.defaultView == this.page.document.defaultView.top
+ || translate.document.defaultView !== this.page.document.defaultView.top)
+ //the best translator we had was of higher priority than the new set
+ && this.page.translators[0].priority <= translators[0].priority
+ ) {
+ return; //keep what we had
+ } else {
+ this.clear(); //clear URL bar icon
}
this.page.translate = translate;