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.

107 lines
4.8 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">
  19. <span id='Ext-state-CookieProvider-method-constructor'><span id='Ext-state-CookieProvider-cfg-secure'><span id='Ext-state-CookieProvider-cfg-domain'><span id='Ext-state-CookieProvider-cfg-expires'><span id='Ext-state-CookieProvider-cfg-path'><span id='Ext-state-CookieProvider'>/**
  20. </span></span></span></span></span></span> * @class Ext.state.CookieProvider
  21. * @extends Ext.state.Provider
  22. * The default Provider implementation which saves state via cookies.
  23. * &lt;br /&gt;Usage:
  24. &lt;pre&gt;&lt;code&gt;
  25. var cp = new Ext.state.CookieProvider({
  26. path: &quot;/cgi-bin/&quot;,
  27. expires: new Date(new Date().getTime()+(1000*60*60*24*30)), //30 days
  28. domain: &quot;extjs.com&quot;
  29. });
  30. Ext.state.Manager.setProvider(cp);
  31. &lt;/code&gt;&lt;/pre&gt;
  32. * @cfg {String} path The path for which the cookie is active (defaults to root '/' which makes it active for all pages in the site)
  33. * @cfg {Date} expires The cookie expiration date (defaults to 7 days from now)
  34. * @cfg {String} domain The domain to save the cookie for. Note that you cannot specify a different domain than
  35. * your page is on, but you can specify a sub-domain, or simply the domain itself like 'extjs.com' to include
  36. * all sub-domains if you need to access cookies across different sub-domains (defaults to null which uses the same
  37. * domain the page is running on including the 'www' like 'www.extjs.com')
  38. * @cfg {Boolean} secure True if the site is using SSL (defaults to false)
  39. * @constructor
  40. * Create a new CookieProvider
  41. * @param {Object} config The configuration object
  42. */
  43. Ext.state.CookieProvider = Ext.extend(Ext.state.Provider, {
  44. constructor : function(config){
  45. Ext.state.CookieProvider.superclass.constructor.call(this);
  46. this.path = &quot;/&quot;;
  47. this.expires = new Date(new Date().getTime()+(1000*60*60*24*7)); //7 days
  48. this.domain = null;
  49. this.secure = false;
  50. Ext.apply(this, config);
  51. this.state = this.readCookies();
  52. },
  53. <span id='Ext-state-CookieProvider-method-set'> // private
  54. </span> set : function(name, value){
  55. if(typeof value == &quot;undefined&quot; || value === null){
  56. this.clear(name);
  57. return;
  58. }
  59. this.setCookie(name, value);
  60. Ext.state.CookieProvider.superclass.set.call(this, name, value);
  61. },
  62. <span id='Ext-state-CookieProvider-method-clear'> // private
  63. </span> clear : function(name){
  64. this.clearCookie(name);
  65. Ext.state.CookieProvider.superclass.clear.call(this, name);
  66. },
  67. <span id='Ext-state-CookieProvider-method-readCookies'> // private
  68. </span> readCookies : function(){
  69. var cookies = {},
  70. c = document.cookie + &quot;;&quot;,
  71. re = /\s?(.*?)=(.*?);/g,
  72. matches,
  73. name,
  74. value;
  75. while((matches = re.exec(c)) != null){
  76. name = matches[1];
  77. value = matches[2];
  78. if(name &amp;&amp; name.substring(0,3) == &quot;ys-&quot;){
  79. cookies[name.substr(3)] = this.decodeValue(value);
  80. }
  81. }
  82. return cookies;
  83. },
  84. <span id='Ext-state-CookieProvider-method-setCookie'> // private
  85. </span> setCookie : function(name, value){
  86. document.cookie = &quot;ys-&quot;+ name + &quot;=&quot; + this.encodeValue(value) +
  87. ((this.expires == null) ? &quot;&quot; : (&quot;; expires=&quot; + this.expires.toGMTString())) +
  88. ((this.path == null) ? &quot;&quot; : (&quot;; path=&quot; + this.path)) +
  89. ((this.domain == null) ? &quot;&quot; : (&quot;; domain=&quot; + this.domain)) +
  90. ((this.secure == true) ? &quot;; secure&quot; : &quot;&quot;);
  91. },
  92. <span id='Ext-state-CookieProvider-method-clearCookie'> // private
  93. </span> clearCookie : function(name){
  94. document.cookie = &quot;ys-&quot; + name + &quot;=null; expires=Thu, 01-Jan-70 00:00:01 GMT&quot; +
  95. ((this.path == null) ? &quot;&quot; : (&quot;; path=&quot; + this.path)) +
  96. ((this.domain == null) ? &quot;&quot; : (&quot;; domain=&quot; + this.domain)) +
  97. ((this.secure == true) ? &quot;; secure&quot; : &quot;&quot;);
  98. }
  99. });</pre>
  100. </body>
  101. </html>