]>
git.proxmox.com Git - pve-manager.git/blob - www/mobile/Cookies.js
2 * Utility class for setting/reading values from browser cookies.
3 * Values can be written using the {@link #set} method.
4 * Values can be read using the {@link #get} method.
5 * A cookie can be invalidated on the client machine using the {@link #clear} method.
7 Ext
.define('Ext.util.Cookies', {
11 * Creates a cookie with the specified name and value. Additional settings for the cookie may be optionally specified
12 * (for example: expiration, access restriction, SSL).
13 * @param {String} name The name of the cookie to set.
14 * @param {Object} value The value to set for the cookie.
15 * @param {Object} [expires] Specify an expiration date the cookie is to persist until. Note that the specified Date
16 * object will be converted to Greenwich Mean Time (GMT).
17 * @param {String} [path] Setting a path on the cookie restricts access to pages that match that path. Defaults to all
19 * @param {String} [domain] Setting a domain restricts access to pages on a given domain (typically used to allow
20 * cookie access across subdomains). For example, "sencha.com" will create a cookie that can be accessed from any
21 * subdomain of sencha.com, including www.sencha.com, support.sencha.com, etc.
22 * @param {Boolean} [secure] Specify true to indicate that the cookie should only be accessible via SSL on a page
23 * using the HTTPS protocol. Defaults to false. Note that this will only work if the page calling this code uses the
24 * HTTPS protocol, otherwise the cookie will be created with default options.
26 set : function(name
, value
){
28 argc
= arguments
.length
,
29 expires
= (argc
> 2) ? argv
[2] : null,
30 path
= (argc
> 3) ? argv
[3] : '/',
31 domain
= (argc
> 4) ? argv
[4] : null,
32 secure
= (argc
> 5) ? argv
[5] : false;
34 document
.cookie
= name
+ "=" +
36 ((expires
=== null) ? "" : ("; expires=" + expires
.toUTCString())) +
37 ((path
=== null) ? "" : ("; path=" + path
)) +
38 ((domain
=== null) ? "" : ("; domain=" + domain
)) +
39 ((secure
=== true) ? "; secure" : "");
43 * Retrieves cookies that are accessible by the current page. If a cookie does not exist, `get()` returns null. The
44 * following example retrieves the cookie called "valid" and stores the String value in the variable validStatus.
46 * var validStatus = Ext.util.Cookies.get("valid");
48 * @param {String} name The name of the cookie to get
49 * @return {Object} Returns the cookie value for the specified name;
50 * null if the cookie name does not exist.
52 get : function(name
) {
53 var parts
= document
.cookie
.split('; '),
57 // In modern browsers, a cookie with an empty string will be stored:
59 // In older versions of IE, it will be stored as:
61 // So here we iterate over all the parts in an attempt to match the key.
62 for (i
= 0; i
< len
; ++i
) {
63 item
= parts
[i
].split('=');
64 if (item
[0] === name
) {
66 return ret
? unescape(ret
) : '';
73 * Removes a cookie with the provided name from the browser
74 * if found by setting its expiration date to sometime in the past.
75 * @param {String} name The name of the cookie to remove
76 * @param {String} [path] The path for the cookie.
77 * This must be included if you included a path while setting the cookie.
79 clear : function(name
, path
){
82 document
.cookie
= name
+ '=' + '; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=' + path
;