4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-util-Cookies'>/**
19 </span> * @class Ext.util.Cookies
21 Utility class for setting/reading values from browser cookies.
22 Values can be written using the {@link #set} method.
23 Values can be read using the {@link #get} method.
24 A cookie can be invalidated on the client machine using the {@link #clear} method.
29 Ext.define('Ext.util.Cookies', {
32 <span id='Ext-util-Cookies-method-set'> /**
33 </span> * Create a cookie with the specified name and value. Additional settings
34 * for the cookie may be optionally specified (for example: expiration,
35 * access restriction, SSL).
36 * @param {String} name The name of the cookie to set.
37 * @param {Mixed} value The value to set for the cookie.
38 * @param {Object} expires (Optional) Specify an expiration date the
39 * cookie is to persist until. Note that the specified Date object will
40 * be converted to Greenwich Mean Time (GMT).
41 * @param {String} path (Optional) Setting a path on the cookie restricts
42 * access to pages that match that path. Defaults to all pages (<tt>'/'</tt>).
43 * @param {String} domain (Optional) Setting a domain restricts access to
44 * pages on a given domain (typically used to allow cookie access across
45 * subdomains). For example, "sencha.com" will create a cookie that can be
46 * accessed from any subdomain of sencha.com, including www.sencha.com,
47 * support.sencha.com, etc.
48 * @param {Boolean} secure (Optional) Specify true to indicate that the cookie
49 * should only be accessible via SSL on a page using the HTTPS protocol.
50 * Defaults to <tt>false</tt>. Note that this will only work if the page
51 * calling this code uses the HTTPS protocol, otherwise the cookie will be
52 * created with default options.
54 set : function(name, value){
56 argc = arguments.length,
57 expires = (argc > 2) ? argv[2] : null,
58 path = (argc > 3) ? argv[3] : '/',
59 domain = (argc > 4) ? argv[4] : null,
60 secure = (argc > 5) ? argv[5] : false;
62 document.cookie = name + "=" + escape(value) + ((expires === null) ? "" : ("; expires=" + expires.toGMTString())) + ((path === null) ? "" : ("; path=" + path)) + ((domain === null) ? "" : ("; domain=" + domain)) + ((secure === true) ? "; secure" : "");
65 <span id='Ext-util-Cookies-method-get'> /**
66 </span> * Retrieves cookies that are accessible by the current page. If a cookie
67 * does not exist, <code>get()</code> returns <tt>null</tt>. The following
68 * example retrieves the cookie called "valid" and stores the String value
69 * in the variable <tt>validStatus</tt>.
70 * <pre><code>
71 * var validStatus = Ext.util.Cookies.get("valid");
72 * </code></pre>
73 * @param {String} name The name of the cookie to get
74 * @return {Mixed} Returns the cookie value for the specified name;
75 * null if the cookie name does not exist.
78 var arg = name + "=",
80 clen = document.cookie.length,
86 if(document.cookie.substring(i, j) == arg){
87 return this.getCookieVal(j);
89 i = document.cookie.indexOf(" ", i) + 1;
97 <span id='Ext-util-Cookies-method-clear'> /**
98 </span> * Removes a cookie with the provided name from the browser
99 * if found by setting its expiration date to sometime in the past.
100 * @param {String} name The name of the cookie to remove
101 * @param {String} path (optional) The path for the cookie. This must be included if you included a path while setting the cookie.
103 clear : function(name, path){
106 document.cookie = name + '=' + '; expires=Thu, 01-Jan-70 00:00:01 GMT; path=' + path;
110 <span id='Ext-util-Cookies-method-getCookieVal'> /**
113 getCookieVal : function(offset){
114 var endstr = document.cookie.indexOf(";", offset);
116 endstr = document.cookie.length;
118 return unescape(document.cookie.substring(offset, endstr));