3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js">
\r
9 <div id="cls-Ext.state.CookieProvider"></div>/**
\r
10 * @class Ext.state.CookieProvider
\r
11 * @extends Ext.state.Provider
\r
12 * The default Provider implementation which saves state via cookies.
\r
15 var cp = new Ext.state.CookieProvider({
\r
17 expires: new Date(new Date().getTime()+(1000*60*60*24*30)), //30 days
\r
20 Ext.state.Manager.setProvider(cp);
\r
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)
\r
23 * @cfg {Date} expires The cookie expiration date (defaults to 7 days from now)
\r
24 * @cfg {String} domain The domain to save the cookie for. Note that you cannot specify a different domain than
\r
25 * your page is on, but you can specify a sub-domain, or simply the domain itself like 'extjs.com' to include
\r
26 * all sub-domains if you need to access cookies across different sub-domains (defaults to null which uses the same
\r
27 * domain the page is running on including the 'www' like 'www.extjs.com')
\r
28 * @cfg {Boolean} secure True if the site is using SSL (defaults to false)
\r
30 * Create a new CookieProvider
\r
31 * @param {Object} config The configuration object
\r
33 Ext.state.CookieProvider = function(config){
\r
34 Ext.state.CookieProvider.superclass.constructor.call(this);
\r
36 this.expires = new Date(new Date().getTime()+(1000*60*60*24*7)); //7 days
\r
38 this.secure = false;
\r
39 Ext.apply(this, config);
\r
40 this.state = this.readCookies();
\r
43 Ext.extend(Ext.state.CookieProvider, Ext.state.Provider, {
\r
45 set : function(name, value){
\r
46 if(typeof value == "undefined" || value === null){
\r
50 this.setCookie(name, value);
\r
51 Ext.state.CookieProvider.superclass.set.call(this, name, value);
\r
55 clear : function(name){
\r
56 this.clearCookie(name);
\r
57 Ext.state.CookieProvider.superclass.clear.call(this, name);
\r
61 readCookies : function(){
\r
63 var c = document.cookie + ";";
\r
64 var re = /\s?(.*?)=(.*?);/g;
\r
66 while((matches = re.exec(c)) != null){
\r
67 var name = matches[1];
\r
68 var value = matches[2];
\r
69 if(name && name.substring(0,3) == "ys-"){
\r
70 cookies[name.substr(3)] = this.decodeValue(value);
\r
77 setCookie : function(name, value){
\r
78 document.cookie = "ys-"+ name + "=" + this.encodeValue(value) +
\r
79 ((this.expires == null) ? "" : ("; expires=" + this.expires.toGMTString())) +
\r
80 ((this.path == null) ? "" : ("; path=" + this.path)) +
\r
81 ((this.domain == null) ? "" : ("; domain=" + this.domain)) +
\r
82 ((this.secure == true) ? "; secure" : "");
\r
86 clearCookie : function(name){
\r
87 document.cookie = "ys-" + name + "=null; expires=Thu, 01-Jan-70 00:00:01 GMT" +
\r
88 ((this.path == null) ? "" : ("; path=" + this.path)) +
\r
89 ((this.domain == null) ? "" : ("; domain=" + this.domain)) +
\r
90 ((this.secure == true) ? "; secure" : "");
\r