4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js">Ext.define('Ext.state.LocalStorageProvider', {
19 /* Begin Definitions */
21 extend: 'Ext.state.Provider',
23 alias: 'state.localstorage',
27 constructor: function(){
29 me.callParent(arguments);
30 me.store = me.getStorageObject();
31 me.state = me.readLocalStorage();
34 readLocalStorage: function(){
35 var store = this.store,
39 prefixLen = prefix.length,
43 for (; i < len; ++i) {
45 if (key.substring(0, prefixLen) == prefix) {
46 data[key.substr(prefixLen)] = this.decodeValue(store.getItem(key));
52 set : function(name, value){
56 if (typeof value == "undefined" || value === null) {
59 me.store.setItem(me.prefix + name, me.encodeValue(value));
60 me.callParent(arguments);
64 clear : function(name){
65 this.store.removeItem(this.prefix + name);
66 this.callParent(arguments);
69 getStorageObject: function(){
71 var supports = 'localStorage' in window && window['localStorage'] !== null;
73 return window.localStorage;
79 Ext.Error.raise('LocalStorage is not supported by the current browser');