3
* Copyright(c) 2006-2008, Ext JS, LLC.
6
* http://extjs.com/license
11
* @class Ext.state.CookieProvider
12
* @extends Ext.state.Provider
13
* The default Provider implementation which saves state via cookies.
16
var cp = new Ext.state.CookieProvider({
18
expires: new Date(new Date().getTime()+(1000*60*60*24*30)), //30 days
21
Ext.state.Manager.setProvider(cp);
23
* @cfg {String} path The path for which the cookie is active (defaults to root '/' which makes it active for all pages in the site)
24
* @cfg {Date} expires The cookie expiration date (defaults to 7 days from now)
25
* @cfg {String} domain The domain to save the cookie for. Note that you cannot specify a different domain than
26
* your page is on, but you can specify a sub-domain, or simply the domain itself like 'extjs.com' to include
27
* all sub-domains if you need to access cookies across different sub-domains (defaults to null which uses the same
28
* domain the page is running on including the 'www' like 'www.extjs.com')
29
* @cfg {Boolean} secure True if the site is using SSL (defaults to false)
31
* Create a new CookieProvider
32
* @param {Object} config The configuration object
34
Ext.state.CookieProvider = 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();
44
Ext.extend(Ext.state.CookieProvider, Ext.state.Provider, {
46
set : function(name, value){
47
if(typeof value == "undefined" || value === null){
51
this.setCookie(name, value);
52
Ext.state.CookieProvider.superclass.set.call(this, name, value);
56
clear : function(name){
57
this.clearCookie(name);
58
Ext.state.CookieProvider.superclass.clear.call(this, name);
62
readCookies : function(){
64
var c = document.cookie + ";";
65
var re = /\s?(.*?)=(.*?);/g;
67
while((matches = re.exec(c)) != null){
68
var name = matches[1];
69
var value = matches[2];
70
if(name && name.substring(0,3) == "ys-"){
71
cookies[name.substr(3)] = this.decodeValue(value);
78
setCookie : function(name, value){
79
document.cookie = "ys-"+ name + "=" + this.encodeValue(value) +
80
((this.expires == null) ? "" : ("; expires=" + this.expires.toGMTString())) +
81
((this.path == null) ? "" : ("; path=" + this.path)) +
82
((this.domain == null) ? "" : ("; domain=" + this.domain)) +
83
((this.secure == true) ? "; secure" : "");
87
clearCookie : function(name){
88
document.cookie = "ys-" + name + "=null; expires=Thu, 01-Jan-70 00:00:01 GMT" +
89
((this.path == null) ? "" : ("; path=" + this.path)) +
90
((this.domain == null) ? "" : ("; domain=" + this.domain)) +
91
((this.secure == true) ? "; secure" : "");
b'\\ No newline at end of file'