3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * A Provider implementation which saves and retrieves state via cookies. The CookieProvider supports the usual cookie
26 * Ext.create('Ext.state.CookieProvider', {
28 * expires: new Date(new Date().getTime()+(1000*60*60*24*30)), //30 days
29 * domain: "sencha.com"
32 * Ext.state.Manager.setProvider(cp);
35 * Creates a new CookieProvider.
36 * @param {Object} config (optional) Config object.
39 Ext.define('Ext.state.CookieProvider', {
40 extend: 'Ext.state.Provider',
44 * The path for which the cookie is active. Defaults to root '/' which makes it active for all pages in the site.
49 * The cookie expiration date. Defaults to 7 days from now.
53 * @cfg {String} domain
54 * The domain to save the cookie for. Note that you cannot specify a different domain than your page is on, but you can
55 * specify a sub-domain, or simply the domain itself like 'sencha.com' to include all sub-domains if you need to access
56 * cookies across different sub-domains. Defaults to null which uses the same domain the page is running on including
57 * the 'www' like 'www.sencha.com'.
61 * @cfg {Boolean} [secure=false]
62 * True if the site is using SSL
66 * Creates a new CookieProvider.
67 * @param {Object} [config] Config object.
69 constructor : function(config){
72 me.expires = new Date(new Date().getTime()+(1000*60*60*24*7)); //7 days
75 me.callParent(arguments);
76 me.state = me.readCookies();
80 set : function(name, value){
83 if(typeof value == "undefined" || value === null){
87 me.setCookie(name, value);
88 me.callParent(arguments);
92 clear : function(name){
93 this.clearCookie(name);
94 this.callParent(arguments);
98 readCookies : function(){
100 c = document.cookie + ";",
101 re = /\s?(.*?)=(.*?);/g,
102 prefix = this.prefix,
108 while((matches = re.exec(c)) != null){
111 if (name && name.substring(0, len) == prefix){
112 cookies[name.substr(len)] = this.decodeValue(value);
119 setCookie : function(name, value){
122 document.cookie = me.prefix + name + "=" + me.encodeValue(value) +
123 ((me.expires == null) ? "" : ("; expires=" + me.expires.toGMTString())) +
124 ((me.path == null) ? "" : ("; path=" + me.path)) +
125 ((me.domain == null) ? "" : ("; domain=" + me.domain)) +
126 ((me.secure == true) ? "; secure" : "");
130 clearCookie : function(name){
133 document.cookie = me.prefix + name + "=null; expires=Thu, 01-Jan-70 00:00:01 GMT" +
134 ((me.path == null) ? "" : ("; path=" + me.path)) +
135 ((me.domain == null) ? "" : ("; domain=" + me.domain)) +
136 ((me.secure == true) ? "; secure" : "");