Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add module from cross domain XHR in IE8

  • Loading branch information...
commit f77e75419ff7c93fd63633641a65147d412e4b0d 1 parent 458e81b
Paweł Chmielowski prefiks authored
Showing with 50 additions and 0 deletions.
  1. +1 −0  Makefile
  2. +49 −0 src/strophe/strophe.xdr.js
1  Makefile
View
@@ -9,6 +9,7 @@ JS_FILES=\
src/strophe/strophe.js \
src/strophe/strophe.bosh.js \
src/strophe/strophe.pubsub.js \
+ src/strophe/strophe.xdr.js \
src/strophe/strophe.roster.js \
src/strophe/strophe.websocket.js \
src/p1pp.js
49 src/strophe/strophe.xdr.js
View
@@ -0,0 +1,49 @@
+Strophe.addConnectionPlugin("xdomainrequest", {
+ init: function () {
+ if (window.XDomainRequest) {
+ Strophe.debug("using XdomainRequest for IE");
+
+ // override thee send method to fire readystate 2
+ XDomainRequest.prototype.oldsend = XDomainRequest.prototype.send;
+ XDomainRequest.prototype.send = function() {
+ XDomainRequest.prototype.oldsend.apply(this, arguments);
+ this.readyState = 2;
+ try {
+ this.onreadystatechange();
+ } catch (e) {}
+ };
+
+ // replace Strophe.Request._newXHR with the xdomainrequest version
+ Strophe.Request.prototype._newXHR = function () {
+ var fireReadyStateChange = function (xhr, status) {
+ xhr.status = status;
+ xhr.readyState = 4;
+ try {
+ xhr.onreadystatechange();
+ } catch (e) {}
+ };
+ var xhr = new XDomainRequest();
+
+ xhr.readyState = 0;
+ xhr.onreadystatechange = this.func.prependArg(this);
+ xhr.onload = function () {
+ xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
+ xmlDoc.async = "false";
+ xmlDoc.loadXML(xhr.responseText);
+ xhr.responseXML = xmlDoc;
+ fireReadyStateChange(xhr, 200);
+ };
+ xhr.onerror = function () {
+ fireReadyStateChange(xhr, 500);
+ };
+ xhr.ontimeout = function () {
+ fireReadyStateChange(xhr, 500);
+ };
+ return xhr;
+ }
+
+ } else {
+ Strophe.error("XDomainRequest not found. Falling back to native XHR implementation.");
+ }
+ }
+});
Please sign in to comment.
Something went wrong with that request. Please try again.