Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added localStorage and sessionStorage polyfills

  • Loading branch information...
commit cebdb9bbac1f52f1f9cb0deef0853065711237e6 1 parent d40e576
Andris Reinman authored
Showing with 1,398 additions and 67 deletions.
  1. +1 −0  .gitignore
  2. +11 −1 README.md
  3. +206 −36 jstorage.js
  4. +18 −14 jstorage.min.js
  5. +0 −16 test.html
  6. BIN  tests/ajax-loader.gif
  7. +10 −0 tests/data.xml
  8. +30 −0 tests/test10_run.html
  9. +17 −0 tests/test10_setup.html
  10. +40 −0 tests/test11_run.html
  11. +16 −0 tests/test11_setup.html
  12. +22 −0 tests/test12_run.html
  13. +16 −0 tests/test12_setup.html
  14. +30 −0 tests/test13_run.html
  15. +19 −0 tests/test13_setup.html
  16. +26 −0 tests/test14_run.html
  17. +29 −0 tests/test14_setup.html
  18. +28 −0 tests/test15_run.html
  19. +14 −0 tests/test15_setup.html
  20. +28 −0 tests/test16_run.html
  21. +15 −0 tests/test16_setup.html
  22. +36 −0 tests/test17_run.html
  23. +15 −0 tests/test17_setup.html
  24. +44 −0 tests/test18_run.html
  25. +15 −0 tests/test18_setup.html
  26. +19 −0 tests/test19_frame1.html
  27. +26 −0 tests/test19_frame2.html
  28. +37 −0 tests/test19_run.html
  29. +13 −0 tests/test19_setup.html
  30. +13 −0 tests/test1_run.html
  31. +14 −0 tests/test1_setup.html
  32. +19 −0 tests/test20_frame1.html
  33. +27 −0 tests/test20_frame2.html
  34. +40 −0 tests/test20_run.html
  35. +13 −0 tests/test20_setup.html
  36. +13 −0 tests/test2_run.html
  37. +14 −0 tests/test2_setup.html
  38. +18 −0 tests/test3_run.html
  39. +14 −0 tests/test3_setup.html
  40. +30 −0 tests/test4_run.html
  41. +17 −0 tests/test4_setup.html
  42. +40 −0 tests/test5_run.html
  43. +16 −0 tests/test5_setup.html
  44. +22 −0 tests/test6_run.html
  45. +16 −0 tests/test6_setup.html
  46. +13 −0 tests/test7_run.html
  47. +14 −0 tests/test7_setup.html
  48. +13 −0 tests/test8_run.html
  49. +14 −0 tests/test8_setup.html
  50. +18 −0 tests/test9_run.html
  51. +14 −0 tests/test9_setup.html
  52. +205 −0 tests/testrunner.html
