Sha256: 9aa251e91556475d1b27827cbb11a80182523ec47d55928b20ae48d92b97ea7b
Contents?: true
Size: 1.84 KB
Versions: 20
Compression:
Stored size: 1.84 KB
Contents
!function(t,e){function r(){return(0|65536*(1+Math.random())).toString(16).substring(1)}function o(){return r()+r()+"-"+r()+"-"+r()+"-"+r()+"-"+r()+r()+r()}e.LocalStorage=window.Store=function(t){this.name=t;var e=this.localStorage().getItem(this.name);this.records=e&&e.split(",")||[]},t.extend(e.LocalStorage.prototype,{save:function(){this.localStorage().setItem(this.name,this.records.join(","))},create:function(t){return t.id||(t.id=o(),t.set(t.idAttribute,t.id)),this.localStorage().setItem(this.name+"-"+t.id,JSON.stringify(t)),this.records.push(t.id.toString()),this.save(),t.toJSON()},update:function(e){return this.localStorage().setItem(this.name+"-"+e.id,JSON.stringify(e)),t.include(this.records,e.id.toString())||this.records.push(e.id.toString()),this.save(),e.toJSON()},find:function(t){return JSON.parse(this.localStorage().getItem(this.name+"-"+t.id))},findAll:function(){return t(this.records).chain().map(function(t){return JSON.parse(this.localStorage().getItem(this.name+"-"+t))},this).compact().value()},destroy:function(e){return this.localStorage().removeItem(this.name+"-"+e.id),this.records=t.reject(this.records,function(t){return t==e.id.toString()}),this.save(),e},localStorage:function(){return localStorage}}),e.LocalStorage.sync=window.Store.sync=e.localSync=function(t,e,r){var o,n=e.localStorage||e.collection.localStorage,i=$.Deferred&&$.Deferred();switch(t){case"read":o=void 0!=e.id?n.find(e):n.findAll();break;case"create":o=n.create(e);break;case"update":o=n.update(e);break;case"delete":o=n.destroy(e)}return o?(r&&r.success&&r.success(o),i&&i.resolve()):(r&&r.error&&r.error("Record not found"),i&&i.reject()),i&&i.promise()},e.ajaxSync=e.sync,e.getSyncMethod=function(t){return t.localStorage||t.collection&&t.collection.localStorage?e.localSync:e.ajaxSync},e.sync=function(t,r,o){return e.getSyncMethod(r).apply(this,[t,r,o])}}(_,Backbone);
Version data entries
20 entries across 20 versions & 1 rubygems