3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\r
4 <title>The source code</title>
\r
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
8 <body onload="prettyPrint();">
\r
9 <pre class="prettyprint lang-js"><div id="cls-Ext.state.Provider"></div>/**
10 * @class Ext.state.Provider
11 * Abstract base class for state provider implementations. This class provides methods
12 * for encoding and decoding <b>typed</b> variables including dates and defines the
15 Ext.state.Provider = function(){
16 <div id="event-Ext.state.Provider-statechange"></div>/**
18 * Fires when a state change occurs.
19 * @param {Provider} this This state provider
20 * @param {String} key The state key which was changed
21 * @param {String} value The encoded value for the state
23 this.addEvents("statechange");
25 Ext.state.Provider.superclass.constructor.call(this);
27 Ext.extend(Ext.state.Provider, Ext.util.Observable, {
28 <div id="method-Ext.state.Provider-get"></div>/**
29 * Returns the current value for a key
30 * @param {String} name The key name
31 * @param {Mixed} defaultValue A default value to return if the key's value is not found
32 * @return {Mixed} The state data
34 get : function(name, defaultValue){
35 return typeof this.state[name] == "undefined" ?
36 defaultValue : this.state[name];
39 <div id="method-Ext.state.Provider-clear"></div>/**
40 * Clears a value from the state
41 * @param {String} name The key name
43 clear : function(name){
44 delete this.state[name];
45 this.fireEvent("statechange", this, name, null);
48 <div id="method-Ext.state.Provider-set"></div>/**
49 * Sets the value for a key
50 * @param {String} name The key name
51 * @param {Mixed} value The value to set
53 set : function(name, value){
54 this.state[name] = value;
55 this.fireEvent("statechange", this, name, value);
58 <div id="method-Ext.state.Provider-decodeValue"></div>/**
59 * Decodes a string previously encoded with {@link #encodeValue}.
60 * @param {String} value The value to decode
61 * @return {Mixed} The decoded value
63 decodeValue : function(cookie){
64 var re = /^(a|n|d|b|s|o)\:(.*)$/;
65 var matches = re.exec(unescape(cookie));
66 if(!matches || !matches[1]) return; // non state cookie
67 var type = matches[1];
73 return new Date(Date.parse(v));
79 Ext.each(v.split('^'), function(val){
80 all.push(this.decodeValue(val));
87 Ext.each(v.split('^'), function(val){
88 var kv = val.split('=');
89 all[kv[0]] = this.decodeValue(kv[1]);
98 <div id="method-Ext.state.Provider-encodeValue"></div>/**
99 * Encodes a value including type information. Decode with {@link #decodeValue}.
100 * @param {Mixed} value The value to encode
101 * @return {String} The encoded value
103 encodeValue : function(v){
105 if(typeof v == "number"){
107 }else if(typeof v == "boolean"){
108 enc = "b:" + (v ? "1" : "0");
109 }else if(Ext.isDate(v)){
110 enc = "d:" + v.toGMTString();
111 }else if(Ext.isArray(v)){
113 for(var i = 0, len = v.length; i < len; i++){
114 flat += this.encodeValue(v[i]);
115 if(i != len-1) flat += "^";
118 }else if(typeof v == "object"){
121 if(typeof v[key] != "function" && v[key] !== undefined){
122 flat += key + "=" + this.encodeValue(v[key]) + "^";
125 enc = "o:" + flat.substring(0, flat.length-1);