Created
August 17, 2012 09:58
-
-
Save bagwanpankaj/3377611 to your computer and use it in GitHub Desktop.
Simplified HTML5 JS storage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.storage = { | |
local: window.localStorage, // storage to be used | |
set: function( key, value ){ | |
this.local.setItem( key, JSON.stringify( value ) ); | |
$( document ).trigger( 'storage', ['set', key, value] ); | |
}, | |
get: function( key ){ | |
return JSON.parse( this.local.getItem( key ) ); | |
}, | |
key: function( index ){ | |
return this.local.key( index ); | |
}, | |
remove: function( key ){ | |
this.local.removeItem( key ); | |
$( document ).trigger( 'storage', ['remove', key] ); | |
}, | |
clear: function(){ | |
return this.local.clear(); | |
$( document ).trigger( 'storage', ['clear'] ); | |
}, | |
keys: function(){ | |
var res = []; | |
for( var i = 0; i < this.local.length; i++ ){ | |
res.push( this.local.key( i ) ); | |
}; | |
return res; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment