www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 5b815a4fa2112e3c21a23db61ddb707dba61322c
parent 800261db264593737f1b617b0a6bb679a723e0f6
Author: Simon Kornblith <simon@simonster.com>
Date:   Wed,  7 Sep 2011 05:35:22 +0000

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


Diffstat:
Mchrome/content/zotero/xpcom/translation/translate.js | 10++++++++++
Mchrome/content/zotero/xpcom/utilities_translate.js | 6++++--
2 files changed, 14 insertions(+), 2 deletions(-)

diff --git 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 @@ -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); }