Don't require a callback to getTranslators, and ask for the translators handler instead, which is already compatible with 2.1. (Not sure what I was thinking last night...)
This commit is contained in:
parent
18bd1855dc
commit
931ba556e1
|
@ -211,22 +211,24 @@ Zotero.Translate.Sandbox = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var translatorsHandlerSet = false;
|
||||||
safeTranslator.getTranslators = function(callback) {
|
safeTranslator.getTranslators = function(callback) {
|
||||||
if(callback) {
|
if(!translation._handlers["translators"] || !translation._handlers["translators"].length) {
|
||||||
translate.incrementAsyncProcesses();
|
if(Zotero.isConnector) {
|
||||||
translation.clearHandlers("translators");
|
throw new Error('Translator must register a "translators" handler to '+
|
||||||
translation.setHandler("translators", function(obj, translators) {
|
'call getTranslators() in this translation environment.');
|
||||||
translate.decrementAsyncProcesses();
|
} else {
|
||||||
callback(translators);
|
translate._debug('COMPAT WARNING: Translator must register a "translators" handler to '+
|
||||||
});
|
'call getTranslators() in connector');
|
||||||
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(!translatorsHandlerSet) {
|
||||||
|
translation.setHandler("translators", function() {
|
||||||
|
translate.decrementAsyncProcesses();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
translate.incrementAsyncProcesses();
|
||||||
|
return translation.getTranslators();
|
||||||
};
|
};
|
||||||
|
|
||||||
var doneHandlerSet = false;
|
var doneHandlerSet = false;
|
||||||
|
@ -244,7 +246,7 @@ Zotero.Translate.Sandbox = {
|
||||||
if(callback) {
|
if(callback) {
|
||||||
translate.incrementAsyncProcesses();
|
translate.incrementAsyncProcesses();
|
||||||
} else {
|
} 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) {
|
var haveTranslatorFunction = function(translator) {
|
||||||
|
@ -401,7 +403,7 @@ Zotero.Translate.Sandbox = {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} 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 "+
|
"Zotero.selectItems(). When executed outside of Firefox, a selectItems() call "+
|
||||||
"will require that this translator to be called multiple times.", 1);
|
"will require that this translator to be called multiple times.", 1);
|
||||||
|
|
||||||
|
@ -432,7 +434,7 @@ Zotero.Translate.Sandbox = {
|
||||||
"_itemDone":function(translate, item) {
|
"_itemDone":function(translate, item) {
|
||||||
if(!item.itemType) {
|
if(!item.itemType) {
|
||||||
item.itemType = "webpage";
|
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") {
|
if(item.type == "attachment" || item.type == "note") {
|
||||||
|
|
|
@ -3,13 +3,13 @@
|
||||||
"label": "COinS",
|
"label": "COinS",
|
||||||
"creator": "Simon Kornblith",
|
"creator": "Simon Kornblith",
|
||||||
"target": "",
|
"target": "",
|
||||||
"minVersion": "2.2",
|
"minVersion": "2.1",
|
||||||
"maxVersion": "",
|
"maxVersion": "",
|
||||||
"priority": 300,
|
"priority": 300,
|
||||||
"inRepository": true,
|
"inRepository": true,
|
||||||
"translatorType": 4,
|
"translatorType": 4,
|
||||||
"browserSupport": "gcs",
|
"browserSupport": "gcs",
|
||||||
"lastUpdated": "2011-07-01 05:16:13"
|
"lastUpdated": "2011-07-01 19:16:28"
|
||||||
}
|
}
|
||||||
|
|
||||||
function detectWeb(doc, url) {
|
function detectWeb(doc, url) {
|
||||||
|
@ -58,10 +58,8 @@ function retrieveNextCOinS(needFullItems, newItems, couldUseFullItems, doc) {
|
||||||
search.setHandler("done", function() {
|
search.setHandler("done", function() {
|
||||||
retrieveNextCOinS(needFullItems, newItems, couldUseFullItems, doc);
|
retrieveNextCOinS(needFullItems, newItems, couldUseFullItems, doc);
|
||||||
});
|
});
|
||||||
search.setSearch(item);
|
|
||||||
|
|
||||||
// look for translators
|
// look for translators
|
||||||
search.getTranslators(function(translators) {
|
search.setHandler("translators", function(obj, translators) {
|
||||||
if(translators.length) {
|
if(translators.length) {
|
||||||
search.setTranslator(translators);
|
search.setTranslator(translators);
|
||||||
search.translate();
|
search.translate();
|
||||||
|
@ -69,6 +67,9 @@ function retrieveNextCOinS(needFullItems, newItems, couldUseFullItems, doc) {
|
||||||
retrieveNextCOinS(needFullItems, newItems, couldUseFullItems, doc);
|
retrieveNextCOinS(needFullItems, newItems, couldUseFullItems, doc);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
search.setSearch(item);
|
||||||
|
search.getTranslators();
|
||||||
} else {
|
} else {
|
||||||
completeCOinS(newItems, couldUseFullItems, doc);
|
completeCOinS(newItems, couldUseFullItems, doc);
|
||||||
Zotero.done();
|
Zotero.done();
|
||||||
|
@ -124,9 +125,7 @@ function completeItems(newItems, useIndices, couldUseFullItems, doc) {
|
||||||
// call next
|
// call next
|
||||||
completeItems(newItems, useIndices, couldUseFullItems);
|
completeItems(newItems, useIndices, couldUseFullItems);
|
||||||
});
|
});
|
||||||
|
search.setHandler("translators", function(obj, translators) {
|
||||||
search.setSearch(newItems[i]);
|
|
||||||
var translators = search.getTranslators(function(translators) {
|
|
||||||
if(translators.length) {
|
if(translators.length) {
|
||||||
search.setTranslator(translators);
|
search.setTranslator(translators);
|
||||||
search.translate();
|
search.translate();
|
||||||
|
@ -138,6 +137,9 @@ function completeItems(newItems, useIndices, couldUseFullItems, doc) {
|
||||||
completeItems(newItems, useIndices, couldUseFullItems);
|
completeItems(newItems, useIndices, couldUseFullItems);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
search.setSearch(newItems[i]);
|
||||||
|
search.getTranslators();
|
||||||
} else {
|
} else {
|
||||||
// add doc as attachment
|
// add doc as attachment
|
||||||
newItems[i].attachments.push({document:doc});
|
newItems[i].attachments.push({document:doc});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user