diff --git a/bower.json b/bower.json index b7d3f38..37dbe92 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "cross-storage", - "version": "0.3.1", + "version": "0.3.2", "description": "Cross domain local storage", "license": "Apache-2.0", "authors": [ diff --git a/dist/client-0.3.1.js b/dist/client-0.3.2.js similarity index 97% rename from dist/client-0.3.1.js rename to dist/client-0.3.2.js index c142e6b..9b0f6c5 100644 --- a/dist/client-0.3.1.js +++ b/dist/client-0.3.2.js @@ -1,7 +1,7 @@ /** * cross-storage - Cross domain local storage * - * @version 0.3.1 + * @version 0.3.2 * @link https://github.com/zendesk/cross-storage * @author Daniel St. Jules * @copyright Zendesk @@ -359,13 +359,19 @@ CrossStorageClient.prototype._request = function(method, params) { // In case we have a broken Array.prototype.toJSON, e.g. because of // old versions of prototype - var originalToJSON = Array.prototype.toJSON; - Array.prototype.toJSON = null; + var originalToJSON; + + if (Array.prototype.toJSON) { + originalToJSON = Array.prototype.toJSON; + Array.prototype.toJSON = null; + } // Send serialized message client._hub.postMessage(JSON.stringify(req), client._origin); // Restore original toJSON - Array.prototype.toJSON = originalToJSON; + if (originalToJSON) { + Array.prototype.toJSON = originalToJSON; + } }); }; diff --git a/dist/client-0.3.1.min.js b/dist/client-0.3.2.min.js similarity index 93% rename from dist/client-0.3.1.min.js rename to dist/client-0.3.2.min.js index 152c105..4cf243a 100644 --- a/dist/client-0.3.1.min.js +++ b/dist/client-0.3.2.min.js @@ -1,11 +1,11 @@ /** * cross-storage - Cross domain local storage * - * @version 0.3.1 + * @version 0.3.2 * @link https://github.com/zendesk/cross-storage * @author Daniel St. Jules * @copyright Zendesk * @license Apache-2.0 */ -function CrossStorageClient(e,t){t=t||{},this._id=CrossStorageClient._generateUUID(),this._promise=t.promise||Promise,this._frameId=t.frameId||"CrossStorageClient-"+this._id,this._origin=CrossStorageClient._getOrigin(e),this._requests={},this._connected=!1,this._closed=!1,this._count=0,this._timeout=t.timeout||3e3,this._listener=null,this._installListener();var r;t.frameId&&(r=document.getElementById(t.frameId)),r&&this._poll(),r=r||this._createFrame(e),this._hub=r.contentWindow}CrossStorageClient.frameStyle={display:"none",position:"absolute",top:"-999px",left:"-999px"},CrossStorageClient._getOrigin=function(e){var t,r;return t=document.createElement("a"),t.href=e,r=t.protocol+"//"+t.host,r=r.replace(/:80$|:443$/,"")},CrossStorageClient._generateUUID=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0,r="x"==e?t:3&t|8;return r.toString(16)})},CrossStorageClient.prototype.onConnect=function(){if(this._connected)return this._promise.resolve();var e=this;return new this._promise(function(t){e._requests.connect=t})},CrossStorageClient.prototype.set=function(e,t,r){return this._request("set",{key:e,value:t,ttl:r})},CrossStorageClient.prototype.get=function(){var e=Array.prototype.slice.call(arguments);return this._request("get",{keys:e})},CrossStorageClient.prototype.del=function(){var e=Array.prototype.slice.call(arguments);return this._request("del",{keys:e})},CrossStorageClient.prototype.getKeys=function(){return this._request("getKeys")},CrossStorageClient.prototype.close=function(){var e=document.getElementById(this._frameId);e&&e.parentNode.removeChild(e),window.removeEventListener?window.removeEventListener("message",this._listener,!1):window.detachEvent("onmessage",this._listener),this._connected=!1,this._closed=!0},CrossStorageClient.prototype._installListener=function(){var e=this;this._listener=function(t){if(!e._closed&&t.origin===e._origin&&(e._connected||(e._connected=!0,e._requests.connect&&(e._requests.connect(),delete e._requests.connect)),"ready"!==t.data)){var r=JSON.parse(t.data);r.id&&e._requests[r.id]&&e._requests[r.id](r.error,r.result)}},window.addEventListener?window.addEventListener("message",this._listener,!1):window.attachEvent("onmessage",this._listener)},CrossStorageClient.prototype._poll=function(){var e,t;e=this,t=setInterval(function(){return e._connected?clearInterval(t):(e._hub&&e._hub.postMessage("poll",e._origin),void 0)},1e3)},CrossStorageClient.prototype._createFrame=function(e){var t=window.document.createElement("iframe");t.id=this._frameId;for(var r in CrossStorageClient.frameStyle)CrossStorageClient.frameStyle.hasOwnProperty(r)&&(t.style[r]=CrossStorageClient.frameStyle[r]);return window.document.body.appendChild(t),t.src=e,t},CrossStorageClient.prototype._request=function(e,t){var r,o;return this._closed?this._promise.reject(new Error("CrossStorageClient has closed")):(o=this,o._count++,r={id:this._id+":"+o._count,method:e,params:t},new this._promise(function(e,t){var n=setTimeout(function(){o._requests[r.id]&&(delete o._requests[r.id],t(new Error("Timeout: could not perform "+r.method)))},o._timeout);o._requests[r.id]=function(r,o){return clearTimeout(n),r?t(new Error(r)):(e(o),void 0)};var s=Array.prototype.toJSON;Array.prototype.toJSON=null,o._hub.postMessage(JSON.stringify(r),o._origin),Array.prototype.toJSON=s}))}; \ No newline at end of file +function CrossStorageClient(e,t){t=t||{},this._id=CrossStorageClient._generateUUID(),this._promise=t.promise||Promise,this._frameId=t.frameId||"CrossStorageClient-"+this._id,this._origin=CrossStorageClient._getOrigin(e),this._requests={},this._connected=!1,this._closed=!1,this._count=0,this._timeout=t.timeout||3e3,this._listener=null,this._installListener();var r;t.frameId&&(r=document.getElementById(t.frameId)),r&&this._poll(),r=r||this._createFrame(e),this._hub=r.contentWindow}CrossStorageClient.frameStyle={display:"none",position:"absolute",top:"-999px",left:"-999px"},CrossStorageClient._getOrigin=function(e){var t,r;return t=document.createElement("a"),t.href=e,r=t.protocol+"//"+t.host,r=r.replace(/:80$|:443$/,"")},CrossStorageClient._generateUUID=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0,r="x"==e?t:3&t|8;return r.toString(16)})},CrossStorageClient.prototype.onConnect=function(){if(this._connected)return this._promise.resolve();var e=this;return new this._promise(function(t){e._requests.connect=t})},CrossStorageClient.prototype.set=function(e,t,r){return this._request("set",{key:e,value:t,ttl:r})},CrossStorageClient.prototype.get=function(){var e=Array.prototype.slice.call(arguments);return this._request("get",{keys:e})},CrossStorageClient.prototype.del=function(){var e=Array.prototype.slice.call(arguments);return this._request("del",{keys:e})},CrossStorageClient.prototype.getKeys=function(){return this._request("getKeys")},CrossStorageClient.prototype.close=function(){var e=document.getElementById(this._frameId);e&&e.parentNode.removeChild(e),window.removeEventListener?window.removeEventListener("message",this._listener,!1):window.detachEvent("onmessage",this._listener),this._connected=!1,this._closed=!0},CrossStorageClient.prototype._installListener=function(){var e=this;this._listener=function(t){if(!e._closed&&t.origin===e._origin&&(e._connected||(e._connected=!0,e._requests.connect&&(e._requests.connect(),delete e._requests.connect)),"ready"!==t.data)){var r=JSON.parse(t.data);r.id&&e._requests[r.id]&&e._requests[r.id](r.error,r.result)}},window.addEventListener?window.addEventListener("message",this._listener,!1):window.attachEvent("onmessage",this._listener)},CrossStorageClient.prototype._poll=function(){var e,t;e=this,t=setInterval(function(){return e._connected?clearInterval(t):(e._hub&&e._hub.postMessage("poll",e._origin),void 0)},1e3)},CrossStorageClient.prototype._createFrame=function(e){var t=window.document.createElement("iframe");t.id=this._frameId;for(var r in CrossStorageClient.frameStyle)CrossStorageClient.frameStyle.hasOwnProperty(r)&&(t.style[r]=CrossStorageClient.frameStyle[r]);return window.document.body.appendChild(t),t.src=e,t},CrossStorageClient.prototype._request=function(e,t){var r,o;return this._closed?this._promise.reject(new Error("CrossStorageClient has closed")):(o=this,o._count++,r={id:this._id+":"+o._count,method:e,params:t},new this._promise(function(e,t){var n=setTimeout(function(){o._requests[r.id]&&(delete o._requests[r.id],t(new Error("Timeout: could not perform "+r.method)))},o._timeout);o._requests[r.id]=function(r,o){return clearTimeout(n),r?t(new Error(r)):(e(o),void 0)};var s;Array.prototype.toJSON&&(s=Array.prototype.toJSON,Array.prototype.toJSON=null),o._hub.postMessage(JSON.stringify(r),o._origin),s&&(Array.prototype.toJSON=s)}))}; \ No newline at end of file diff --git a/dist/hub-0.3.1.js b/dist/hub-0.3.2.js similarity index 99% rename from dist/hub-0.3.1.js rename to dist/hub-0.3.2.js index bd62bea..9e110af 100644 --- a/dist/hub-0.3.1.js +++ b/dist/hub-0.3.2.js @@ -1,7 +1,7 @@ /** * cross-storage - Cross domain local storage * - * @version 0.3.1 + * @version 0.3.2 * @link https://github.com/zendesk/cross-storage * @author Daniel St. Jules * @copyright Zendesk diff --git a/dist/hub-0.3.1.min.js b/dist/hub-0.3.2.min.js similarity index 99% rename from dist/hub-0.3.1.min.js rename to dist/hub-0.3.2.min.js index c5b3a84..2ba531f 100644 --- a/dist/hub-0.3.1.min.js +++ b/dist/hub-0.3.2.min.js @@ -1,7 +1,7 @@ /** * cross-storage - Cross domain local storage * - * @version 0.3.1 + * @version 0.3.2 * @link https://github.com/zendesk/cross-storage * @author Daniel St. Jules * @copyright Zendesk diff --git a/package.json b/package.json index edff6ae..4904c4b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cross-storage", - "version": "0.3.1", + "version": "0.3.2", "description": "Cross domain local storage", "keywords": [ "local",