julien-maurel / jQuery-Storage-API

This plugin is no longer maintained! A new one, without dependencies with jQuery, is available : https://github.com/julien-maurel/js-storage
308 stars 83 forks source link

Use CookieStorage fallback correctly #8

Closed Wonno closed 10 years ago

Wonno commented 10 years ago

In case of Cookie-Fallback: If there is no window.localStorage available then you cannot override window.sessionStorage or window.localStorage

julien-maurel commented 10 years ago

Sorry but your commit change all indentation and all lines are marked as modified, so I can't check your changes...

Wonno commented 10 years ago

use "git diif -w ...." for ignoring Whitespaces and you will get:

diff --git a/jquery.storageapi.js b/jquery.storageapi.js
index 9402db4..8a5ec5c 100644
--- a/jquery.storageapi.js
+++ b/jquery.storageapi.js
@@ -377,8 +377,8 @@
             }
         };
         if(!window.localStorage){
-      window.localStorage=$.extend({},cookie_storage,{_prefix:cookie_local_prefix,_expires:365*10});
-      window.sessionStorage=$.extend({},cookie_storage,{_prefix:cookie_session_prefix+window.name+'_'});
+            window.localCookieStorage=$.extend({},cookie_storage,{_prefix:cookie_local_prefix,_expires:365*10});
+            window.sessionCookieStorage=$.extend({},cookie_storage,{_prefix:cookie_session_prefix+window.name+'_'});
         }
         window.cookieStorage=$.extend({},cookie_storage);
         // cookieStorage API
@@ -394,10 +394,17 @@

     // Get a new API on a namespace
     $.initNamespaceStorage=function(ns){return _createNamespace(ns);};
+    if (window.localStorage) {
         // localStorage API
         $.localStorage=$.extend({},storage,{_type:'localStorage'});
         // sessionStorage API
         $.sessionStorage=$.extend({},storage,{_type:'sessionStorage'});
+    }else{
+        // localStorage API
+        $.localStorage=$.extend({},storage,{_type:'localCookieStorage'});
+        // sessionStorage API
+        $.sessionStorage=$.extend({},storage,{_type:'sessionCookieStorage'});
+    }
     // List of all namespace storage
     $.namespaceStorages={};
     // Remove all items in all storages
julien-maurel commented 10 years ago

Ok, I'm agree with you. So I did a new version with your changes. Thanks