Add Zotero.Translate#removeHandler() and don't let processDocuments interfere with Zotero.Translate instance reuse

This commit is contained in:
Simon Kornblith 2011-09-07 05:35:22 +00:00
parent 800261db26
commit 5b815a4fa2
2 changed files with 14 additions and 2 deletions

View file

@ -777,6 +777,16 @@ Zotero.Translate.Base.prototype = {
"clearHandlers":function(type) {
this._handlers[type] = new Array();
},
/**
* Clears a single handler for a given function
* @param {String} type See {@link Zotero.Translate.Base#setHandler} for valid values
* @param {Function} handler Callback function to remove
*/
"removeHandler":function(type, handler) {
var handlerIndex = this._handlers[type].indexOf(handler);
if(handlerIndex !== -1) this._handlers[type].splice(handlerIndex, 1);
},
/**
* Indicates that a new async process is running

View file

@ -230,11 +230,13 @@ Zotero.Utilities.Translate.prototype.processDocuments = function(urls, processor
translate.incrementAsyncProcesses("Zotero.Utilities.Translate#processDocuments");
var hiddenBrowser = Zotero.HTTP.processDocuments(urls, processor, function() {
if(done) done();
translate.setHandler("done", function() {
var handler = function() {
try {
Zotero.Browser.deleteHiddenBrowser(hiddenBrowser);
translate.removeHandler("done", handler);
} catch(e) {}
});
};
translate.setHandler("done", handler);
translate.decrementAsyncProcesses("Zotero.Utilities.Translate#processDocuments");
}, myException, true, translate.cookieSandbox);
}