diff --git a/chrome/content/zotero/xpcom/translation/translate.js b/chrome/content/zotero/xpcom/translation/translate.js index 4756573f37..4e94db86e0 100644 --- a/chrome/content/zotero/xpcom/translation/translate.js +++ b/chrome/content/zotero/xpcom/translation/translate.js @@ -211,22 +211,24 @@ Zotero.Translate.Sandbox = { } }; + var translatorsHandlerSet = false; safeTranslator.getTranslators = function(callback) { - if(callback) { - translate.incrementAsyncProcesses(); - translation.clearHandlers("translators"); - translation.setHandler("translators", function(obj, translators) { - translate.decrementAsyncProcesses(); - callback(translators); - }); - translation.getTranslators(); - } else if(Zotero.isConnector) { - throw new Error("Translator must pass a callback to getTranslatorObject() to "+ - "operate in this translation environment."); - } else { - Zotero.debug("Translate: COMPAT WARNING: Translator must pass a callback to getTranslators() to operate in connector"); - return translation.getTranslators(); + if(!translation._handlers["translators"] || !translation._handlers["translators"].length) { + if(Zotero.isConnector) { + throw new Error('Translator must register a "translators" handler to '+ + 'call getTranslators() in this translation environment.'); + } else { + translate._debug('COMPAT WARNING: Translator must register a "translators" handler to '+ + 'call getTranslators() in connector'); + } } + if(!translatorsHandlerSet) { + translation.setHandler("translators", function() { + translate.decrementAsyncProcesses(); + }); + } + translate.incrementAsyncProcesses(); + return translation.getTranslators(); }; var doneHandlerSet = false; @@ -244,7 +246,7 @@ Zotero.Translate.Sandbox = { if(callback) { translate.incrementAsyncProcesses(); } else { - Zotero.debug("Translate: COMPAT WARNING: Translator must pass a callback to getTranslatorObject() to operate in connector"); + translate._debug("COMPAT WARNING: Translator must pass a callback to getTranslatorObject() to operate in connector"); } var haveTranslatorFunction = function(translator) { @@ -401,7 +403,7 @@ Zotero.Translate.Sandbox = { } return false; } else { - translate._debug("Translate: COMPAT WARNING: No callback was provided for "+ + translate._debug("COMPAT WARNING: No callback was provided for "+ "Zotero.selectItems(). When executed outside of Firefox, a selectItems() call "+ "will require that this translator to be called multiple times.", 1); @@ -432,7 +434,7 @@ Zotero.Translate.Sandbox = { "_itemDone":function(translate, item) { if(!item.itemType) { item.itemType = "webpage"; - Zotero.debug("Translate: WARNING: No item type specified"); + translate._debug("WARNING: No item type specified"); } if(item.type == "attachment" || item.type == "note") { diff --git a/translators/COinS.js b/translators/COinS.js index 43420d356c..e612394223 100644 --- a/translators/COinS.js +++ b/translators/COinS.js @@ -3,13 +3,13 @@ "label": "COinS", "creator": "Simon Kornblith", "target": "", - "minVersion": "2.2", + "minVersion": "2.1", "maxVersion": "", "priority": 300, "inRepository": true, "translatorType": 4, "browserSupport": "gcs", - "lastUpdated": "2011-07-01 05:16:13" + "lastUpdated": "2011-07-01 19:16:28" } function detectWeb(doc, url) { @@ -58,10 +58,8 @@ function retrieveNextCOinS(needFullItems, newItems, couldUseFullItems, doc) { search.setHandler("done", function() { retrieveNextCOinS(needFullItems, newItems, couldUseFullItems, doc); }); - search.setSearch(item); - // look for translators - search.getTranslators(function(translators) { + search.setHandler("translators", function(obj, translators) { if(translators.length) { search.setTranslator(translators); search.translate(); @@ -69,6 +67,9 @@ function retrieveNextCOinS(needFullItems, newItems, couldUseFullItems, doc) { retrieveNextCOinS(needFullItems, newItems, couldUseFullItems, doc); } }); + + search.setSearch(item); + search.getTranslators(); } else { completeCOinS(newItems, couldUseFullItems, doc); Zotero.done(); @@ -124,9 +125,7 @@ function completeItems(newItems, useIndices, couldUseFullItems, doc) { // call next completeItems(newItems, useIndices, couldUseFullItems); }); - - search.setSearch(newItems[i]); - var translators = search.getTranslators(function(translators) { + search.setHandler("translators", function(obj, translators) { if(translators.length) { search.setTranslator(translators); search.translate(); @@ -138,6 +137,9 @@ function completeItems(newItems, useIndices, couldUseFullItems, doc) { completeItems(newItems, useIndices, couldUseFullItems); } }); + + search.setSearch(newItems[i]); + search.getTranslators(); } else { // add doc as attachment newItems[i].attachments.push({document:doc});