diff --git a/jstorage.js b/jstorage.js index a30da7d..f04c500 100644 --- a/jstorage.js +++ b/jstorage.js @@ -152,13 +152,13 @@ */ function _init(){ /* Check if browser supports localStorage */ - if(window.localStorage){ + if("localStorage" in window){ try { _storage_service = window.localStorage; } catch(E3) {/* Firefox fails when touching localStorage and cookies are disabled */} } /* Check if browser supports globalStorage */ - else if(window.globalStorage){ + else if("globalStorage" in window){ try { _storage_service = window.globalStorage[window.location.hostname]; } catch(E4) {/* Firefox fails when touching localStorage and cookies are disabled */} @@ -227,7 +227,7 @@ $.jStorage = { /* Version number */ - version: "0.1.4", + version: "0.1.4.1", /** * Sets a key's value. diff --git a/jstorage.min.js b/jstorage.min.js index 19253f6..2841959 100644 --- a/jstorage.min.js +++ b/jstorage.min.js @@ -1 +1 @@ -(function(f){if(!f||!(f.toJSON||Object.toJSON||window.JSON)){throw new Error("jQuery, MooTools or Prototype needs to be loaded before jStorage!")}var g={},d={jStorage:"{}"},h=null,i=0,k=f.toJSON||Object.toJSON||(window.JSON&&(JSON.encode||JSON.stringify)),e=f.evalJSON||(window.JSON&&(JSON.decode||JSON.parse))||function(l){return String(l).evalJSON()},c={isXML:function(m){var l=(m?m.ownerDocument||m:0).documentElement;return l?l.nodeName!=="HTML":false},encode:function(m){if(!this.isXML(m)){return false}try{return new XMLSerializer().serializeToString(m)}catch(l){try{return m.xml}catch(n){}}return false},decode:function(m){var l=("DOMParser" in window&&(new DOMParser()).parseFromString)||(window.ActiveXObject&&function(o){var p=new ActiveXObject("Microsoft.XMLDOM");p.async="false";p.loadXML(o);return p}),n;if(!l){return false}n=l.call("DOMParser" in window&&(new DOMParser())||window,m,"text/xml");return this.isXML(n)?n:false}};function j(){if(window.localStorage){try{d=window.localStorage}catch(p){}}else{if(window.globalStorage){try{d=window.globalStorage[window.location.hostname]}catch(o){}}else{h=document.createElement("link");if(h.addBehavior){h.style.behavior="url(#default#userData)";document.getElementsByTagName("head")[0].appendChild(h);h.load("jStorage");var n="{}";try{n=h.getAttribute("jStorage")}catch(m){}d.jStorage=n}else{h=null;return}}}if(d.jStorage){try{g=e(String(d.jStorage))}catch(l){d.jStorage="{}"}}else{d.jStorage="{}"}i=d.jStorage?String(d.jStorage).length:0}function b(){try{d.jStorage=k(g);if(h){h.setAttribute("jStorage",d.jStorage);h.save("jStorage")}i=d.jStorage?String(d.jStorage).length:0}catch(l){}}function a(l){if((!l&&l!==0)||(typeof l!="string"&&typeof l!="number")){throw new TypeError("Key name must be string or numeric")}return true}f.jStorage={version:"0.1.4",set:function(l,m){a(l);if(c.isXML(m)){m={_is_xml:true,xml:c.encode(m)}}g[l]=m;b();return m},get:function(l,m){a(l);if(l in g){if(typeof g[l]=="object"&&g[l]._is_xml&&g[l]._is_xml){return c.decode(g[l].xml)}else{return g[l]}}return typeof(m)=="undefined"?null:m},deleteKey:function(l){a(l);if(l in g){delete g[l];b();return true}return false},flush:function(){g={};b();try{window.localStorage.clear()}catch(l){}return true},storageObj:function(){function l(){}l.prototype=g;return new l()},index:function(){var l=[],m;for(m in g){if(g.hasOwnProperty(m)){l.push(m)}}return l},storageSize:function(){return i}};j()})(window.jQuery||window.$); \ No newline at end of file +(function(f){if(!f||!(f.toJSON||Object.toJSON||window.JSON)){throw new Error("jQuery, MooTools or Prototype needs to be loaded before jStorage!")}var g={},d={jStorage:"{}"},h=null,i=0,k=f.toJSON||Object.toJSON||(window.JSON&&(JSON.encode||JSON.stringify)),e=f.evalJSON||(window.JSON&&(JSON.decode||JSON.parse))||function(l){return String(l).evalJSON()},c={isXML:function(m){var l=(m?m.ownerDocument||m:0).documentElement;return l?l.nodeName!=="HTML":false},encode:function(m){if(!this.isXML(m)){return false}try{return new XMLSerializer().serializeToString(m)}catch(l){try{return m.xml}catch(n){}}return false},decode:function(m){var l=("DOMParser" in window&&(new DOMParser()).parseFromString)||(window.ActiveXObject&&function(o){var p=new ActiveXObject("Microsoft.XMLDOM");p.async="false";p.loadXML(o);return p}),n;if(!l){return false}n=l.call("DOMParser" in window&&(new DOMParser())||window,m,"text/xml");return this.isXML(n)?n:false}};function j(){if("localStorage" in window){try{d=window.localStorage}catch(p){}}else{if("globalStorage" in window){try{d=window.globalStorage[window.location.hostname]}catch(o){}}else{h=document.createElement("link");if(h.addBehavior){h.style.behavior="url(#default#userData)";document.getElementsByTagName("head")[0].appendChild(h);h.load("jStorage");var n="{}";try{n=h.getAttribute("jStorage")}catch(m){}d.jStorage=n}else{h=null;return}}}if(d.jStorage){try{g=e(String(d.jStorage))}catch(l){d.jStorage="{}"}}else{d.jStorage="{}"}i=d.jStorage?String(d.jStorage).length:0}function b(){try{d.jStorage=k(g);if(h){h.setAttribute("jStorage",d.jStorage);h.save("jStorage")}i=d.jStorage?String(d.jStorage).length:0}catch(l){}}function a(l){if((!l&&l!==0)||(typeof l!="string"&&typeof l!="number")){throw new TypeError("Key name must be string or numeric")}return true}f.jStorage={version:"0.1.4.1",set:function(l,m){a(l);if(c.isXML(m)){m={_is_xml:true,xml:c.encode(m)}}g[l]=m;b();return m},get:function(l,m){a(l);if(l in g){if(typeof g[l]=="object"&&g[l]._is_xml&&g[l]._is_xml){return c.decode(g[l].xml)}else{return g[l]}}return typeof(m)=="undefined"?null:m},deleteKey:function(l){a(l);if(l in g){delete g[l];b();return true}return false},flush:function(){g={};b();try{window.localStorage.clear()}catch(l){}return true},storageObj:function(){function l(){}l.prototype=g;return new l()},index:function(){var l=[],m;for(m in g){if(g.hasOwnProperty(m)){l.push(m)}}return l},storageSize:function(){return i}};j()})(window.jQuery||window.$); \ No newline at end of file