3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js"><div id="cls-Ext.state.Provider"></div>/**
9 * @class Ext.state.Provider
10 * Abstract base class for state provider implementations. This class provides methods
11 * for encoding and decoding <b>typed</b> variables including dates and defines the
14 Ext.state.Provider = function(){
15 <div id="event-Ext.state.Provider-statechange"></div>/**
17 * Fires when a state change occurs.
18 * @param {Provider} this This state provider
19 * @param {String} key The state key which was changed
20 * @param {String} value The encoded value for the state
22 this.addEvents("statechange");
24 Ext.state.Provider.superclass.constructor.call(this);
26 Ext.extend(Ext.state.Provider, Ext.util.Observable, {
27 <div id="method-Ext.state.Provider-get"></div>/**
28 * Returns the current value for a key
29 * @param {String} name The key name
30 * @param {Mixed} defaultValue A default value to return if the key's value is not found
31 * @return {Mixed} The state data
33 get : function(name, defaultValue){
34 return typeof this.state[name] == "undefined" ?
35 defaultValue : this.state[name];
38 <div id="method-Ext.state.Provider-clear"></div>/**
39 * Clears a value from the state
40 * @param {String} name The key name
42 clear : function(name){
43 delete this.state[name];
44 this.fireEvent("statechange", this, name, null);
47 <div id="method-Ext.state.Provider-set"></div>/**
48 * Sets the value for a key
49 * @param {String} name The key name
50 * @param {Mixed} value The value to set
52 set : function(name, value){
53 this.state[name] = value;
54 this.fireEvent("statechange", this, name, value);
57 <div id="method-Ext.state.Provider-decodeValue"></div>/**
58 * Decodes a string previously encoded with {@link #encodeValue}.
59 * @param {String} value The value to decode
60 * @return {Mixed} The decoded value
62 decodeValue : function(cookie){
63 var re = /^(a|n|d|b|s|o)\:(.*)$/;
64 var matches = re.exec(unescape(cookie));
65 if(!matches || !matches[1]) return; // non state cookie
66 var type = matches[1];
72 return new Date(Date.parse(v));
77 var values = v.split("^");
78 for(var i = 0, len = values.length; i < len; i++){
79 all.push(this.decodeValue(values[i]));
84 var values = v.split("^");
85 for(var i = 0, len = values.length; i < len; i++){
86 var kv = values[i].split("=");
87 all[kv[0]] = this.decodeValue(kv[1]);
95 <div id="method-Ext.state.Provider-encodeValue"></div>/**
96 * Encodes a value including type information. Decode with {@link #decodeValue}.
97 * @param {Mixed} value The value to encode
98 * @return {String} The encoded value
100 encodeValue : function(v){
102 if(typeof v == "number"){
104 }else if(typeof v == "boolean"){
105 enc = "b:" + (v ? "1" : "0");
106 }else if(Ext.isDate(v)){
107 enc = "d:" + v.toGMTString();
108 }else if(Ext.isArray(v)){
110 for(var i = 0, len = v.length; i < len; i++){
111 flat += this.encodeValue(v[i]);
112 if(i != len-1) flat += "^";
115 }else if(typeof v == "object"){
118 if(typeof v[key] != "function" && v[key] !== undefined){
119 flat += key + "=" + this.encodeValue(v[key]) + "^";
122 enc = "o:" + flat.substring(0, flat.length-1);