1 Ext.define('Ext.state.LocalStorageProvider', {
2 /* Begin Definitions */
4 extend: 'Ext.state.Provider',
6 alias: 'state.localstorage',
10 constructor: function(){
12 me.callParent(arguments);
13 me.store = me.getStorageObject();
14 me.state = me.readLocalStorage();
17 readLocalStorage: function(){
18 var store = this.store,
22 prefixLen = prefix.length,
26 for (; i < len; ++i) {
28 if (key.substring(0, prefixLen) == prefix) {
29 data[key.substr(prefixLen)] = this.decodeValue(store.getItem(key));
35 set : function(name, value){
39 if (typeof value == "undefined" || value === null) {
42 me.store.setItem(me.prefix + name, me.encodeValue(value));
43 me.callParent(arguments);
47 clear : function(name){
48 this.store.removeItem(this.prefix + name);
49 this.callParent(arguments);
52 getStorageObject: function(){
54 var supports = 'localStorage' in window && window['localStorage'] !== null;
56 return window.localStorage;
62 Ext.Error.raise('LocalStorage is not supported by the current browser');