// -- Sammy.js -- /plugins/sammy.storage.js // http://sammyjs.org // Version: 0.7.6 // Built: 2014-08-26 10:45:34 +0300 (function(factory){if(typeof define==="function"&&define.amd){define(["jquery","sammy"],factory)}else{(window.Sammy=window.Sammy||{}).Storage=factory(window.jQuery,window.Sammy)}})(function($,Sammy){Sammy.Store=function(options){var store=this;this.options=options||{};this.name=this.options.name||"store";this.element=this.options.element||"body";this.$element=$(this.element);if($.isArray(this.options.type)){$.each(this.options.type,function(i,type){if(Sammy.Store.isAvailable(type)){store.type=type;return false}})}else{this.type=this.options.type||"memory"}this.meta_key=this.options.meta_key||"__keys__";this.storage=new Sammy.Store[Sammy.Store.stores[this.type]](this.name,this.element,this.options)};Sammy.Store.stores={memory:"Memory",data:"Data",local:"LocalStorage",session:"SessionStorage",cookie:"Cookie"};$.extend(Sammy.Store.prototype,{isAvailable:function(){if($.isFunction(this.storage.isAvailable)){return this.storage.isAvailable()}else{return true}},exists:function(key){return this.storage.exists(key)},set:function(key,value){var string_value=typeof value=="string"?value:JSON.stringify(value);key=key.toString();this.storage.set(key,string_value);if(key!=this.meta_key){this._addKey(key);this.$element.trigger("set-"+this.name,{key:key,value:value});this.$element.trigger("set-"+this.name+"-"+key,{key:key,value:value})}return value},get:function(key){var value=this.storage.get(key);if(typeof value=="undefined"||value==null||value==""){return value}try{return JSON.parse(value)}catch(e){return value}},clear:function(key){this._removeKey(key);return this.storage.clear(key)},clearAll:function(){var self=this;this.each(function(key,value){self.clear(key)})},keys:function(){return this.get(this.meta_key)||[]},each:function(callback){var i=0,keys=this.keys(),returned;for(i;i