View
1  .gitignore
@@ -0,0 +1 @@
+.DS_Store
View
12 README.md
@@ -6,7 +6,11 @@ Additionally jStorage is library agnostic, it works well with any other JavaScri
jStorage supports storing Strings, Numbers, JavaScript objects, Arrays and even native XML nodes which kind of makes it a JSON storage. jStorage also supports setting TTL values for auto expiring stored keys and - best of all - notifying other tabs/windows when a key has been changed, which makes jStorage also a local PubSub platform for web applications.
-jStorage is pretty small, about 8kB when minified.
+jStorage is pretty small, about 10kB when minified, 4kB gzipped.
+
+If jStorage is loaded on the page localStorage and sessionStorage polyfills are added to IE6 and IE7 in addition to regular $.jStorage methods.
+You can use regular setItem/getItem
+methods with the polyfills but getter/setters can be used as well - <code>localStorage.mykey = myval;</code> is absolutely valid with jStorage. The only downside is that you can't use <em>onstorage</em> event, you need to fall back to <em>listenKeyChange</em> instead.
## Donate
@@ -32,6 +36,12 @@ Safari 4+, Chrome 4+, Opera 10.50+
If the browser doesn't support data caching, then no exceptions are raised - jStorage can still
be used by the script but nothing is actually stored.
+## Tests
+
+See [tests/testrunner.html](http://tahvel.info/jStorage/tests/testrunner.html) for unit tests
+
+**NB!** - listenKeyChange and publish/subscribe tests tend to fail sometimes in Internet Explorer, which should be ok.
+
## Docs
Project homepage and docs: [www.jstorage.info](http://www.jstorage.info)
View
242 jstorage.js
@@ -173,8 +173,8 @@
}
},
- _localStoragePolyfillSetKey = function(){},
- _localStoragePolyfillFlush = function(){};
+ _localStoragePolyfillSetKey = function(){};
+
////////////////////////// PRIVATE METHODS ////////////////////////
@@ -195,6 +195,7 @@
// QUOTA_EXCEEDED_ERRROR DOM Exception 22.
}
}
+
if(localStorageReallyWorks){
try {
if(window.localStorage) {
@@ -225,7 +226,14 @@
/* userData element needs to be inserted into the DOM! */
document.getElementsByTagName('head')[0].appendChild(_storage_elm);
- _storage_elm.load("jStorage");
+ try{
+ _storage_elm.load("jStorage");
+ }catch(E){
+ // try to reset cache
+ _storage_elm.setAttribute("jStorage", "{}");
+ _storage_elm.save("jStorage");
+ _storage_elm.load("jStorage");
+ }
var data = "{}";
try{
@@ -244,16 +252,20 @@
}
}
+ // Load data from storage
_load_storage();
// remove dead keys
_handleTTL();
- _handleLocalStoragePolyfill();
+ // create localStorage and sessionStorage polyfills if needed
+ _createPolyfillStorage("local");
+ _createPolyfillStorage("session");
// start listening for changes
_setupObserver();
+ // initialize publish-subscribe service
_handlePubSub();
// handle cached navigation
@@ -266,68 +278,225 @@
}
}
- function _handleLocalStoragePolyfill(forceCreate){
- var _skipSave = false;
- if(!forceCreate && typeof window.localStorage != "undefined"){
+ /**
+ * Create a polyfill for localStorage (type="local") or sessionStorage (type="session")
+ *
+ * @param {String} type Either "local" or "session"
+@param {Boolean} forceCreate If set to true, recreate the polyfill (needed with flush)
+ */
+ function _createPolyfillStorage(type, forceCreate){
+ var _skipSave = false,
+ _length = 0,
+ i,
+ storage,
+ storage_source = {};
+
+ var rand = Math.random();
+
+ if(!forceCreate && typeof window[type+"Storage"] != "undefined"){
return;
}
- if(window.globalStorage){
+ // Use globalStorage for localStorage if available
+ if(type == "local" && window.globalStorage){
localStorage = window.globalStorage[window.location.hostname];
return;
}
- if("attachEvent" in document){
- var i;
+ // only IE6/7 from this point on
+ if(_backend != "userDataBehavior"){
+ return;
+ }
+
+ // Remove existing storage element if available
+ if(forceCreate && window[type+"Storage"] && window[type+"Storage"].parentNode){
+ window[type+"Storage"].parentNode.removeChild(window[type+"Storage"]);
+ }
+
+ storage = document.createElement("button");
+ document.getElementsByTagName('head')[0].appendChild(storage);
+
+ if(type == "local"){
+ storage_source = _storage;
+ }else if(type == "session"){
+ _sessionStoragePolyfillUpdate();
+ }
+
+ for(i in storage_source){
- if(window.localStorage && window.localStorage.parentNode){
- localStorage.parentNode.removeChild(localStorage);
+ if(storage_source.hasOwnProperty(i) && i != "__jstorage_meta" && i != "length" && typeof storage_source[i] != "undefined"){
+ if(!(i in storage)){
+ _length++;
+ }
+ storage[i] = storage_source[i];
}
+ }
+
+ // Polyfill API
- localStorage = document.createElement("button");
- document.getElementsByTagName('head')[0].appendChild(localStorage);
-
- for(i in _storage){
- if(_storage.hasOwnProperty(i) && i != "__jstorage_meta"){
- localStorage[i] = _storage[i];
+ /**
+ * Indicates how many keys are stored in the storage
+ */
+ storage.length = _length;
+
+ /**
+ * Returns the key of the nth stored value
+ *
+ * @param {Number} n Index position
+ * @return {String} Key name of the nth stored value
+ */
+ storage.key = function(n){
+ var count = 0, i;
+ _sessionStoragePolyfillUpdate();
+ for(i in storage_source){
+ if(storage_source.hasOwnProperty(i) && i != "__jstorage_meta" && i!="length" && typeof storage_source[i] != "undefined"){
+ if(count == n){
+ return i;
+ }
+ count++;
}
}
+ }
- localStorage.setItem = function(key, value){
- localStorage[key] = value;
+ /**
+ * Returns the current value associated with the given key
+ *
+ * @param {String} key key name
+ * @return {Mixed} Stored value
+ */
+ storage.getItem = function(key){
+ _sessionStoragePolyfillUpdate();
+ if(type == "session"){
+ return storage_source[key];
}
+ return $.jStorage.get(key);
+ }
- localStorage.getItem = function(key){
- return $.jStorage.get(key);
+ /**
+ * Sets or updates value for a give key
+ *
+ * @param {String} key Key name to be updated
+ * @param {String} value String value to be stored
+ */
+ storage.setItem = function(key, value){
+ if(typeof value == "undefined"){
+ return;
}
+ storage[key] = (value || "").toString();
+ }
- localStorage.removeItem = function(key){
+ /**
+ * Removes key from the storage
+ *
+ * @param {String} key Key name to be removed
+ */
+ storage.removeItem = function(key){
+ if(type == "local"){
return $.jStorage.deleteKey(key);
}
- localStorage.clear = function(){
- $.jStorage.flush();
+ storage[key] = undefined;
+
+ _skipSave = true;
+ if(key in storage){
+ storage.removeAttribute(key);
}
+ _skipSave = false;
+ }
- _localStoragePolyfillFlush = function(){
- _handleLocalStoragePolyfill(true);
+ /**
+ * Clear storage
+ */
+ storage.clear = function(){
+ if(type == "session"){
+ window.name = "";
+ _createPolyfillStorage("session", true);
+ return;
}
+ $.jStorage.flush();
+ }
+
+ if(type == "local"){
_localStoragePolyfillSetKey = function(key, value){
+ if(key == "length"){
+ return;
+ }
_skipSave = true;
- localStorage[key] = value;
+ if(typeof value == "undefined"){
+ if(key in storage){
+ _length--;
+ storage.removeAttribute(key);
+ }
+ }else{
+ if(!(key in storage)){
+ _length++;
+ }
+ storage[key] = (value || "").toString();
+ }
+ storage.length = _length;
_skipSave = false;
}
+ }
- localStorage.attachEvent("onpropertychange", function(e){
- if(_skipSave){
+ function _sessionStoragePolyfillUpdate(){
+ if(type != "session"){
return;
}
- $.jStorage.set(e.propertyName, localStorage[e.propertyName]);
- });
- }
+ try{
+ storage_source = JSON.parse(window.name || "{}");
+ }catch(E){
+ storage_source = {};
+ }
+ }
+
+ function _sessionStoragePolyfillSave(){
+ if(type != "session"){
+ return;
+ }
+ window.name = JSON.stringify(storage_source);
+ };
+
+ storage.attachEvent("onpropertychange", function(e){
+ if(e.propertyName == "length"){
+ return;
+ }
+
+ if(_skipSave || e.propertyName == "length"){
+ return;
+ }
+
+ if(type == "local"){
+ if(!(e.propertyName in storage_source) && typeof storage[e.propertyName] != "undefined"){
+ _length ++;
+ }
+ }else if(type == "session"){
+ _sessionStoragePolyfillUpdate();
+ if(typeof storage[e.propertyName] != "undefined" && !(e.propertyName in storage_source)){
+ storage_source[e.propertyName] = storage[e.propertyName];
+ _length++;
+ }else if(typeof storage[e.propertyName] == "undefined" && e.propertyName in storage_source){
+ delete storage_source[e.propertyName];
+ _length--;
+ }else{
+ storage_source[e.propertyName] = storage[e.propertyName];
+ }
+
+ _sessionStoragePolyfillSave();
+ storage.length = _length;
+ return;
+ }
+
+ $.jStorage.set(e.propertyName, storage[e.propertyName]);
+ storage.length = _length;
+ });
+
+ window[type+"Storage"] = storage;
}
+ /**
+ * Reload data from storage when needed
+ */
function _reloadData(){
var data = "{}";
@@ -597,7 +766,7 @@
* Fires all subscriber listeners for a pubsub channel
*
* @param {String} channel Channel name
- * @param {Mixed} payload Payload data to deliver
+ * @param {Mixed} payload Payload data to deliver
*/
function _fireSubscribers(channel, payload){
if(_pubsub_observers[channel]){
@@ -709,6 +878,7 @@
// clone the object before saving to _storage tree
value = JSON.parse(JSON.stringify(value));
}
+
_storage[key] = value;
_storage.__jstorage_meta.CRC32[key] = _crc32(JSON.stringify(value));
@@ -759,7 +929,7 @@
}
delete _storage.__jstorage_meta.CRC32[key];
- _localStoragePolyfillSetKey(key, "undefined");
+ _localStoragePolyfillSetKey(key, undefined);
_save();
_publishChange();
@@ -826,7 +996,7 @@
*/
flush: function(){
_storage = {__jstorage_meta:{CRC32:{}}};
- _localStoragePolyfillFlush();
+ _createPolyfillStorage("local", true);
_save();
_publishChange();
_fireObservers(null, "flushed");
View
32 jstorage.min.js
@@ -1,14 +1,18 @@
-(function(){function y(){var a="{}";if("userDataBehavior"==i){d.load("jStorage");try{a=d.getAttribute("jStorage")}catch(c){}try{n=d.getAttribute("jStorage_update")}catch(b){}e.jStorage=a}z();t();A()}function q(){var a;clearTimeout(B);B=setTimeout(function(){if("localStorage"==i||"globalStorage"==i)a=e.jStorage_update;else if("userDataBehavior"==i){d.load("jStorage");try{a=d.getAttribute("jStorage_update")}catch(c){}}if(a&&a!=n){n=a;var g=j.parse(j.stringify(b.__jstorage_meta.CRC32)),l;y();l=j.parse(j.stringify(b.__jstorage_meta.CRC32));
-var f,u=[],h=[];for(f in g)g.hasOwnProperty(f)&&(l[f]?g[f]!=l[f]&&u.push(f):h.push(f));for(f in l)l.hasOwnProperty(f)&&(g[f]||u.push(f));o(u,"updated");o(h,"deleted")}},25)}function o(a,c){a=[].concat(a||[]);if("flushed"==c){var a=[],b;for(b in h)h.hasOwnProperty(b)&&a.push(b);c="deleted"}b=0;for(var l=a.length;b<l;b++)if(h[a[b]])for(var f=0,d=h[a[b]].length;f<d;f++)h[a[b]][f](a[b],c)}function r(){var a=(+new Date).toString();"localStorage"==i||"globalStorage"==i?e.jStorage_update=a:"userDataBehavior"==
-i&&(d.setAttribute("jStorage_update",a),d.save("jStorage"));q()}function z(){if(e.jStorage)try{b=j.parse(String(e.jStorage))}catch(a){e.jStorage="{}"}else e.jStorage="{}";v=e.jStorage?String(e.jStorage).length:0;b.__jstorage_meta||(b.__jstorage_meta={});b.__jstorage_meta.CRC32||(b.__jstorage_meta.CRC32={})}function s(){if(b.__jstorage_meta.PubSub){for(var a=+new Date-2E3,c=0,g=b.__jstorage_meta.PubSub.length;c<g;c++)if(b.__jstorage_meta.PubSub[c][0]<=a){b.__jstorage_meta.PubSub.splice(c,b.__jstorage_meta.PubSub.length-
-c);break}b.__jstorage_meta.PubSub.length||delete b.__jstorage_meta.PubSub}try{e.jStorage=j.stringify(b),d&&(d.setAttribute("jStorage",e.jStorage),d.save("jStorage")),v=e.jStorage?String(e.jStorage).length:0}catch(l){}}function m(a){if(!a||"string"!=typeof a&&"number"!=typeof a)throw new TypeError("Key name must be string or numeric");if("__jstorage_meta"==a)throw new TypeError("Reserved key name");return!0}function t(){var a,c,g,l,f=Infinity,d=!1,e=[];clearTimeout(C);if(b.__jstorage_meta&&"object"==
-typeof b.__jstorage_meta.TTL){a=+new Date;g=b.__jstorage_meta.TTL;l=b.__jstorage_meta.CRC32;for(c in g)g.hasOwnProperty(c)&&(g[c]<=a?(delete g[c],delete l[c],delete b[c],d=!0,e.push(c)):g[c]<f&&(f=g[c]));Infinity!=f&&(C=setTimeout(t,f-a));d&&(s(),r(),o(e,"deleted"))}}function A(){if(b.__jstorage_meta.PubSub){for(var a,c=w,g=len=b.__jstorage_meta.PubSub.length-1;0<=g;g--)if(a=b.__jstorage_meta.PubSub[g],a[0]>w){var c=a[0],d=a[1];a=a[2];if(p[d])for(var f=0,e=p[d].length;f<e;f++)p[d][f](d,j.parse(j.stringify(a)))}w=
-c}}var k=window.jQuery||window.$||(window.$={}),j={parse:window.JSON&&(window.JSON.parse||window.JSON.decode)||String.prototype.evalJSON&&function(a){return String(a).evalJSON()}||k.parseJSON||k.evalJSON,stringify:Object.toJSON||window.JSON&&(window.JSON.stringify||window.JSON.encode)||k.toJSON};if(!j.parse||!j.stringify)throw Error("No JSON support found, include //cdnjs.cloudflare.com/ajax/libs/json2/20110223/json2.js to page");var b={},e={jStorage:"{}"},d=null,v=0,i=!1,h={},B=!1,n=0,p={},w=+new Date,
-C,x={isXML:function(a){return(a=(a?a.ownerDocument||a:0).documentElement)?"HTML"!==a.nodeName:!1},encode:function(a){if(!this.isXML(a))return!1;try{return(new XMLSerializer).serializeToString(a)}catch(b){try{return a.xml}catch(g){}}return!1},decode:function(a){var b="DOMParser"in window&&(new DOMParser).parseFromString||window.ActiveXObject&&function(a){var b=new ActiveXObject("Microsoft.XMLDOM");b.async="false";b.loadXML(a);return b};if(!b)return!1;a=b.call("DOMParser"in window&&new DOMParser||window,
-a,"text/xml");return this.isXML(a)?a:!1}};k.jStorage={version:"0.2.5",set:function(a,c,g){m(a);g=g||{};if("undefined"==typeof c)return this.deleteKey(a),c;if(x.isXML(c))c={_is_xml:!0,xml:x.encode(c)};else{if("function"==typeof c)return;c&&"object"==typeof c&&(c=j.parse(j.stringify(c)))}b[a]=c;var d=b.__jstorage_meta.CRC32,f=j.stringify(c),e,h=0,h=0;e=-1;for(var i=0,k=f.length;i<k;i++)h=(e^f.charCodeAt(i))&255,h="0x"+"00000000 77073096 EE0E612C 990951BA 076DC419 706AF48F E963A535 9E6495A3 0EDB8832 79DCB8A4 E0D5E91E 97D2D988 09B64C2B 7EB17CBD E7B82D07 90BF1D91 1DB71064 6AB020F2 F3B97148 84BE41DE 1ADAD47D 6DDDE4EB F4D4B551 83D385C7 136C9856 646BA8C0 FD62F97A 8A65C9EC 14015C4F 63066CD9 FA0F3D63 8D080DF5 3B6E20C8 4C69105E D56041E4 A2677172 3C03E4D1 4B04D447 D20D85FD A50AB56B 35B5A8FA 42B2986C DBBBC9D6 ACBCF940 32D86CE3 45DF5C75 DCD60DCF ABD13D59 26D930AC 51DE003A C8D75180 BFD06116 21B4F4B5 56B3C423 CFBA9599 B8BDA50F 2802B89E 5F058808 C60CD9B2 B10BE924 2F6F7C87 58684C11 C1611DAB B6662D3D 76DC4190 01DB7106 98D220BC EFD5102A 71B18589 06B6B51F 9FBFE4A5 E8B8D433 7807C9A2 0F00F934 9609A88E E10E9818 7F6A0DBB 086D3D2D 91646C97 E6635C01 6B6B51F4 1C6C6162 856530D8 F262004E 6C0695ED 1B01A57B 8208F4C1 F50FC457 65B0D9C6 12B7E950 8BBEB8EA FCB9887C 62DD1DDF 15DA2D49 8CD37CF3 FBD44C65 4DB26158 3AB551CE A3BC0074 D4BB30E2 4ADFA541 3DD895D7 A4D1C46D D3D6F4FB 4369E96A 346ED9FC AD678846 DA60B8D0 44042D73 33031DE5 AA0A4C5F DD0D7CC9 5005713C 270241AA BE0B1010 C90C2086 5768B525 206F85B3 B966D409 CE61E49F 5EDEF90E 29D9C998 B0D09822 C7D7A8B4 59B33D17 2EB40D81 B7BD5C3B C0BA6CAD EDB88320 9ABFB3B6 03B6E20C 74B1D29A EAD54739 9DD277AF 04DB2615 73DC1683 E3630B12 94643B84 0D6D6A3E 7A6A5AA8 E40ECF0B 9309FF9D 0A00AE27 7D079EB1 F00F9344 8708A3D2 1E01F268 6906C2FE F762575D 806567CB 196C3671 6E6B06E7 FED41B76 89D32BE0 10DA7A5A 67DD4ACC F9B9DF6F 8EBEEFF9 17B7BE43 60B08ED5 D6D6A3E8 A1D1937E 38D8C2C4 4FDFF252 D1BB67F1 A6BC5767 3FB506DD 48B2364B D80D2BDA AF0A1B4C 36034AF6 41047A60 DF60EFC3 A867DF55 316E8EEF 4669BE79 CB61B38C BC66831A 256FD2A0 5268E236 CC0C7795 BB0B4703 220216B9 5505262F C5BA3BBE B2BD0B28 2BB45A92 5CB36A04 C2D7FFA7 B5D0CF31 2CD99E8B 5BDEAE1D 9B64C2B0 EC63F226 756AA39C 026D930A 9C0906A9 EB0E363F 72076785 05005713 95BF4A82 E2B87A14 7BB12BAE 0CB61B38 92D28E9B E5D5BE0D 7CDCEFB7 0BDBDF21 86D3D2D4 F1D4E242 68DDB3F8 1FDA836E 81BE16CD F6B9265B 6FB077E1 18B74777 88085AE6 FF0F6A70 66063BCA 11010B5C 8F659EFF F862AE69 616BFFD3 166CCF45 A00AE278 D70DD2EE 4E048354 3903B3C2 A7672661 D06016F7 4969474D 3E6E77DB AED16A4A D9D65ADC 40DF0B66 37D83BF0 A9BCAE53 DEBB9EC5 47B2CF7F 30B5FFE9 BDBDF21C CABAC28A 53B39330 24B4A3A6 BAD03605 CDD70693 54DE5729 23D967BF B3667A2E C4614AB8 5D681B02 2A6F2B94 B40BBE37 C30C8EA1 5A05DF1B 2D02EF8D".substr(9*
-h,8),e=e>>>8^h;d[a]=e^-1;this.setTTL(a,g.TTL||0);o(a,"updated");return c},get:function(a,c){m(a);return a in b?b[a]&&"object"==typeof b[a]&&b[a]._is_xml&&b[a]._is_xml?x.decode(b[a].xml):b[a]:"undefined"==typeof c?null:c},deleteKey:function(a){m(a);return a in b?(delete b[a],"object"==typeof b.__jstorage_meta.TTL&&a in b.__jstorage_meta.TTL&&delete b.__jstorage_meta.TTL[a],delete b.__jstorage_meta.CRC32[a],s(),r(),o(a,"deleted"),!0):!1},setTTL:function(a,c){var d=+new Date;m(a);c=Number(c)||0;return a in
-b?(b.__jstorage_meta.TTL||(b.__jstorage_meta.TTL={}),0<c?b.__jstorage_meta.TTL[a]=d+c:delete b.__jstorage_meta.TTL[a],s(),t(),r(),!0):!1},getTTL:function(a){var c=+new Date;m(a);return a in b&&b.__jstorage_meta.TTL&&b.__jstorage_meta.TTL[a]?(a=b.__jstorage_meta.TTL[a]-c)||0:0},flush:function(){b={__jstorage_meta:{CRC32:{}}};s();r();o(null,"flushed");return!0},storageObj:function(){function a(){}a.prototype=b;return new a},index:function(){var a=[],c;for(c in b)b.hasOwnProperty(c)&&"__jstorage_meta"!=
-c&&a.push(c);return a},storageSize:function(){return v},currentBackend:function(){return i},storageAvailable:function(){return!!i},listenKeyChange:function(a,b){m(a);h[a]||(h[a]=[]);h[a].push(b)},stopListening:function(a,b){m(a);if(h[a])if(b)for(var d=h[a].length-1;0<=d;d--)h[a][d]==b&&h[a].splice(d,1);else delete h[a]},subscribe:function(a,b){a=(a||"").toString();if(!a)throw new TypeError("Channel not defined");p[a]||(p[a]=[]);p[a].push(b)},publish:function(a,c){a=(a||"").toString();if(!a)throw new TypeError("Channel not defined");
-b.__jstorage_meta||(b.__jstorage_meta={});b.__jstorage_meta.PubSub||(b.__jstorage_meta.PubSub=[]);b.__jstorage_meta.PubSub.unshift([+new Date,a,c]);s();r()},reInit:function(){y()}};a:{k=!1;if("localStorage"in window)try{window.localStorage.setItem("_tmptest","tmpval"),k=!0,window.localStorage.removeItem("_tmptest")}catch(D){}if(k)try{window.localStorage&&(e=window.localStorage,i="localStorage",n=e.jStorage_update)}catch(E){}else if("globalStorage"in window)try{window.globalStorage&&(e=window.globalStorage[window.location.hostname],
-i="globalStorage",n=e.jStorage_update)}catch(F){}else if(d=document.createElement("link"),d.addBehavior){d.style.behavior="url(#default#userData)";document.getElementsByTagName("head")[0].appendChild(d);d.load("jStorage");k="{}";try{k=d.getAttribute("jStorage")}catch(G){}try{n=d.getAttribute("jStorage_update")}catch(H){}e.jStorage=k;i="userDataBehavior"}else{d=null;break a}z();t();"localStorage"==i||"globalStorage"==i?"addEventListener"in window?window.addEventListener("storage",q,!1):document.attachEvent("onstorage",
-q):"userDataBehavior"==i&&setInterval(q,1E3);A();"addEventListener"in window&&window.addEventListener("pageshow",function(a){a.persisted&&q()},!1)}})();
+(function(){function x(a,b){function f(){if("session"==a)try{j=m.parse(window.name||"{}")}catch(b){j={}}}var h=!1,e=0,g,d,j={};Math.random();if(b||"undefined"==typeof window[a+"Storage"])if("local"==a&&window.globalStorage)localStorage=window.globalStorage[window.location.hostname];else if("userDataBehavior"==l){b&&(window[a+"Storage"]&&window[a+"Storage"].parentNode)&&window[a+"Storage"].parentNode.removeChild(window[a+"Storage"]);d=document.createElement("button");document.getElementsByTagName("head")[0].appendChild(d);
+"local"==a?j=c:"session"==a&&f();for(g in j)j.hasOwnProperty(g)&&("__jstorage_meta"!=g&&"length"!=g&&"undefined"!=typeof j[g])&&(g in d||e++,d[g]=j[g]);d.length=e;d.key=function(a){var b=0,c;f();for(c in j)if(j.hasOwnProperty(c)&&"__jstorage_meta"!=c&&"length"!=c&&"undefined"!=typeof j[c]){if(b==a)return c;b++}};d.getItem=function(b){f();return"session"==a?j[b]:o.jStorage.get(b)};d.setItem=function(a,b){"undefined"!=typeof b&&(d[a]=(b||"").toString())};d.removeItem=function(b){if("local"==a)return o.jStorage.deleteKey(b);
+d[b]=void 0;h=!0;b in d&&d.removeAttribute(b);h=!1};d.clear=function(){"session"==a?(window.name="",x("session",!0)):o.jStorage.flush()};"local"==a&&(z=function(a,b){"length"!=a&&(h=!0,"undefined"==typeof b?a in d&&(e--,d.removeAttribute(a)):(a in d||e++,d[a]=(b||"").toString()),d.length=e,h=!1)});d.attachEvent("onpropertychange",function(b){if("length"!=b.propertyName&&!(h||"length"==b.propertyName)){if("local"==a)!(b.propertyName in j)&&"undefined"!=typeof d[b.propertyName]&&e++;else if("session"==
+a){f();"undefined"!=typeof d[b.propertyName]&&!(b.propertyName in j)?(j[b.propertyName]=d[b.propertyName],e++):"undefined"==typeof d[b.propertyName]&&b.propertyName in j?(delete j[b.propertyName],e--):j[b.propertyName]=d[b.propertyName];"session"==a&&(window.name=m.stringify(j));d.length=e;return}o.jStorage.set(b.propertyName,d[b.propertyName]);d.length=e}});window[a+"Storage"]=d}}function D(){var a="{}";if("userDataBehavior"==l){i.load("jStorage");try{a=i.getAttribute("jStorage")}catch(b){}try{q=
+i.getAttribute("jStorage_update")}catch(c){}k.jStorage=a}E();y();F()}function t(){var a;clearTimeout(G);G=setTimeout(function(){if("localStorage"==l||"globalStorage"==l)a=k.jStorage_update;else if("userDataBehavior"==l){i.load("jStorage");try{a=i.getAttribute("jStorage_update")}catch(b){}}if(a&&a!=q){q=a;var f=m.parse(m.stringify(c.__jstorage_meta.CRC32)),h;D();h=m.parse(m.stringify(c.__jstorage_meta.CRC32));var e,g=[],d=[];for(e in f)f.hasOwnProperty(e)&&(h[e]?f[e]!=h[e]&&g.push(e):d.push(e));for(e in h)h.hasOwnProperty(e)&&
+(f[e]||g.push(e));r(g,"updated");r(d,"deleted")}},25)}function r(a,b){a=[].concat(a||[]);if("flushed"==b){var a=[],c;for(c in n)n.hasOwnProperty(c)&&a.push(c);b="deleted"}c=0;for(var h=a.length;c<h;c++)if(n[a[c]])for(var e=0,g=n[a[c]].length;e<g;e++)n[a[c]][e](a[c],b)}function u(){var a=(+new Date).toString();"localStorage"==l||"globalStorage"==l?k.jStorage_update=a:"userDataBehavior"==l&&(i.setAttribute("jStorage_update",a),i.save("jStorage"));t()}function E(){if(k.jStorage)try{c=m.parse(String(k.jStorage))}catch(a){k.jStorage=
+"{}"}else k.jStorage="{}";A=k.jStorage?String(k.jStorage).length:0;c.__jstorage_meta||(c.__jstorage_meta={});c.__jstorage_meta.CRC32||(c.__jstorage_meta.CRC32={})}function v(){if(c.__jstorage_meta.PubSub){for(var a=+new Date-2E3,b=0,f=c.__jstorage_meta.PubSub.length;b<f;b++)if(c.__jstorage_meta.PubSub[b][0]<=a){c.__jstorage_meta.PubSub.splice(b,c.__jstorage_meta.PubSub.length-b);break}c.__jstorage_meta.PubSub.length||delete c.__jstorage_meta.PubSub}try{k.jStorage=m.stringify(c),i&&(i.setAttribute("jStorage",
+k.jStorage),i.save("jStorage")),A=k.jStorage?String(k.jStorage).length:0}catch(h){}}function p(a){if(!a||"string"!=typeof a&&"number"!=typeof a)throw new TypeError("Key name must be string or numeric");if("__jstorage_meta"==a)throw new TypeError("Reserved key name");return!0}function y(){var a,b,f,h,e=Infinity,g=!1,d=[];clearTimeout(H);if(c.__jstorage_meta&&"object"==typeof c.__jstorage_meta.TTL){a=+new Date;f=c.__jstorage_meta.TTL;h=c.__jstorage_meta.CRC32;for(b in f)f.hasOwnProperty(b)&&(f[b]<=
+a?(delete f[b],delete h[b],delete c[b],g=!0,d.push(b)):f[b]<e&&(e=f[b]));Infinity!=e&&(H=setTimeout(y,e-a));g&&(v(),u(),r(d,"deleted"))}}function F(){if(c.__jstorage_meta.PubSub){for(var a,b=B,f=len=c.__jstorage_meta.PubSub.length-1;0<=f;f--)if(a=c.__jstorage_meta.PubSub[f],a[0]>B){var b=a[0],h=a[1];a=a[2];if(s[h])for(var e=0,g=s[h].length;e<g;e++)s[h][e](h,m.parse(m.stringify(a)))}B=b}}var o=window.jQuery||window.$||(window.$={}),m={parse:window.JSON&&(window.JSON.parse||window.JSON.decode)||String.prototype.evalJSON&&
+function(a){return String(a).evalJSON()}||o.parseJSON||o.evalJSON,stringify:Object.toJSON||window.JSON&&(window.JSON.stringify||window.JSON.encode)||o.toJSON};if(!m.parse||!m.stringify)throw Error("No JSON support found, include //cdnjs.cloudflare.com/ajax/libs/json2/20110223/json2.js to page");var c={},k={jStorage:"{}"},i=null,A=0,l=!1,n={},G=!1,q=0,s={},B=+new Date,H,C={isXML:function(a){return(a=(a?a.ownerDocument||a:0).documentElement)?"HTML"!==a.nodeName:!1},encode:function(a){if(!this.isXML(a))return!1;
+try{return(new XMLSerializer).serializeToString(a)}catch(b){try{return a.xml}catch(c){}}return!1},decode:function(a){var b="DOMParser"in window&&(new DOMParser).parseFromString||window.ActiveXObject&&function(a){var b=new ActiveXObject("Microsoft.XMLDOM");b.async="false";b.loadXML(a);return b};if(!b)return!1;a=b.call("DOMParser"in window&&new DOMParser||window,a,"text/xml");return this.isXML(a)?a:!1}},z=function(){};o.jStorage={version:"0.3.0",set:function(a,b,f){p(a);f=f||{};if("undefined"==typeof b)return this.deleteKey(a),
+b;if(C.isXML(b))b={_is_xml:!0,xml:C.encode(b)};else{if("function"==typeof b)return;b&&"object"==typeof b&&(b=m.parse(m.stringify(b)))}c[a]=b;var h=c.__jstorage_meta.CRC32,e=m.stringify(b),g,d=0,d=0;g=-1;for(var j=0,i=e.length;j<i;j++)d=(g^e.charCodeAt(j))&255,d="0x"+"00000000 77073096 EE0E612C 990951BA 076DC419 706AF48F E963A535 9E6495A3 0EDB8832 79DCB8A4 E0D5E91E 97D2D988 09B64C2B 7EB17CBD E7B82D07 90BF1D91 1DB71064 6AB020F2 F3B97148 84BE41DE 1ADAD47D 6DDDE4EB F4D4B551 83D385C7 136C9856 646BA8C0 FD62F97A 8A65C9EC 14015C4F 63066CD9 FA0F3D63 8D080DF5 3B6E20C8 4C69105E D56041E4 A2677172 3C03E4D1 4B04D447 D20D85FD A50AB56B 35B5A8FA 42B2986C DBBBC9D6 ACBCF940 32D86CE3 45DF5C75 DCD60DCF ABD13D59 26D930AC 51DE003A C8D75180 BFD06116 21B4F4B5 56B3C423 CFBA9599 B8BDA50F 2802B89E 5F058808 C60CD9B2 B10BE924 2F6F7C87 58684C11 C1611DAB B6662D3D 76DC4190 01DB7106 98D220BC EFD5102A 71B18589 06B6B51F 9FBFE4A5 E8B8D433 7807C9A2 0F00F934 9609A88E E10E9818 7F6A0DBB 086D3D2D 91646C97 E6635C01 6B6B51F4 1C6C6162 856530D8 F262004E 6C0695ED 1B01A57B 8208F4C1 F50FC457 65B0D9C6 12B7E950 8BBEB8EA FCB9887C 62DD1DDF 15DA2D49 8CD37CF3 FBD44C65 4DB26158 3AB551CE A3BC0074 D4BB30E2 4ADFA541 3DD895D7 A4D1C46D D3D6F4FB 4369E96A 346ED9FC AD678846 DA60B8D0 44042D73 33031DE5 AA0A4C5F DD0D7CC9 5005713C 270241AA BE0B1010 C90C2086 5768B525 206F85B3 B966D409 CE61E49F 5EDEF90E 29D9C998 B0D09822 C7D7A8B4 59B33D17 2EB40D81 B7BD5C3B C0BA6CAD EDB88320 9ABFB3B6 03B6E20C 74B1D29A EAD54739 9DD277AF 04DB2615 73DC1683 E3630B12 94643B84 0D6D6A3E 7A6A5AA8 E40ECF0B 9309FF9D 0A00AE27 7D079EB1 F00F9344 8708A3D2 1E01F268 6906C2FE F762575D 806567CB 196C3671 6E6B06E7 FED41B76 89D32BE0 10DA7A5A 67DD4ACC F9B9DF6F 8EBEEFF9 17B7BE43 60B08ED5 D6D6A3E8 A1D1937E 38D8C2C4 4FDFF252 D1BB67F1 A6BC5767 3FB506DD 48B2364B D80D2BDA AF0A1B4C 36034AF6 41047A60 DF60EFC3 A867DF55 316E8EEF 4669BE79 CB61B38C BC66831A 256FD2A0 5268E236 CC0C7795 BB0B4703 220216B9 5505262F C5BA3BBE B2BD0B28 2BB45A92 5CB36A04 C2D7FFA7 B5D0CF31 2CD99E8B 5BDEAE1D 9B64C2B0 EC63F226 756AA39C 026D930A 9C0906A9 EB0E363F 72076785 05005713 95BF4A82 E2B87A14 7BB12BAE 0CB61B38 92D28E9B E5D5BE0D 7CDCEFB7 0BDBDF21 86D3D2D4 F1D4E242 68DDB3F8 1FDA836E 81BE16CD F6B9265B 6FB077E1 18B74777 88085AE6 FF0F6A70 66063BCA 11010B5C 8F659EFF F862AE69 616BFFD3 166CCF45 A00AE278 D70DD2EE 4E048354 3903B3C2 A7672661 D06016F7 4969474D 3E6E77DB AED16A4A D9D65ADC 40DF0B66 37D83BF0 A9BCAE53 DEBB9EC5 47B2CF7F 30B5FFE9 BDBDF21C CABAC28A 53B39330 24B4A3A6 BAD03605 CDD70693 54DE5729 23D967BF B3667A2E C4614AB8 5D681B02 2A6F2B94 B40BBE37 C30C8EA1 5A05DF1B 2D02EF8D".substr(9*
+d,8),g=g>>>8^d;h[a]=g^-1;this.setTTL(a,f.TTL||0);z(a,b);r(a,"updated");return b},get:function(a,b){p(a);return a in c?c[a]&&"object"==typeof c[a]&&c[a]._is_xml&&c[a]._is_xml?C.decode(c[a].xml):c[a]:"undefined"==typeof b?null:b},deleteKey:function(a){p(a);return a in c?(delete c[a],"object"==typeof c.__jstorage_meta.TTL&&a in c.__jstorage_meta.TTL&&delete c.__jstorage_meta.TTL[a],delete c.__jstorage_meta.CRC32[a],z(a,void 0),v(),u(),r(a,"deleted"),!0):!1},setTTL:function(a,b){var f=+new Date;p(a);
+b=Number(b)||0;return a in c?(c.__jstorage_meta.TTL||(c.__jstorage_meta.TTL={}),0<b?c.__jstorage_meta.TTL[a]=f+b:delete c.__jstorage_meta.TTL[a],v(),y(),u(),!0):!1},getTTL:function(a){var b=+new Date;p(a);return a in c&&c.__jstorage_meta.TTL&&c.__jstorage_meta.TTL[a]?(a=c.__jstorage_meta.TTL[a]-b)||0:0},flush:function(){c={__jstorage_meta:{CRC32:{}}};x("local",!0);v();u();r(null,"flushed");return!0},storageObj:function(){function a(){}a.prototype=c;return new a},index:function(){var a=[],b;for(b in c)c.hasOwnProperty(b)&&
+"__jstorage_meta"!=b&&a.push(b);return a},storageSize:function(){return A},currentBackend:function(){return l},storageAvailable:function(){return!!l},listenKeyChange:function(a,b){p(a);n[a]||(n[a]=[]);n[a].push(b)},stopListening:function(a,b){p(a);if(n[a])if(b)for(var c=n[a].length-1;0<=c;c--)n[a][c]==b&&n[a].splice(c,1);else delete n[a]},subscribe:function(a,b){a=(a||"").toString();if(!a)throw new TypeError("Channel not defined");s[a]||(s[a]=[]);s[a].push(b)},publish:function(a,b){a=(a||"").toString();
+if(!a)throw new TypeError("Channel not defined");c.__jstorage_meta||(c.__jstorage_meta={});c.__jstorage_meta.PubSub||(c.__jstorage_meta.PubSub=[]);c.__jstorage_meta.PubSub.unshift([+new Date,a,b]);v();u()},reInit:function(){D()}};a:{var w=!1;if("localStorage"in window)try{window.localStorage.setItem("_tmptest","tmpval"),w=!0,window.localStorage.removeItem("_tmptest")}catch(I){}if(w)try{window.localStorage&&(k=window.localStorage,l="localStorage",q=k.jStorage_update)}catch(J){}else if("globalStorage"in
+window)try{window.globalStorage&&(k=window.globalStorage[window.location.hostname],l="globalStorage",q=k.jStorage_update)}catch(K){}else if(i=document.createElement("link"),i.addBehavior){i.style.behavior="url(#default#userData)";document.getElementsByTagName("head")[0].appendChild(i);try{i.load("jStorage")}catch(L){i.setAttribute("jStorage","{}"),i.save("jStorage"),i.load("jStorage")}w="{}";try{w=i.getAttribute("jStorage")}catch(M){}try{q=i.getAttribute("jStorage_update")}catch(N){}k.jStorage=w;
+l="userDataBehavior"}else{i=null;break a}E();y();x("local");x("session");"localStorage"==l||"globalStorage"==l?"addEventListener"in window?window.addEventListener("storage",t,!1):document.attachEvent("onstorage",t):"userDataBehavior"==l&&setInterval(t,1E3);F();"addEventListener"in window&&window.addEventListener("pageshow",function(a){a.persisted&&t()},!1)}})();
View
16 test.html
@@ -105,22 +105,6 @@
$("val").value = payload;
});
</script>
- <script>
- setTimeout(function(){
- alert(localStorage.a);
- localStorage.a = Number(localStorage.a || 124) + 1;
- localStorage.setItem("b", Number(localStorage.b || 324) + 1);
- alert(localStorage.getItem("b"));
-
- if(localStorage.a > 130){
- localStorage.clear();
- }
-
- if(localStorage.b > 326){
- localStorage.removeItem("b");
- }
- }, 300);
- </script>
</head>
<body>
View
BIN  tests/ajax-loader.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
10 tests/data.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<rss version="0.91">
+ <channel>
+ <title>Pealkiri</title>
+ <link>Lingi nimi</link>
+ <description>Kirjeldus</description>
+ <language>et</language>
+ </channel>
+</rss>
View
30 tests/test10_run.html
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+ function runTest(){
+
+ parent.sessionStorage.removeItem("jStorage");
+ parent.sessionStorage.removeItem("jStorage_update");
+
+ if(parent.sessionStorage.length != 3){
+ alert(parent.sessionStorage.length)
+ return false;
+ }
+ parent.sessionStorage.setItem("keyname3", "mull");
+ parent.sessionStorage.setItem("keyname4", "mull");
+ if(parent.sessionStorage.length != 4){
+ return false;
+ }
+ parent.sessionStorage.removeItem("keyname3");
+ return parent.sessionStorage.length == 3;
+ }
+ parent.testReady(runTest());
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
17 tests/test10_setup.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+ parent.sessionStorage.keyname1 = "myrdo";
+ parent.sessionStorage.setItem("keyname1", "mull");
+ parent.sessionStorage.setItem("keyname2", "mull");
+ parent.sessionStorage.setItem("keyname3", "mull");
+ parent.setupReady();
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
40 tests/test11_run.html
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+ function runTest(){
+
+ var keys = {
+ keyname1: true,
+ keyname2: true,
+ keyname3: true},
+ existing = {};
+
+ parent.sessionStorage.removeItem("jStorage");
+ parent.sessionStorage.removeItem("jStorage_update");
+
+ for(var i=0; i<parent.sessionStorage.length; i++){
+
+ if(!keys[parent.sessionStorage.key(i)]){
+ return false;
+ }
+
+ existing[parent.sessionStorage.key(i)] = true;
+ }
+
+ for(var i in keys){
+ if(keys.hasOwnProperty(i) && !existing[i]){
+ return false;
+ }
+ }
+ return true;
+ }
+ parent.testReady(runTest());
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
16 tests/test11_setup.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+ parent.sessionStorage.setItem("keyname2", "mull");
+ parent.sessionStorage.setItem("keyname3", "mull");
+ parent.sessionStorage.setItem("keyname1", "mull");
+ parent.setupReady();
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
22 tests/test12_run.html
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+ function runTest(){
+
+ parent.sessionStorage.clear();
+
+ parent.sessionStorage.removeItem("jStorage");
+ parent.sessionStorage.removeItem("jStorage_update");
+
+ return !parent.sessionStorage.length && !parent.sessionStorage.keyname1;
+ }
+ parent.testReady(runTest());
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
16 tests/test12_setup.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+ parent.sessionStorage.setItem("keyname2", "mull");
+ parent.sessionStorage.setItem("keyname3", "mull");
+ parent.sessionStorage.setItem("keyname1", "mull");
+ parent.setupReady();
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
30 tests/test13_run.html
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+
+ function runTest(){
+ if(typeof $.jStorage.get("jskey_str") != "string" || $.jStorage.get("jskey_str") !== "stringval"){
+ return false;
+ }
+ if(typeof $.jStorage.get("jskey_num") != "number" || $.jStorage.get("jskey_num") !== 12345){
+ return false;
+ }
+ if(typeof $.jStorage.get("jskey_bool") != "boolean" || $.jStorage.get("jskey_bool") !== false){
+ return false;
+ }
+ if(typeof $.jStorage.get("jskey_obj") != "object" || $.jStorage.get("jskey_obj").test !== 123){
+ return false;
+ }
+
+ return true;
+ }
+ parent.testReady(runTest());
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
19 tests/test13_setup.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+ $.jStorage.set("jskey_str", "stringval");
+ $.jStorage.set("jskey_num", 12345);
+ $.jStorage.set("jskey_bool", false);
+ $.jStorage.set("jskey_obj", {test: 123});
+
+ parent.setupReady();
+
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
26 tests/test14_run.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+
+ function runTest(){
+
+ try{
+ if($.jStorage.get("jskey_xml").getElementsByTagName("title")[0].firstChild.nodeValue != "Pealkiri"){
+ return false;
+ }
+ }catch(E){
+ return false;
+ }
+
+ return true;
+ }
+ parent.testReady(runTest());
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
29 tests/test14_setup.html
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+ var xmlhttp;
+
+ if (window.XMLHttpRequest){
+ xmlhttp = new XMLHttpRequest();
+ }else{
+ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
+ }
+
+ xmlhttp.onreadystatechange=function(){
+ if(xmlhttp.readyState==4 && xmlhttp.status==200){
+ $.jStorage.set("jskey_xml", xmlhttp.responseXML);
+ parent.setupReady();
+ }
+ }
+ xmlhttp.open("GET","data.xml",true);
+ xmlhttp.send();
+
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
28 tests/test15_run.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+
+ function runTest(){
+
+ if($.jStorage.get("ttlkey") != "ttlval"){
+
+ parent.testReady(false);
+ }
+
+ var interval = setInterval(function(){
+ if(!$.jStorage.get("ttlkey")){
+ clearInterval(interval);
+ parent.testReady(true);
+ }
+ }, 100)
+ }
+ runTest()
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
14 tests/test15_setup.html
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+ $.jStorage.set("ttlkey", "ttlval", {TTL: 1500});
+ parent.setupReady();
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
28 tests/test16_run.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+
+ function runTest(){
+
+ if($.jStorage.get("ttlkey") != "ttlval"){
+
+ parent.testReady(false);
+ }
+
+ var interval = setInterval(function(){
+ if(!$.jStorage.get("ttlkey")){
+ clearInterval(interval);
+ parent.testReady(true);
+ }
+ }, 100)
+ }
+ runTest()
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
15 tests/test16_setup.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+ $.jStorage.set("ttlkey", "ttlval");
+ $.jStorage.setTTL("ttlkey", 1500);
+ parent.setupReady();
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
36 tests/test17_run.html
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+
+ function runTest(){
+
+ if($.jStorage.get("delkey") != "delval"){
+ return false;
+ }
+
+ if($.jStorage.get("nodelkey") != "nodelval"){
+ return false;
+ }
+
+ $.jStorage.deleteKey("delkey");
+
+ if($.jStorage.get("delkey")){
+ return false;
+ }
+
+ if($.jStorage.get("nodelkey") != "nodelval"){
+ return false;
+ }
+
+ return true;
+ }
+ parent.testReady(runTest());
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
15 tests/test17_setup.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+ $.jStorage.set("delkey", "delval");
+ $.jStorage.set("nodelkey", "nodelval");
+ parent.setupReady();
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
44 tests/test18_run.html
@@ -0,0 +1,44 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+
+ function runTest(){
+
+ if($.jStorage.get("delkey") != "delval"){
+ return false;
+ }
+
+ if($.jStorage.get("nodelkey") != "nodelval"){
+ return false;
+ }
+
+ if($.jStorage.index().length != 2){
+ return false;
+ }
+
+ $.jStorage.flush();
+
+ if($.jStorage.get("delkey")){
+ return false;
+ }
+
+ if($.jStorage.get("nodelkey")){
+ return false;
+ }
+
+ if($.jStorage.index().length){
+ return false;
+ }
+
+ return true;
+ }
+ parent.testReady(runTest());
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
15 tests/test18_setup.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+ $.jStorage.set("delkey", "delval");
+ $.jStorage.set("nodelkey", "nodelval");
+ parent.setupReady();
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
19 tests/test19_frame1.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+
+ function go(){
+ $.jStorage.set("test", "pest");
+ $.jStorage.set("test", "vest");
+ }
+
+ parent.iframeReady(1, window);
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
26 tests/test19_frame2.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+ var done = false;
+ $.jStorage.listenKeyChange("test", function(key){
+ if(done)return;
+
+ if($.jStorage.get("test") == "pest"){
+ parent.listenReady(false);
+ done = true
+ }else if($.jStorage.get("test") == "vest"){
+ parent.listenReady(true);
+ done = true;
+ }
+ });
+
+ parent.iframeReady(2, window);
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
37 tests/test19_run.html
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+
+ var iframe1 = document.createElement("iframe");
+ iframe1.src = "test19_frame1.html";
+
+ var iframe2 = document.createElement("iframe");
+ iframe2.src = "test19_frame2.html";
+
+ var ready = {};
+
+ function iframeReady(nr, win){
+ ready["iframe"+nr] = win;
+
+ if(ready.iframe1 && ready.iframe2){
+ ready.iframe1.go();
+ }
+ }
+
+ function listenReady(success){
+ parent.testReady(!!success);
+ }
+
+ </script>
+</head>
+<body>
+
+<script>
+ document.body.appendChild(iframe1);
+ document.body.appendChild(iframe2);
+</script>
+</body>
+</html>
View
13 tests/test19_setup.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+ parent.setupReady();
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
13 tests/test1_run.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+ parent.testReady(localStorage.keyname == "myrdo");
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
14 tests/test1_setup.html
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+ localStorage.keyname = "myrdo";
+ parent.setupReady();
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
19 tests/test20_frame1.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+
+ function go(){
+ $.jStorage.publish("test", "pest1");
+ $.jStorage.publish("test", "pest2");
+ }
+
+ parent.iframeReady(1, window);
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
27 tests/test20_frame2.html
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+
+ var received = {}, done = false;
+
+ $.jStorage.subscribe("test", function(channel, payload){
+ if(done)return;
+
+ received[payload] = true;
+
+ if(received["pest1"] && received["pest2"]){
+ done = true;
+ parent.listenReady(true);
+ }
+ });
+
+ parent.iframeReady(2, window);
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
40 tests/test20_run.html
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+
+ var iframe1 = document.createElement("iframe");
+ iframe1.src = "test20_frame1.html";
+
+ var iframe2 = document.createElement("iframe");
+ iframe2.src = "test20_frame2.html";
+
+ var ready = {};
+
+ function iframeReady(nr, win){
+ ready["iframe"+nr] = win;
+
+ if(ready.iframe1 && ready.iframe2){
+ ready.iframe1.go();
+ }
+ }
+
+
+ function listenReady(success){
+
+ parent.testReady(!!success);
+
+ }
+
+ </script>
+</head>
+<body>
+
+<script>
+ document.body.appendChild(iframe1);
+ document.body.appendChild(iframe2);
+</script>
+</body>
+</html>
View
13 tests/test20_setup.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+ parent.setupReady();
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
13 tests/test2_run.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+ parent.testReady(localStorage.getItem("keyname") == "myrdo");
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
14 tests/test2_setup.html
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+ localStorage.setItem("keyname", "myrdo");
+ parent.setupReady();
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
18 tests/test3_run.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+ if(!localStorage.keyname){
+ parent.testReady(false);
+ }else{
+ localStorage.removeItem("keyname")
+ parent.testReady(!localStorage.keyname);
+ }
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
14 tests/test3_setup.html
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+ localStorage.keyname = "myrdo";
+ parent.setupReady();
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
30 tests/test4_run.html
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+ function runTest(){
+
+ localStorage.removeItem("jStorage");
+ localStorage.removeItem("jStorage_update");
+
+ if(localStorage.length != 3){
+ alert(localStorage.length)
+ return false;
+ }
+ localStorage.setItem("keyname3", "mull");
+ localStorage.setItem("keyname4", "mull");
+ if(localStorage.length != 4){
+ return false;
+ }
+ localStorage.removeItem("keyname3");
+ return localStorage.length == 3;
+ }
+ parent.testReady(runTest());
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
17 tests/test4_setup.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+ localStorage.keyname1 = "myrdo";
+ localStorage.setItem("keyname1", "mull");
+ localStorage.setItem("keyname2", "mull");
+ localStorage.setItem("keyname3", "mull");
+ parent.setupReady();
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
40 tests/test5_run.html
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+ function runTest(){
+
+ var keys = {
+ keyname1: true,
+ keyname2: true,
+ keyname3: true},
+ existing = {};
+
+ localStorage.removeItem("jStorage");
+ localStorage.removeItem("jStorage_update");
+
+ for(var i=0; i<localStorage.length; i++){
+
+ if(!keys[localStorage.key(i)]){
+ return false;
+ }
+
+ existing[localStorage.key(i)] = true;
+ }
+
+ for(var i in keys){
+ if(keys.hasOwnProperty(i) && !existing[i]){
+ return false;
+ }
+ }
+ return true;
+ }
+ parent.testReady(runTest());
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
16 tests/test5_setup.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+ localStorage.setItem("keyname2", "mull");
+ localStorage.setItem("keyname3", "mull");
+ localStorage.setItem("keyname1", "mull");
+ parent.setupReady();
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
22 tests/test6_run.html
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+ function runTest(){
+
+ localStorage.clear();
+
+ localStorage.removeItem("jStorage");
+ localStorage.removeItem("jStorage_update");
+
+ return !localStorage.length && !localStorage.keyname1;
+ }
+ parent.testReady(runTest());
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
16 tests/test6_setup.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+ localStorage.setItem("keyname2", "mull");
+ localStorage.setItem("keyname3", "mull");
+ localStorage.setItem("keyname1", "mull");
+ parent.setupReady();
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
13 tests/test7_run.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+ parent.testReady(parent.sessionStorage.keyname == "myrdo");
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
14 tests/test7_setup.html
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+ parent.sessionStorage.keyname = "myrdo";
+ parent.setupReady();
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
13 tests/test8_run.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+ parent.testReady(parent.sessionStorage.getItem("keyname") == "myrdo");
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
14 tests/test8_setup.html
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+ parent.sessionStorage.setItem("keyname", "myrdo");
+ parent.setupReady();
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
18 tests/test9_run.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+ if(!parent.sessionStorage.keyname){
+ parent.testReady(false);
+ }else{
+ parent.sessionStorage.removeItem("keyname")
+ parent.testReady(!parent.sessionStorage.keyname);
+ }
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
14 tests/test9_setup.html
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+ parent.sessionStorage.keyname = "myrdo";
+ parent.setupReady();
+ </script>
+</head>
+<body>
+
+</body>
+</html>
View
205 tests/testrunner.html
@@ -0,0 +1,205 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <style type="text/css">
+ body{
+ font-family: Helvetica, Sans-serif;
+ font-size: 13px;
+ }
+ .red{
+ background: red;
+ color: white;
+ }
+ .green{
+ background: green;
+ color: white;
+ }
+ .yellow{
+ background: yellow url(ajax-loader.gif) no-repeat 3px center;
+ }
+
+ .black{
+ background: black;
+ color: white;
+ }
+
+ ul{
+ padding:0;
+ list-style: none;
+ margin: 10 0;
+ }
+
+ li{
+ padding: 5px 25px;
+ margin: 0 0 1px 0;
+ }
+ </style>
+ <script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
+ <script src="../jstorage.js"></script>
+ <script>
+ var tests = [
+ {
+ id: "test1",
+ name: "localStorage polyfill getter/setter"
+ },
+ {
+ id: "test2",
+ name: "localStorage polyfill setItem/getItem"
+ },
+ {
+ id: "test3",
+ name: "localStorage polyfill removeItem"
+ },
+ {
+ id: "test4",
+ name: "localStorage polyfill length"
+ },
+ {
+ id: "test5",
+ name: "localStorage polyfill key(n)"
+ },
+ {
+ id: "test6",
+ name: "localStorage polyfill clear"
+ },
+ {
+ id: "test7",
+ name: "sessionStorage polyfill getter/setter"
+ },
+ {
+ id: "test8",
+ name: "sessionStorage polyfill setItem/getItem"
+ },
+ {
+ id: "test9",
+ name: "sessionStorage polyfill removeItem"
+ },
+ {
+ id: "test10",
+ name: "sessionStorage polyfill length"
+ },
+ {
+ id: "test11",
+ name: "sessionStorage polyfill key(n)"
+ },
+ {
+ id: "test12",
+ name: "sessionStorage polyfill clear"
+ },
+ {
+ id: "test13",
+ name: "jStorage set/get JSON types"
+ },
+ {
+ id: "test14",
+ name: "jStorage set/get XML"
+ },
+ {
+ id: "test15",
+ name: "jStorage set with TTL option"
+ },
+ {
+ id: "test16",
+ name: "jStorage setTTL"
+ },
+ {
+ id: "test17",
+ name: "jStorage delete key"
+ },
+ {
+ id: "test18",
+ name: "jStorage flush/index"
+ },
+ {
+ id: "test19",
+ name: "jStorage listenKeyChange"
+ },
+ {
+ id: "test20",
+ name: "jStorage publish/subscribe"
+ }
+ ],
+ test,
+ succeeded = 0,
+ failed = 0;
+
+
+ function runTests(){
+ $.jStorage.flush();
+ localStorage.clear();
+ sessionStorage.clear();
+
+ if(!tests.length){
+ alert("All tests ready, "+succeeded + " succeeded, "+failed+ " failed");
+ return;
+ }
+
+ test = tests.shift();
+ if(!test){
+ return runTests();
+ }
+
+ test.li = document.createElement("li");
+ test.li.innerHTML = test.name+ " running";
+ test.li.className = "yellow";
+ document.getElementById("results").appendChild(test.li);
+
+ createIframe(test.id+"_setup.html");
+ test.timeout = setTimeout(testFail, 4000);
+ };
+
+ function createIframe(url){
+ test.iframe = document.createElement("iframe");
+ test.iframe.style.position = "absolute";
+ test.iframe.style.left = "-1000px";
+ test.iframe.style.top = "-1000px";
+ test.iframe.src = url;
+ document.body.appendChild(test.iframe);
+
+ }
+
+ function testFail(){
+ clearTimeout(test.timeout);
+ if(test && test.iframe){
+ test.iframe.parentNode.removeChild(test.iframe);
+ test.li.className = "black";
+ test.li.innerHTML = test.name+" timeout";
+ }
+ failed++;
+
+ runTests();
+ }
+
+ function setupReady(){
+ clearTimeout(test.timeout);
+ test.timeout = setTimeout(testFail, 4000);
+ test.iframe.parentNode.removeChild(test.iframe);
+ createIframe(test.id+"_run.html");
+ }
+
+ function testReady(success){
+ clearTimeout(test.timeout);
+
+ test.iframe.parentNode.removeChild(test.iframe);
+ test.li.className = success ? "green" : "red";
+
+ if(success){
+ test.li.innerHTML = test.name+" succeeded";
+ succeeded++;
+ }else{
+ test.li.innerHTML = test.name+" failed";
+ failed++;
+ }
+
+ runTests();
+ }
+
+ </script>
+</head>
+<body>
+ <h1>jStorage tests</h1>
+ <ul id="results"></ul>
+
+ <script>runTests();</script>
+</body>
+</html>
Please sign in to comment.
Something went wrong with that request. Please try again.