4 * Copyright(c) 2006-2007, Ext JS, LLC.
6 * Originally Released Under LGPL - original licence link has changed is not relivant.
9 * <script type="text/javascript">
12 * @class Roo.state.CookieProvider
13 * @extends Roo.state.Provider
14 * The default Provider implementation which saves state via cookies.
17 var cp = new Roo.state.CookieProvider({
19 expires: new Date(new Date().getTime()+(1000*60*60*24*30)); //30 days
22 Roo.state.Manager.setProvider(cp);
24 * @cfg {String} path The path for which the cookie is active (defaults to root '/' which makes it active for all pages in the site)
25 * @cfg {Date} expires The cookie expiration date (defaults to 7 days from now)
26 * @cfg {String} domain The domain to save the cookie for. Note that you cannot specify a different domain than
27 * your page is on, but you can specify a sub-domain, or simply the domain itself like 'roojs.com' to include
28 * all sub-domains if you need to access cookies across different sub-domains (defaults to null which uses the same
29 * domain the page is running on including the 'www' like 'www.roojs.com')
30 * @cfg {Boolean} secure True if the site is using SSL (defaults to false)
32 * Create a new CookieProvider
33 * @param {Object} config The configuration object
35 Roo.state.CookieProvider = function(config){
36 Roo.state.CookieProvider.superclass.constructor.call(this);
38 this.expires = new Date(new Date().getTime()+(1000*60*60*24*7)); //7 days
41 Roo.apply(this, config);
42 this.state = this.readCookies();
45 Roo.extend(Roo.state.CookieProvider, Roo.state.Provider, {
47 set : function(name, value){
48 if(typeof value == "undefined" || value === null){
52 this.setCookie(name, value);
53 Roo.state.CookieProvider.superclass.set.call(this, name, value);
57 clear : function(name){
58 this.clearCookie(name);
59 Roo.state.CookieProvider.superclass.clear.call(this, name);
63 readCookies : function(){
65 var c = document.cookie + ";";
66 var re = /\s?(.*?)=(.*?);/g;
68 while((matches = re.exec(c)) != null){
69 var name = matches[1];
70 var value = matches[2];
71 if(name && name.substring(0,3) == "ys-"){
72 cookies[name.substr(3)] = this.decodeValue(value);
79 setCookie : function(name, value){
80 document.cookie = "ys-"+ name + "=" + this.encodeValue(value) +
81 ((this.expires == null) ? "" : ("; expires=" + this.expires.toGMTString())) +
82 ((this.path == null) ? "" : ("; path=" + this.path)) +
83 ((this.domain == null) ? "" : ("; domain=" + this.domain)) +
84 ((this.secure == true) ? "; secure" : "");
88 clearCookie : function(name){
89 document.cookie = "ys-" + name + "=null; expires=Thu, 01-Jan-70 00:00:01 GMT" +
90 ((this.path == null) ? "" : ("; path=" + this.path)) +
91 ((this.domain == null) ? "" : ("; domain=" + this.domain)) +
92 ((this.secure == true) ? "; secure" : "");