diff --git a/README.md b/README.md index b08b40a..c55662d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,3 @@ -![image](http://upstatement.com/wp-content/uploads/2012/01/jquery-total-storage1.png) Dead-Simple local storage for every browser and device ## What makes it TOTAL Storage? @@ -41,4 +40,4 @@ Last year my firm worked on a project to help seniors calculate their savings, s ### Many thanks to: Andris Reinman and Klaus Hartl. Their plugins (jStorage and Cookie, respectively) provided the roadmap to make this. Also feedback and comments from users have been most helpful in making this more efficient and killing some bugs. -[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/jarednova/jquery-total-storage/trend.png)](https://bitdeli.com/free "Bitdeli Badge") + diff --git a/bower.json b/bower.json index 5217d28..2c51fe3 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "jquery-total-storage", - "version": "1.0.0", + "version": "1.1.3", "description": "Local storage for every browser", "license": "MIT", "ignore": [ diff --git a/jquery.total-storage.js b/jquery.total-storage.js index 478eed1..8255530 100644 --- a/jquery.total-storage.js +++ b/jquery.total-storage.js @@ -8,6 +8,12 @@ * * Total Storage is the conceptual the love child of jStorage by Andris Reinman, * and Cookie by Klaus Hartl -- though this is not connected to either project. + * + * @name $.totalStorage + * @cat Plugins/Cookie + * @author Jared Novack/jared@upstatement.com + * @version 1.1.3 + * @url http://upstatement.com/blog/2012/01/jquery-local-storage-done-right-and-easy/ */ /** @@ -34,149 +40,143 @@ $.totalStorage('people', myArray); //to return: $.totalStorage('people'); - * - * @name $.totalStorage - * @cat Plugins/Cookie - * @author Jared Novack/jared@upstatement.com - * @version 1.1.2 - * @url http://upstatement.com/blog/2012/01/jquery-local-storage-done-right-and-easy/ */ -;(function($, undefined){ - - /* Variables I'll need throghout */ - - var supported, ls, mod = 'test'; - if ('localStorage' in window){ - try { - ls = (typeof window.localStorage === 'undefined') ? undefined : window.localStorage; - if (typeof ls == 'undefined' || typeof window.JSON == 'undefined'){ - supported = false; - } else { - supported = true; - } - - window.localStorage.setItem(mod, '1'); - window.localStorage.removeItem(mod); - } - catch (err){ - supported = false; - } - } +;(function ($, undefined) { + + /* Variables I'll need throughout */ + + var supported, ls, mod = 'test'; + if ('localStorage' in window) { + try { + ls = (typeof window.localStorage === 'undefined') ? undefined : window.localStorage; + if (typeof ls == 'undefined' || typeof window.JSON == 'undefined') { + supported = false; + } else { + supported = true; + } + + window.localStorage.setItem(mod, '1'); + window.localStorage.removeItem(mod); + } + catch (err) { + supported = false; + } + } /* Make the methods public */ - $.totalStorage = function(key, value, options){ - return $.totalStorage.impl.init(key, value); - }; + $.totalStorage = function (key, value, options) { + return $.totalStorage.impl.init(key, value, options); + }; - $.totalStorage.setItem = function(key, value){ - return $.totalStorage.impl.setItem(key, value); - }; + $.totalStorage.setItem = function (key, value, options) { + return $.totalStorage.impl.setItem(key, value, options); + }; - $.totalStorage.getItem = function(key){ - return $.totalStorage.impl.getItem(key); - }; + $.totalStorage.getItem = function (key) { + return $.totalStorage.impl.getItem(key); + }; - $.totalStorage.getAll = function(){ - return $.totalStorage.impl.getAll(); - }; + $.totalStorage.getAll = function () { + return $.totalStorage.impl.getAll(); + }; - $.totalStorage.deleteItem = function(key){ - return $.totalStorage.impl.deleteItem(key); - }; + $.totalStorage.deleteItem = function (key) { + return $.totalStorage.impl.deleteItem(key); + }; /* Object to hold all methods: public and private */ - $.totalStorage.impl = { - - init: function(key, value){ - if (typeof value != 'undefined') { - return this.setItem(key, value); - } else { - return this.getItem(key); - } - }, - - setItem: function(key, value){ - if (!supported){ - try { - $.cookie(key, value); - return value; - } catch(e){ - console.log('Local Storage not supported by this browser. Install the cookie plugin on your site to take advantage of the same functionality. You can get it at https://github.com/carhartl/jquery-cookie'); - } - } - var saver = JSON.stringify(value); - ls.setItem(key, saver); - return this.parseResult(saver); - }, - getItem: function(key){ - if (!supported){ - try { - return this.parseResult($.cookie(key)); - } catch(e){ - return null; - } - } - var item = ls.getItem(key); - return this.parseResult(item); - }, - deleteItem: function(key){ - if (!supported){ - try { - $.cookie(key, null); - return true; - } catch(e){ - return false; - } - } - ls.removeItem(key); - return true; - }, - getAll: function(){ - var items = []; - if (!supported){ - try { - var pairs = document.cookie.split(";"); - for (var i = 0; i