4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/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"><span id='Ext-state-LocalStorageProvider'>/**
19 </span> * @class Ext.state.LocalStorageProvider
20 * @extends Ext.state.Provider
21 * A Provider implementation which saves and retrieves state via the HTML5 localStorage object.
22 * If the browser does not support local storage, an exception will be thrown upon instantiating
26 Ext.define('Ext.state.LocalStorageProvider', {
27 /* Begin Definitions */
29 extend: 'Ext.state.Provider',
31 alias: 'state.localstorage',
35 constructor: function(){
37 me.callParent(arguments);
38 me.store = me.getStorageObject();
39 me.state = me.readLocalStorage();
42 readLocalStorage: function(){
43 var store = this.store,
47 prefixLen = prefix.length,
51 for (; i < len; ++i) {
53 if (key.substring(0, prefixLen) == prefix) {
54 data[key.substr(prefixLen)] = this.decodeValue(store.getItem(key));
60 set : function(name, value){
64 if (typeof value == "undefined" || value === null) {
67 me.store.setItem(me.prefix + name, me.encodeValue(value));
68 me.callParent(arguments);
72 clear : function(name){
73 this.store.removeItem(this.prefix + name);
74 this.callParent(arguments);
77 getStorageObject: function(){
79 var supports = 'localStorage' in window && window['localStorage'] !== null;
81 return window.localStorage;
87 Ext.Error.raise('LocalStorage is not supported by the current browser');