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