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-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'>/**
19 </span></span></span></span></span> * @class Ext.state.CookieProvider
20 * @extends Ext.state.Provider
21 * A Provider implementation which saves and retrieves state via cookies.
22 * The CookieProvider supports the usual cookie options, such as:
24 * <li>{@link #path}</li>
25 * <li>{@link #expires}</li>
26 * <li>{@link #domain}</li>
27 * <li>{@link #secure}</li>
29 <pre><code>
30 var cp = new Ext.state.CookieProvider({
31 path: "/cgi-bin/",
32 expires: new Date(new Date().getTime()+(1000*60*60*24*30)), //30 days
33 domain: "sencha.com"
35 Ext.state.Manager.setProvider(cp);
36 </code></pre>
39 * @cfg {String} path The path for which the cookie is active (defaults to root '/' which makes it active for all pages in the site)
40 * @cfg {Date} expires The cookie expiration date (defaults to 7 days from now)
41 * @cfg {String} domain The domain to save the cookie for. Note that you cannot specify a different domain than
42 * your page is on, but you can specify a sub-domain, or simply the domain itself like 'sencha.com' to include
43 * all sub-domains if you need to access cookies across different sub-domains (defaults to null which uses the same
44 * domain the page is running on including the 'www' like 'www.sencha.com')
45 * @cfg {Boolean} secure True if the site is using SSL (defaults to false)
47 Ext.define('Ext.state.CookieProvider', {
48 extend: 'Ext.state.Provider',
50 <span id='Ext-state-CookieProvider-method-constructor'> /**
51 </span> * Creates a new CookieProvider.
52 * @param {Object} config (optional) Config object.
54 constructor : function(config){
56 me.path = "/";
57 me.expires = new Date(new Date().getTime()+(1000*60*60*24*7)); //7 days
60 me.callParent(arguments);
61 me.state = me.readCookies();
65 set : function(name, value){
68 if(typeof value == "undefined" || value === null){
72 me.setCookie(name, value);
73 me.callParent(arguments);
77 clear : function(name){
78 this.clearCookie(name);
79 this.callParent(arguments);
83 readCookies : function(){
85 c = document.cookie + ";",
86 re = /\s?(.*?)=(.*?);/g,
93 while((matches = re.exec(c)) != null){
96 if (name && name.substring(0, len) == prefix){
97 cookies[name.substr(len)] = this.decodeValue(value);
104 setCookie : function(name, value){
107 document.cookie = me.prefix + name + "=" + me.encodeValue(value) +
108 ((me.expires == null) ? "" : ("; expires=" + me.expires.toGMTString())) +
109 ((me.path == null) ? "" : ("; path=" + me.path)) +
110 ((me.domain == null) ? "" : ("; domain=" + me.domain)) +
111 ((me.secure == true) ? "; secure" : "");
115 clearCookie : function(name){
118 document.cookie = me.prefix + name + "=null; expires=Thu, 01-Jan-70 00:00:01 GMT" +
119 ((me.path == null) ? "" : ("; path=" + me.path)) +
120 ((me.domain == null) ? "" : ("; domain=" + me.domain)) +
121 ((me.secure == true) ? "; secure" : "");