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-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'>/**
2 </span></span></span></span></span></span> * @class Ext.state.CookieProvider
3 * @extends Ext.state.Provider
4 * A Provider implementation which saves and retrieves state via cookies.
5 * The CookieProvider supports the usual cookie options, such as:
7 * <li>{@link #path}</li>
8 * <li>{@link #expires}</li>
9 * <li>{@link #domain}</li>
10 * <li>{@link #secure}</li>
12 <pre><code>
13 var cp = new Ext.state.CookieProvider({
14 path: "/cgi-bin/",
15 expires: new Date(new Date().getTime()+(1000*60*60*24*30)), //30 days
16 domain: "sencha.com"
18 Ext.state.Manager.setProvider(cp);
19 </code></pre>
22 * @cfg {String} path The path for which the cookie is active (defaults to root '/' which makes it active for all pages in the site)
23 * @cfg {Date} expires The cookie expiration date (defaults to 7 days from now)
24 * @cfg {String} domain The domain to save the cookie for. Note that you cannot specify a different domain than
25 * your page is on, but you can specify a sub-domain, or simply the domain itself like 'sencha.com' to include
26 * all sub-domains if you need to access cookies across different sub-domains (defaults to null which uses the same
27 * domain the page is running on including the 'www' like 'www.sencha.com')
28 * @cfg {Boolean} secure True if the site is using SSL (defaults to false)
30 * Create a new CookieProvider
31 * @param {Object} config The configuration object
33 Ext.define('Ext.state.CookieProvider', {
34 extend: 'Ext.state.Provider',
36 constructor : function(config){
38 me.path = "/";
39 me.expires = new Date(new Date().getTime()+(1000*60*60*24*7)); //7 days
42 me.callParent(arguments);
43 me.state = me.readCookies();
47 set : function(name, value){
50 if(typeof value == "undefined" || value === null){
54 me.setCookie(name, value);
55 me.callParent(arguments);
59 clear : function(name){
60 this.clearCookie(name);
61 this.callParent(arguments);
65 readCookies : function(){
67 c = document.cookie + ";",
68 re = /\s?(.*?)=(.*?);/g,
75 while((matches = re.exec(c)) != null){
78 if (name && name.substring(0, len) == prefix){
79 cookies[name.substr(len)] = this.decodeValue(value);
86 setCookie : function(name, value){
89 document.cookie = me.prefix + name + "=" + me.encodeValue(value) +
90 ((me.expires == null) ? "" : ("; expires=" + me.expires.toGMTString())) +
91 ((me.path == null) ? "" : ("; path=" + me.path)) +
92 ((me.domain == null) ? "" : ("; domain=" + me.domain)) +
93 ((me.secure == true) ? "; secure" : "");
97 clearCookie : function(name){
100 document.cookie = me.prefix + name + "=null; expires=Thu, 01-Jan-70 00:00:01 GMT" +
101 ((me.path == null) ? "" : ("; path=" + me.path)) +
102 ((me.domain == null) ? "" : ("; domain=" + me.domain)) +
103 ((me.secure == true) ? "; secure" : "");
106 </pre></pre></body></html>