27 |
jpm |
1 |
/*
|
|
|
2 |
* Ext JS Library 2.0.2
|
|
|
3 |
* Copyright(c) 2006-2008, Ext JS, LLC.
|
|
|
4 |
* licensing@extjs.com
|
|
|
5 |
*
|
|
|
6 |
* http://extjs.com/license
|
|
|
7 |
*/
|
|
|
8 |
|
|
|
9 |
|
|
|
10 |
/**
|
|
|
11 |
* @class Ext.state.CookieProvider
|
|
|
12 |
* @extends Ext.state.Provider
|
|
|
13 |
* The default Provider implementation which saves state via cookies.
|
|
|
14 |
* <br />Usage:
|
|
|
15 |
<pre><code>
|
|
|
16 |
var cp = new Ext.state.CookieProvider({
|
|
|
17 |
path: "/cgi-bin/",
|
|
|
18 |
expires: new Date(new Date().getTime()+(1000*60*60*24*30)), //30 days
|
|
|
19 |
domain: "extjs.com"
|
|
|
20 |
});
|
|
|
21 |
Ext.state.Manager.setProvider(cp);
|
|
|
22 |
</code></pre>
|
|
|
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)
|
|
|
30 |
* @constructor
|
|
|
31 |
* Create a new CookieProvider
|
|
|
32 |
* @param {Object} config The configuration object
|
|
|
33 |
*/
|
|
|
34 |
Ext.state.CookieProvider = function(config){
|
|
|
35 |
Ext.state.CookieProvider.superclass.constructor.call(this);
|
|
|
36 |
this.path = "/";
|
|
|
37 |
this.expires = new Date(new Date().getTime()+(1000*60*60*24*7)); //7 days
|
|
|
38 |
this.domain = null;
|
|
|
39 |
this.secure = false;
|
|
|
40 |
Ext.apply(this, config);
|
|
|
41 |
this.state = this.readCookies();
|
|
|
42 |
};
|
|
|
43 |
|
|
|
44 |
Ext.extend(Ext.state.CookieProvider, Ext.state.Provider, {
|
|
|
45 |
// private
|
|
|
46 |
set : function(name, value){
|
|
|
47 |
if(typeof value == "undefined" || value === null){
|
|
|
48 |
this.clear(name);
|
|
|
49 |
return;
|
|
|
50 |
}
|
|
|
51 |
this.setCookie(name, value);
|
|
|
52 |
Ext.state.CookieProvider.superclass.set.call(this, name, value);
|
|
|
53 |
},
|
|
|
54 |
|
|
|
55 |
// private
|
|
|
56 |
clear : function(name){
|
|
|
57 |
this.clearCookie(name);
|
|
|
58 |
Ext.state.CookieProvider.superclass.clear.call(this, name);
|
|
|
59 |
},
|
|
|
60 |
|
|
|
61 |
// private
|
|
|
62 |
readCookies : function(){
|
|
|
63 |
var cookies = {};
|
|
|
64 |
var c = document.cookie + ";";
|
|
|
65 |
var re = /\s?(.*?)=(.*?);/g;
|
|
|
66 |
var matches;
|
|
|
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);
|
|
|
72 |
}
|
|
|
73 |
}
|
|
|
74 |
return cookies;
|
|
|
75 |
},
|
|
|
76 |
|
|
|
77 |
// private
|
|
|
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" : "");
|
|
|
84 |
},
|
|
|
85 |
|
|
|
86 |
// private
|
|
|
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" : "");
|
|
|
92 |
}
|
|
|
93 |
});
|