3 * Copyright(c) 2006-2010 Ext JS, Inc.
5 * http://www.extjs.com/license
9 * @class Ext.state.CookieProvider
10 * @extends Ext.state.Provider
11 * The default Provider implementation which saves state via cookies.
14 var cp = new Ext.state.CookieProvider({
16 expires: new Date(new Date().getTime()+(1000*60*60*24*30)), //30 days
19 Ext.state.Manager.setProvider(cp);
21 * @cfg {String} path The path for which the cookie is active (defaults to root '/' which makes it active for all pages in the site)
22 * @cfg {Date} expires The cookie expiration date (defaults to 7 days from now)
23 * @cfg {String} domain The domain to save the cookie for. Note that you cannot specify a different domain than
24 * your page is on, but you can specify a sub-domain, or simply the domain itself like 'extjs.com' to include
25 * all sub-domains if you need to access cookies across different sub-domains (defaults to null which uses the same
26 * domain the page is running on including the 'www' like 'www.extjs.com')
27 * @cfg {Boolean} secure True if the site is using SSL (defaults to false)
29 * Create a new CookieProvider
30 * @param {Object} config The configuration object
32 Ext.state.CookieProvider = Ext.extend(Ext.state.Provider, {
34 constructor : function(config){
35 Ext.state.CookieProvider.superclass.constructor.call(this);
37 this.expires = new Date(new Date().getTime()+(1000*60*60*24*7)); //7 days
40 Ext.apply(this, config);
41 this.state = this.readCookies();
45 set : function(name, value){
46 if(typeof value == "undefined" || value === null){
50 this.setCookie(name, value);
51 Ext.state.CookieProvider.superclass.set.call(this, name, value);
55 clear : function(name){
56 this.clearCookie(name);
57 Ext.state.CookieProvider.superclass.clear.call(this, name);
61 readCookies : function(){
63 c = document.cookie + ";",
64 re = /\s?(.*?)=(.*?);/g,
68 while((matches = re.exec(c)) != null){
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" : "");