diff --git a/chrome/content/zotero/xpcom/translation/translate.js b/chrome/content/zotero/xpcom/translation/translate.js index 332a8d037..923334b36 100644 --- a/chrome/content/zotero/xpcom/translation/translate.js +++ b/chrome/content/zotero/xpcom/translation/translate.js @@ -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 diff --git a/chrome/content/zotero/xpcom/utilities_translate.js b/chrome/content/zotero/xpcom/utilities_translate.js index 77f75581c..4d8e1d35e 100644 --- a/chrome/content/zotero/xpcom/utilities_translate.js +++ b/chrome/content/zotero/xpcom/utilities_translate.js @@ -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); }