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.

109 lines
4.9 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-util-Cookies'>/**
  19. </span> * @class Ext.util.Cookies
  20. * Utility class for managing and interacting with cookies.
  21. * @singleton
  22. */
  23. Ext.util.Cookies = {
  24. <span id='Ext-util-Cookies-method-set'> /**
  25. </span> * Create a cookie with the specified name and value. Additional settings
  26. * for the cookie may be optionally specified (for example: expiration,
  27. * access restriction, SSL).
  28. * @param {String} name The name of the cookie to set.
  29. * @param {Mixed} value The value to set for the cookie.
  30. * @param {Object} expires (Optional) Specify an expiration date the
  31. * cookie is to persist until. Note that the specified Date object will
  32. * be converted to Greenwich Mean Time (GMT).
  33. * @param {String} path (Optional) Setting a path on the cookie restricts
  34. * access to pages that match that path. Defaults to all pages (&lt;tt&gt;'/'&lt;/tt&gt;).
  35. * @param {String} domain (Optional) Setting a domain restricts access to
  36. * pages on a given domain (typically used to allow cookie access across
  37. * subdomains). For example, &quot;extjs.com&quot; will create a cookie that can be
  38. * accessed from any subdomain of extjs.com, including www.extjs.com,
  39. * support.extjs.com, etc.
  40. * @param {Boolean} secure (Optional) Specify true to indicate that the cookie
  41. * should only be accessible via SSL on a page using the HTTPS protocol.
  42. * Defaults to &lt;tt&gt;false&lt;/tt&gt;. Note that this will only work if the page
  43. * calling this code uses the HTTPS protocol, otherwise the cookie will be
  44. * created with default options.
  45. */
  46. set : function(name, value){
  47. var argv = arguments;
  48. var argc = arguments.length;
  49. var expires = (argc &gt; 2) ? argv[2] : null;
  50. var path = (argc &gt; 3) ? argv[3] : '/';
  51. var domain = (argc &gt; 4) ? argv[4] : null;
  52. var secure = (argc &gt; 5) ? argv[5] : false;
  53. document.cookie = name + &quot;=&quot; + escape(value) + ((expires === null) ? &quot;&quot; : (&quot;; expires=&quot; + expires.toGMTString())) + ((path === null) ? &quot;&quot; : (&quot;; path=&quot; + path)) + ((domain === null) ? &quot;&quot; : (&quot;; domain=&quot; + domain)) + ((secure === true) ? &quot;; secure&quot; : &quot;&quot;);
  54. },
  55. <span id='Ext-util-Cookies-method-get'> /**
  56. </span> * Retrieves cookies that are accessible by the current page. If a cookie
  57. * does not exist, &lt;code&gt;get()&lt;/code&gt; returns &lt;tt&gt;null&lt;/tt&gt;. The following
  58. * example retrieves the cookie called &quot;valid&quot; and stores the String value
  59. * in the variable &lt;tt&gt;validStatus&lt;/tt&gt;.
  60. * &lt;pre&gt;&lt;code&gt;
  61. * var validStatus = Ext.util.Cookies.get(&quot;valid&quot;);
  62. * &lt;/code&gt;&lt;/pre&gt;
  63. * @param {String} name The name of the cookie to get
  64. * @return {Mixed} Returns the cookie value for the specified name;
  65. * null if the cookie name does not exist.
  66. */
  67. get : function(name){
  68. var arg = name + &quot;=&quot;;
  69. var alen = arg.length;
  70. var clen = document.cookie.length;
  71. var i = 0;
  72. var j = 0;
  73. while(i &lt; clen){
  74. j = i + alen;
  75. if(document.cookie.substring(i, j) == arg){
  76. return Ext.util.Cookies.getCookieVal(j);
  77. }
  78. i = document.cookie.indexOf(&quot; &quot;, i) + 1;
  79. if(i === 0){
  80. break;
  81. }
  82. }
  83. return null;
  84. },
  85. <span id='Ext-util-Cookies-method-clear'> /**
  86. </span> * Removes a cookie with the provided name from the browser
  87. * if found by setting its expiration date to sometime in the past.
  88. * @param {String} name The name of the cookie to remove
  89. */
  90. clear : function(name){
  91. if(Ext.util.Cookies.get(name)){
  92. document.cookie = name + &quot;=&quot; + &quot;; expires=Thu, 01-Jan-70 00:00:01 GMT&quot;;
  93. }
  94. },
  95. <span id='Ext-util-Cookies-method-getCookieVal'> /**
  96. </span> * @private
  97. */
  98. getCookieVal : function(offset){
  99. var endstr = document.cookie.indexOf(&quot;;&quot;, offset);
  100. if(endstr == -1){
  101. endstr = document.cookie.length;
  102. }
  103. return unescape(document.cookie.substring(offset, endstr));
  104. }
  105. };</pre>
  106. </body>
  107. </html>