+++ /dev/null
-/*\r
- * Ext JS Library 2.2.1\r
- * Copyright(c) 2006-2009, Ext JS, LLC.\r
- * licensing@extjs.com\r
- * \r
- * http://extjs.com/license\r
- */\r
-\r
-/**\r
- * @class Ext.state.Provider\r
- * Abstract base class for state provider implementations. This class provides methods\r
- * for encoding and decoding <b>typed</b> variables including dates and defines the \r
- * Provider interface.\r
- */\r
-Ext.state.Provider = function(){\r
- /**\r
- * @event statechange\r
- * Fires when a state change occurs.\r
- * @param {Provider} this This state provider\r
- * @param {String} key The state key which was changed\r
- * @param {String} value The encoded value for the state\r
- */\r
- this.addEvents("statechange");\r
- this.state = {};\r
- Ext.state.Provider.superclass.constructor.call(this);\r
-};\r
-Ext.extend(Ext.state.Provider, Ext.util.Observable, {\r
- /**\r
- * Returns the current value for a key\r
- * @param {String} name The key name\r
- * @param {Mixed} defaultValue A default value to return if the key's value is not found\r
- * @return {Mixed} The state data\r
- */\r
- get : function(name, defaultValue){\r
- return typeof this.state[name] == "undefined" ?\r
- defaultValue : this.state[name];\r
- },\r
- \r
- /**\r
- * Clears a value from the state\r
- * @param {String} name The key name\r
- */\r
- clear : function(name){\r
- delete this.state[name];\r
- this.fireEvent("statechange", this, name, null);\r
- },\r
- \r
- /**\r
- * Sets the value for a key\r
- * @param {String} name The key name\r
- * @param {Mixed} value The value to set\r
- */\r
- set : function(name, value){\r
- this.state[name] = value;\r
- this.fireEvent("statechange", this, name, value);\r
- },\r
- \r
- /**\r
- * Decodes a string previously encoded with {@link #encodeValue}.\r
- * @param {String} value The value to decode\r
- * @return {Mixed} The decoded value\r
- */\r
- decodeValue : function(cookie){\r
- var re = /^(a|n|d|b|s|o)\:(.*)$/;\r
- var matches = re.exec(unescape(cookie));\r
- if(!matches || !matches[1]) return; // non state cookie\r
- var type = matches[1];\r
- var v = matches[2];\r
- switch(type){\r
- case "n":\r
- return parseFloat(v);\r
- case "d":\r
- return new Date(Date.parse(v));\r
- case "b":\r
- return (v == "1");\r
- case "a":\r
- var all = [];\r
- var values = v.split("^");\r
- for(var i = 0, len = values.length; i < len; i++){\r
- all.push(this.decodeValue(values[i]));\r
- }\r
- return all;\r
- case "o":\r
- var all = {};\r
- var values = v.split("^");\r
- for(var i = 0, len = values.length; i < len; i++){\r
- var kv = values[i].split("=");\r
- all[kv[0]] = this.decodeValue(kv[1]);\r
- }\r
- return all;\r
- default:\r
- return v;\r
- }\r
- },\r
- \r
- /**\r
- * Encodes a value including type information. Decode with {@link #decodeValue}.\r
- * @param {Mixed} value The value to encode\r
- * @return {String} The encoded value\r
- */\r
- encodeValue : function(v){\r
- var enc;\r
- if(typeof v == "number"){\r
- enc = "n:" + v;\r
- }else if(typeof v == "boolean"){\r
- enc = "b:" + (v ? "1" : "0");\r
- }else if(Ext.isDate(v)){\r
- enc = "d:" + v.toGMTString();\r
- }else if(Ext.isArray(v)){\r
- var flat = "";\r
- for(var i = 0, len = v.length; i < len; i++){\r
- flat += this.encodeValue(v[i]);\r
- if(i != len-1) flat += "^";\r
- }\r
- enc = "a:" + flat;\r
- }else if(typeof v == "object"){\r
- var flat = "";\r
- for(var key in v){\r
- if(typeof v[key] != "function" && v[key] !== undefined){\r
- flat += key + "=" + this.encodeValue(v[key]) + "^";\r
- }\r
- }\r
- enc = "o:" + flat.substring(0, flat.length-1);\r
- }else{\r
- enc = "s:" + v;\r
- }\r
- return escape(enc); \r
- }\r
-});\r