3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.3.1
11 * Copyright(c) 2006-2010 Sencha Inc.
12 * licensing@sencha.com
13 * http://www.sencha.com/license
15 <div id="cls-Ext.state.Provider"></div>/**
16 * @class Ext.state.Provider
17 * Abstract base class for state provider implementations. This class provides methods
18 * for encoding and decoding <b>typed</b> variables including dates and defines the
21 Ext.state.Provider = Ext.extend(Ext.util.Observable, {
23 constructor : function(){
24 <div id="event-Ext.state.Provider-statechange"></div>/**
26 * Fires when a state change occurs.
27 * @param {Provider} this This state provider
28 * @param {String} key The state key which was changed
29 * @param {String} value The encoded value for the state
31 this.addEvents("statechange");
33 Ext.state.Provider.superclass.constructor.call(this);
36 <div id="method-Ext.state.Provider-get"></div>/**
37 * Returns the current value for a key
38 * @param {String} name The key name
39 * @param {Mixed} defaultValue A default value to return if the key's value is not found
40 * @return {Mixed} The state data
42 get : function(name, defaultValue){
43 return typeof this.state[name] == "undefined" ?
44 defaultValue : this.state[name];
47 <div id="method-Ext.state.Provider-clear"></div>/**
48 * Clears a value from the state
49 * @param {String} name The key name
51 clear : function(name){
52 delete this.state[name];
53 this.fireEvent("statechange", this, name, null);
56 <div id="method-Ext.state.Provider-set"></div>/**
57 * Sets the value for a key
58 * @param {String} name The key name
59 * @param {Mixed} value The value to set
61 set : function(name, value){
62 this.state[name] = value;
63 this.fireEvent("statechange", this, name, value);
66 <div id="method-Ext.state.Provider-decodeValue"></div>/**
67 * Decodes a string previously encoded with {@link #encodeValue}.
68 * @param {String} value The value to decode
69 * @return {Mixed} The decoded value
71 decodeValue : function(cookie){
72 <div id="prop-Ext.state.Provider-var"></div>/**
81 var re = /^(a|n|d|b|s|o|e)\:(.*)$/,
82 matches = re.exec(unescape(cookie)),
87 if(!matches || !matches[1]){
88 return; // non state cookie
98 return new Date(Date.parse(v));
104 Ext.each(v.split('^'), function(val){
105 all.push(this.decodeValue(val));
112 Ext.each(v.split('^'), function(val){
114 all[kv[0]] = this.decodeValue(kv[1]);
123 <div id="method-Ext.state.Provider-encodeValue"></div>/**
124 * Encodes a value including type information. Decode with {@link #decodeValue}.
125 * @param {Mixed} value The value to encode
126 * @return {String} The encoded value
128 encodeValue : function(v){
136 }else if(typeof v == 'number'){
138 }else if(typeof v == 'boolean'){
139 enc = 'b:' + (v ? '1' : '0');
140 }else if(Ext.isDate(v)){
141 enc = 'd:' + v.toGMTString();
142 }else if(Ext.isArray(v)){
143 for(len = v.length; i < len; i++){
144 flat += this.encodeValue(v[i]);
150 }else if(typeof v == 'object'){
152 if(typeof v[key] != 'function' && v[key] !== undefined){
153 flat += key + '=' + this.encodeValue(v[key]) + '^';
156 enc = 'o:' + flat.substring(0, flat.length-1);