You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 lines
5.5 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-state-Provider'>/**
  19. </span> * @class Ext.state.Provider
  20. * Abstract base class for state provider implementations. This class provides methods
  21. * for encoding and decoding &lt;b&gt;typed&lt;/b&gt; variables including dates and defines the
  22. * Provider interface.
  23. */
  24. Ext.state.Provider = Ext.extend(Ext.util.Observable, {
  25. <span id='Ext-state-Provider-method-constructor'> constructor : function(){
  26. </span><span id='Ext-state-Provider-event-statechange'> /**
  27. </span> * @event statechange
  28. * Fires when a state change occurs.
  29. * @param {Provider} this This state provider
  30. * @param {String} key The state key which was changed
  31. * @param {String} value The encoded value for the state
  32. */
  33. this.addEvents(&quot;statechange&quot;);
  34. this.state = {};
  35. Ext.state.Provider.superclass.constructor.call(this);
  36. },
  37. <span id='Ext-state-Provider-method-get'> /**
  38. </span> * Returns the current value for a key
  39. * @param {String} name The key name
  40. * @param {Mixed} defaultValue A default value to return if the key's value is not found
  41. * @return {Mixed} The state data
  42. */
  43. get : function(name, defaultValue){
  44. return typeof this.state[name] == &quot;undefined&quot; ?
  45. defaultValue : this.state[name];
  46. },
  47. <span id='Ext-state-Provider-method-clear'> /**
  48. </span> * Clears a value from the state
  49. * @param {String} name The key name
  50. */
  51. clear : function(name){
  52. delete this.state[name];
  53. this.fireEvent(&quot;statechange&quot;, this, name, null);
  54. },
  55. <span id='Ext-state-Provider-method-set'> /**
  56. </span> * Sets the value for a key
  57. * @param {String} name The key name
  58. * @param {Mixed} value The value to set
  59. */
  60. set : function(name, value){
  61. this.state[name] = value;
  62. this.fireEvent(&quot;statechange&quot;, this, name, value);
  63. },
  64. <span id='Ext-state-Provider-method-decodeValue'> /**
  65. </span> * Decodes a string previously encoded with {@link #encodeValue}.
  66. * @param {String} value The value to decode
  67. * @return {Mixed} The decoded value
  68. */
  69. decodeValue : function(cookie){
  70. <span id='Ext-state-Provider-property-re'> /**
  71. </span> * a -&gt; Array
  72. * n -&gt; Number
  73. * d -&gt; Date
  74. * b -&gt; Boolean
  75. * s -&gt; String
  76. * o -&gt; Object
  77. * -&gt; Empty (null)
  78. */
  79. var re = /^(a|n|d|b|s|o|e)\:(.*)$/,
  80. matches = re.exec(unescape(cookie)),
  81. all,
  82. type,
  83. v,
  84. kv;
  85. if(!matches || !matches[1]){
  86. return; // non state cookie
  87. }
  88. type = matches[1];
  89. v = matches[2];
  90. switch(type){
  91. case 'e':
  92. return null;
  93. case 'n':
  94. return parseFloat(v);
  95. case 'd':
  96. return new Date(Date.parse(v));
  97. case 'b':
  98. return (v == '1');
  99. case 'a':
  100. all = [];
  101. if(v != ''){
  102. Ext.each(v.split('^'), function(val){
  103. all.push(this.decodeValue(val));
  104. }, this);
  105. }
  106. return all;
  107. case 'o':
  108. all = {};
  109. if(v != ''){
  110. Ext.each(v.split('^'), function(val){
  111. kv = val.split('=');
  112. all[kv[0]] = this.decodeValue(kv[1]);
  113. }, this);
  114. }
  115. return all;
  116. default:
  117. return v;
  118. }
  119. },
  120. <span id='Ext-state-Provider-method-encodeValue'> /**
  121. </span> * Encodes a value including type information. Decode with {@link #decodeValue}.
  122. * @param {Mixed} value The value to encode
  123. * @return {String} The encoded value
  124. */
  125. encodeValue : function(v){
  126. var enc,
  127. flat = '',
  128. i = 0,
  129. len,
  130. key;
  131. if(v == null){
  132. return 'e:1';
  133. }else if(typeof v == 'number'){
  134. enc = 'n:' + v;
  135. }else if(typeof v == 'boolean'){
  136. enc = 'b:' + (v ? '1' : '0');
  137. }else if(Ext.isDate(v)){
  138. enc = 'd:' + v.toGMTString();
  139. }else if(Ext.isArray(v)){
  140. for(len = v.length; i &lt; len; i++){
  141. flat += this.encodeValue(v[i]);
  142. if(i != len - 1){
  143. flat += '^';
  144. }
  145. }
  146. enc = 'a:' + flat;
  147. }else if(typeof v == 'object'){
  148. for(key in v){
  149. if(typeof v[key] != 'function' &amp;&amp; v[key] !== undefined){
  150. flat += key + '=' + this.encodeValue(v[key]) + '^';
  151. }
  152. }
  153. enc = 'o:' + flat.substring(0, flat.length-1);
  154. }else{
  155. enc = 's:' + v;
  156. }
  157. return escape(enc);
  158. }
  159. });
  160. </pre>
  161. </body>
  162. </html>