4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/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-method-constructor'><span id='Ext-state-CookieProvider'>/**
19 </span></span> * A Provider implementation which saves and retrieves state via cookies. The CookieProvider supports the usual cookie
29 * Ext.create('Ext.state.CookieProvider', {
30 * path: "/cgi-bin/",
31 * expires: new Date(new Date().getTime()+(1000*60*60*24*30)), //30 days
32 * domain: "sencha.com"
35 * Ext.state.Manager.setProvider(cp);
38 * Creates a new CookieProvider.
39 * @param {Object} config (optional) Config object.
42 Ext.define('Ext.state.CookieProvider', {
43 extend: 'Ext.state.Provider',
45 <span id='Ext-state-CookieProvider-cfg-path'> /**
46 </span> * @cfg {String} path
47 * The path for which the cookie is active. Defaults to root '/' which makes it active for all pages in the site.
50 <span id='Ext-state-CookieProvider-cfg-expires'> /**
51 </span> * @cfg {Date} expires
52 * The cookie expiration date. Defaults to 7 days from now.
55 <span id='Ext-state-CookieProvider-cfg-domain'> /**
56 </span> * @cfg {String} domain
57 * The domain to save the cookie for. Note that you cannot specify a different domain than your page is on, but you can
58 * specify a sub-domain, or simply the domain itself like 'sencha.com' to include all sub-domains if you need to access
59 * cookies across different sub-domains. Defaults to null which uses the same domain the page is running on including
60 * the 'www' like 'www.sencha.com'.
63 <span id='Ext-state-CookieProvider-cfg-secure'> /**
64 </span> * @cfg {Boolean} [secure=false]
65 * True if the site is using SSL
68 <span id='Ext-state-CookieProvider-method-constructor'> /**
69 </span> * Creates a new CookieProvider.
70 * @param {Object} [config] Config object.
72 constructor : function(config){
74 me.path = "/";
75 me.expires = new Date(new Date().getTime()+(1000*60*60*24*7)); //7 days
78 me.callParent(arguments);
79 me.state = me.readCookies();
83 set : function(name, value){
86 if(typeof value == "undefined" || value === null){
90 me.setCookie(name, value);
91 me.callParent(arguments);
95 clear : function(name){
96 this.clearCookie(name);
97 this.callParent(arguments);
101 readCookies : function(){
103 c = document.cookie + ";",
104 re = /\s?(.*?)=(.*?);/g,
105 prefix = this.prefix,
111 while((matches = re.exec(c)) != null){
114 if (name && name.substring(0, len) == prefix){
115 cookies[name.substr(len)] = this.decodeValue(value);
122 setCookie : function(name, value){
125 document.cookie = me.prefix + name + "=" + me.encodeValue(value) +
126 ((me.expires == null) ? "" : ("; expires=" + me.expires.toGMTString())) +
127 ((me.path == null) ? "" : ("; path=" + me.path)) +
128 ((me.domain == null) ? "" : ("; domain=" + me.domain)) +
129 ((me.secure == true) ? "; secure" : "");
133 clearCookie : function(name){
136 document.cookie = me.prefix + name + "=null; expires=Thu, 01-Jan-70 00:00:01 GMT" +
137 ((me.path == null) ? "" : ("; path=" + me.path)) +
138 ((me.domain == null) ? "" : ("; domain=" + me.domain)) +
139 ((me.secure == true) ? "; secure" : "");