commit 0f684fee6e9d13e4d450d328ef48b46def7882ca
parent cb6ae9cec72ac0b6d1086fd46a8a0f0b1dba2a89
Author: aurimasv <aurimas.dev@gmail.com>
Date: Thu, 5 Apr 2012 02:44:33 -0500
Move _detectWeb to Zotero.Translate.Web.prototype
Diffstat:
2 files changed, 27 insertions(+), 35 deletions(-)
diff --git a/chrome/content/zotero/recognizePDF.js b/chrome/content/zotero/recognizePDF.js
@@ -463,42 +463,18 @@ Zotero_RecognizePDF.Recognizer.prototype._scrape = function(/**Zotero.Translate*
this._hiddenBrowser.removeEventListener("pageshow", this._scrape.caller, true);
translate.setDocument(this._hiddenBrowser.contentDocument);
- //closure?
- (function(me) {
- me._detectWeb(translate, function(translate, itemType) {
- if(itemType) {
- translate.translate(me._libraryID, false);
- } else {
- me._queryGoogle();
- }
- });
- })(this);
-}
-
-/**
- * Performs detectWeb on a loaded page and calls callback
- * with the itemType returned by the first matching translator or false
- * @private
- */
-Zotero_RecognizePDF.Recognizer.prototype._detectWeb = function(translate, callback) {
- //do we need to use closure here for callback???
- (function(callback) {
- translate.setHandler("translators", function(translate, detected) {
- callback(translate, (detected.length && detected[0].itemType) || false );
- });
- })(callback);
-
- // Only one simultaneous instance allowed.
- if(this._currentState === "detect") throw new Error("RecognizePDF: _scrape is already running");
- translate._currentState = "detect";
- translate._getAllTranslators = false; //though this shouldn't matter, since we're only going to load one translator
+ var me = this;
- var translators = new Array();
- translators.push(Zotero.Translators.get(translate.translator[0]));
- if(!translators[0]) throw new Error('RecognizePDF: could not get translator ' + translate.translator[0]);
+ translate.setHandler("translators", function(translate, detected) {
+ if(detected.length) {
+ translate.translate(me._libraryID, false);
+ } else {
+ me._queryGoogle();
+ }
+ });
- translate._getTranslatorsTranslatorsReceived(translators);
-};
+ translate._detectWeb();
+}
/**
* Callback to pick first item in the Google Scholar item list
diff --git a/chrome/content/zotero/xpcom/translation/translate.js b/chrome/content/zotero/xpcom/translation/translate.js
@@ -779,7 +779,7 @@ Zotero.Translate.Base.prototype = {
* translators
* valid: all
* called: when a translator search initiated with Zotero.Translate.getTranslators() is
- * complete
+ * complete or when _detectWeb is called and completes.
* passed: an array of appropriate translators
* returns: N/A
* @param {Function} handler Callback function. All handlers will be passed the current
@@ -1427,6 +1427,22 @@ Zotero.Translate.Web.prototype._getTranslatorsGetPotentialTranslators = function
}
/**
+ * Run detectWeb on a loaded document using the set translator
+ */
+Zotero.Translate.Web.prototype._detectWeb = function() {
+ // Only one simultaneous instance allowed.
+ if(this._currentState === "detect") throw new Error("Translate: _detectWeb is already running");
+ this._currentState = "detect";
+ this._getAllTranslators = false;
+
+ var translators = new Array();
+ translators.push(Zotero.Translators.get(this.translator[0]));
+ if(!translators[0]) throw new Error('Translate: could not get translator ' + this.translator[0]);
+
+ this._getTranslatorsTranslatorsReceived(translators);
+}
+
+/**
* Bind sandbox to document being translated
*/
Zotero.Translate.Web.prototype._getSandboxLocation = function() {