www

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

commit d9ea7dc46c0f6360b80754026942de66bbc95580
parent e4b380e1ed43eff930301abdd106fc185fafb968
Author: Simon Kornblith <simon@simonster.com>
Date:   Thu,  1 Sep 2011 23:23:16 +0000

IE quirks mode support


Diffstat:
Mchrome/content/zotero/xpcom/connector/connector.js | 65+++++++++++++++++++++++++++++++++--------------------------------
Mchrome/content/zotero/xpcom/debug.js | 4++--
Mchrome/content/zotero/xpcom/translation/translate.js | 6+++---
3 files changed, 38 insertions(+), 37 deletions(-)

diff --git a/chrome/content/zotero/xpcom/connector/connector.js b/chrome/content/zotero/xpcom/connector/connector.js @@ -26,9 +26,9 @@ Zotero.Connector = new function() { const CONNECTOR_URI = "http://127.0.0.1:23119/"; const CONNECTOR_API_VERSION = 2; - const IE_HACK_MSG = "ZOTERO_IE_HACK_MSG "; var _ieStandaloneIframeTarget; + var _ieConnectorCallbacks; this.isOnline = null; /** @@ -46,24 +46,38 @@ Zotero.Connector = new function() { return; } - Zotero.debug("Connector: Trying IE hack"); + Zotero.debug("Connector: Looking for Zotero Standalone"); try { var xdr = new XDomainRequest(); xdr.open("POST", "http://127.0.0.1:23119/connector/ping", true); xdr.onerror = xdr.ontimeout = function() { + Zotero.debug("Connector: Zotero Standalone is not online or cannot be contacted"); this.isOnline = false; callback(false); }; xdr.onload = function() { - var listener = function(event) { - if(event.origin === "http://127.0.0.1:23119" && event.data === "ZOTERO_IE_STANDALONE_LOADED true") { - this.isOnline = true; - window.removeEventListener("message", listener, false); - _ieStandaloneIframeTarget = iframe.contentWindow; - callback(true); - } - }; - window.addEventListener("message", listener, false); + Zotero.debug("Connector: Standalone found; trying IE hack"); + + _ieConnectorCallbacks = []; + Zotero.Messaging.addMessageListener("standaloneLoaded", function(data, event) { + if(event.origin !== "http://127.0.0.1:23119") return; + + Zotero.debug("Connector: Standalone loaded"); + this.isOnline = true; + _ieStandaloneIframeTarget = iframe.contentWindow; + callback(true); + }); + Zotero.Messaging.addMessageListener("connectorResponse", function(data, event) { + if(event.origin !== "http://127.0.0.1:23119") return; + + var xhrSurrogate = { + "status":data[1], + "responseText":data[2], + "getResponseHeader":function(x) { return data[3][x.toLowerCase()] } + }; + _ieConnectorCallbacks[data[0]](xhrSurrogate); + delete _ieConnectorCallbacks[data[0]]; + }); var iframe = document.createElement("iframe"); iframe.src = "http://127.0.0.1:23119/connector/ieHack"; @@ -71,6 +85,7 @@ Zotero.Connector = new function() { }; xdr.send(""); } catch(e) { + Zotero.debug("Connector: Zotero Standalone is not online or cannot be contacted"); Zotero.logError(e); this.isOnline = false; callback(false); @@ -100,7 +115,10 @@ Zotero.Connector = new function() { */ this.callMethod = function(method, data, callback) { // Don't bother trying if not online in bookmarklet - if(Zotero.isBookmarklet && this.isOnline === false) callback(false, 0); + if(Zotero.isBookmarklet && this.isOnline === false) { + callback(false, 0); + return; + } var newCallback = function(req) { try { @@ -145,35 +163,18 @@ Zotero.Connector = new function() { } }; - var uri = CONNECTOR_URI+"connector/"+method; if(Zotero.isIE) { // IE requires XDR for CORS if(_ieStandaloneIframeTarget !== undefined) { var requestID = Zotero.Utilities.randomString(); - - var listener = function(event) { - if(event.origin === "http://127.0.0.1:23119" && event.data.substr(0, IE_HACK_MSG.length) === IE_HACK_MSG) { - var data = JSON.parse(event.data.substr(IE_HACK_MSG.length)); - if(data[0] !== "connectorResponse" || data[1][0] !== requestID) return; - - window.removeEventListener("message", listener, false); - - var xhrSurrogate = { - "status":data[1][1], - "responseText":data[1][2], - "getResponseHeader":function(x) { return data[1][3][x.toLowerCase()] } - }; - newCallback(xhrSurrogate); - } - }; - - window.addEventListener("message", listener, false); - _ieStandaloneIframeTarget.postMessage(IE_HACK_MSG+JSON.stringify(["connectorRequest", + _ieConnectorCallbacks[requestID] = newCallback; + _ieStandaloneIframeTarget.postMessage("ZOTERO_MSG "+JSON.stringify([null, "connectorRequest", [requestID, method, JSON.stringify(data)]]), "http://127.0.0.1:23119/connector/ieHack"); } else { Zotero.debug("Connector: No iframe target; not sending to Standalone"); callback(false, 0); } } else { // Other browsers can use plain doPost + var uri = CONNECTOR_URI+"connector/"+method; Zotero.HTTP.doPost(uri, JSON.stringify(data), newCallback, { "Content-Type":"application/json", diff --git a/chrome/content/zotero/xpcom/debug.js b/chrome/content/zotero/xpcom/debug.js @@ -90,8 +90,8 @@ Zotero.Debug = new function () { var output = 'zotero(' + level + ')' + (_time ? deltaStr : '') + ': ' + message; if(Zotero.isFx) { dump(output+"\n\n"); - } else { - console.log(output); + } else if(window.console) { + window.console.log(output); } } if (_store) { diff --git a/chrome/content/zotero/xpcom/translation/translate.js b/chrome/content/zotero/xpcom/translation/translate.js @@ -45,7 +45,7 @@ Zotero.Translate = function(type) { * Create a new translator by a string type */ Zotero.Translate.newInstance = function(type) { - return new Zotero.Translate[type[0].toUpperCase()+type.substr(1).toLowerCase()]; + return new Zotero.Translate[type.substr(0, 1).toUpperCase()+type.substr(1).toLowerCase()]; } /** @@ -193,7 +193,7 @@ Zotero.Translate.Sandbox = { return; } - Zotero.debug("Translate: creating translate instance of type "+type+" in sandbox"); + Zotero.debug("Translate: Creating translate instance of type "+type+" in sandbox"); var translation = Zotero.Translate.newInstance(type); translation._parentTranslator = translate; @@ -1391,7 +1391,7 @@ Zotero.Translate.Web.prototype._getTranslatorsGetPotentialTranslators = function * Bind sandbox to document being translated */ Zotero.Translate.Web.prototype._getSandboxLocation = function() { - return this.document.defaultView; + return ("defaultView" in this.document ? this.document.defaultView : this.document.location.toString()); } /**