/* * TotalStorage * * Copyright (c) 2012 Jared Novack & Upstatement (upstatement.com) * Dual licensed under the MIT and GPL licenses: * https://www.opensource.org/licenses/mit-license.php * https://www.gnu.org/licenses/gpl.html * * 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.2 * @url https://upstatement.com/blog/2012/01/jquery-local-storage-done-right-and-easy/ */ (function($){var ls=window.localStorage;var supported;if(typeof ls=='undefined'||typeof window.JSON=='undefined'){supported=false;}else{supported=true;} $.totalStorage=function(key,value,options){return $.totalStorage.impl.init(key,value);} $.totalStorage.setItem=function(key,value){return $.totalStorage.impl.setItem(key,value);} $.totalStorage.getItem=function(key){return $.totalStorage.impl.getItem(key);} $.totalStorage.getAll=function(){return $.totalStorage.impl.getAll();} $.totalStorage.deleteItem=function(key){return $.totalStorage.impl.deleteItem(key);} $.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;}} return this.parseResult(ls.getItem(key));},deleteItem:function(key){if(!supported){try{$.cookie(key,null);return true;}catch(e){return false;}} ls.removeItem(key);return true;},getAll:function(){var items=new Array();if(!supported){try{var pairs=document.cookie.split(";");for(var i=0;i