1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-util.Cookies'>/**
2 </span> * @class Ext.util.Cookies
4 Utility class for setting/reading values from browser cookies.
5 Values can be written using the {@link #set} method.
6 Values can be read using the {@link #get} method.
7 A cookie can be invalidated on the client machine using the {@link #clear} method.
12 Ext.define('Ext.util.Cookies', {
15 <span id='Ext-util.Cookies-method-set'> /**
16 </span> * Create a cookie with the specified name and value. Additional settings
17 * for the cookie may be optionally specified (for example: expiration,
18 * access restriction, SSL).
19 * @param {String} name The name of the cookie to set.
20 * @param {Mixed} value The value to set for the cookie.
21 * @param {Object} expires (Optional) Specify an expiration date the
22 * cookie is to persist until. Note that the specified Date object will
23 * be converted to Greenwich Mean Time (GMT).
24 * @param {String} path (Optional) Setting a path on the cookie restricts
25 * access to pages that match that path. Defaults to all pages (<tt>'/'</tt>).
26 * @param {String} domain (Optional) Setting a domain restricts access to
27 * pages on a given domain (typically used to allow cookie access across
28 * subdomains). For example, "sencha.com" will create a cookie that can be
29 * accessed from any subdomain of sencha.com, including www.sencha.com,
30 * support.sencha.com, etc.
31 * @param {Boolean} secure (Optional) Specify true to indicate that the cookie
32 * should only be accessible via SSL on a page using the HTTPS protocol.
33 * Defaults to <tt>false</tt>. Note that this will only work if the page
34 * calling this code uses the HTTPS protocol, otherwise the cookie will be
35 * created with default options.
37 set : function(name, value){
39 argc = arguments.length,
40 expires = (argc > 2) ? argv[2] : null,
41 path = (argc > 3) ? argv[3] : '/',
42 domain = (argc > 4) ? argv[4] : null,
43 secure = (argc > 5) ? argv[5] : false;
45 document.cookie = name + "=" + escape(value) + ((expires === null) ? "" : ("; expires=" + expires.toGMTString())) + ((path === null) ? "" : ("; path=" + path)) + ((domain === null) ? "" : ("; domain=" + domain)) + ((secure === true) ? "; secure" : "");
48 <span id='Ext-util.Cookies-method-get'> /**
49 </span> * Retrieves cookies that are accessible by the current page. If a cookie
50 * does not exist, <code>get()</code> returns <tt>null</tt>. The following
51 * example retrieves the cookie called "valid" and stores the String value
52 * in the variable <tt>validStatus</tt>.
53 * <pre><code>
54 * var validStatus = Ext.util.Cookies.get("valid");
55 * </code></pre>
56 * @param {String} name The name of the cookie to get
57 * @return {Mixed} Returns the cookie value for the specified name;
58 * null if the cookie name does not exist.
61 var arg = name + "=",
63 clen = document.cookie.length,
69 if(document.cookie.substring(i, j) == arg){
70 return this.getCookieVal(j);
72 i = document.cookie.indexOf(" ", i) + 1;
80 <span id='Ext-util.Cookies-method-clear'> /**
81 </span> * Removes a cookie with the provided name from the browser
82 * if found by setting its expiration date to sometime in the past.
83 * @param {String} name The name of the cookie to remove
84 * @param {String} path (optional) The path for the cookie. This must be included if you included a path while setting the cookie.
86 clear : function(name, path){
89 document.cookie = name + '=' + '; expires=Thu, 01-Jan-70 00:00:01 GMT; path=' + path;
93 <span id='Ext-util.Cookies-method-getCookieVal'> /**
96 getCookieVal : function(offset){
97 var endstr = document.cookie.indexOf(";", offset);
99 endstr = document.cookie.length;
101 return unescape(document.cookie.substring(offset, endstr));
104 </pre></pre></body></html>