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.2.1
11 * Copyright(c) 2006-2010 Ext JS, Inc.
13 * http://www.extjs.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 = function(){
22 <div id="event-Ext.state.Provider-statechange"></div>/**
24 * Fires when a state change occurs.
25 * @param {Provider} this This state provider
26 * @param {String} key The state key which was changed
27 * @param {String} value The encoded value for the state
29 this.addEvents("statechange");
31 Ext.state.Provider.superclass.constructor.call(this);
33 Ext.extend(Ext.state.Provider, Ext.util.Observable, {
34 <div id="method-Ext.state.Provider-get"></div>/**
35 * Returns the current value for a key
36 * @param {String} name The key name
37 * @param {Mixed} defaultValue A default value to return if the key's value is not found
38 * @return {Mixed} The state data
40 get : function(name, defaultValue){
41 return typeof this.state[name] == "undefined" ?
42 defaultValue : this.state[name];
45 <div id="method-Ext.state.Provider-clear"></div>/**
46 * Clears a value from the state
47 * @param {String} name The key name
49 clear : function(name){
50 delete this.state[name];
51 this.fireEvent("statechange", this, name, null);
54 <div id="method-Ext.state.Provider-set"></div>/**
55 * Sets the value for a key
56 * @param {String} name The key name
57 * @param {Mixed} value The value to set
59 set : function(name, value){
60 this.state[name] = value;
61 this.fireEvent("statechange", this, name, value);
64 <div id="method-Ext.state.Provider-decodeValue"></div>/**
65 * Decodes a string previously encoded with {@link #encodeValue}.
66 * @param {String} value The value to decode
67 * @return {Mixed} The decoded value
69 decodeValue : function(cookie){
70 var re = /^(a|n|d|b|s|o)\:(.*)$/;
71 var matches = re.exec(unescape(cookie));
72 if(!matches || !matches[1]) return; // non state cookie
73 var type = matches[1];
79 return new Date(Date.parse(v));
85 Ext.each(v.split('^'), function(val){
86 all.push(this.decodeValue(val));
93 Ext.each(v.split('^'), function(val){
94 var kv = val.split('=');
95 all[kv[0]] = this.decodeValue(kv[1]);
104 <div id="method-Ext.state.Provider-encodeValue"></div>/**
105 * Encodes a value including type information. Decode with {@link #decodeValue}.
106 * @param {Mixed} value The value to encode
107 * @return {String} The encoded value
109 encodeValue : function(v){
111 if(typeof v == "number"){
113 }else if(typeof v == "boolean"){
114 enc = "b:" + (v ? "1" : "0");
115 }else if(Ext.isDate(v)){
116 enc = "d:" + v.toGMTString();
117 }else if(Ext.isArray(v)){
119 for(var i = 0, len = v.length; i < len; i++){
120 flat += this.encodeValue(v[i]);
121 if(i != len-1) flat += "^";
124 }else if(typeof v == "object"){
127 if(typeof v[key] != "function" && v[key] !== undefined){
128 flat += key + "=" + this.encodeValue(v[key]) + "^";
131 enc = "o:" + flat.substring(0, flat.length-1);