4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-state-CookieProvider-method-constructor'><span id='Ext-state-CookieProvider-cfg-secure'><span id='Ext-state-CookieProvider-cfg-domain'><span id='Ext-state-CookieProvider-cfg-expires'><span id='Ext-state-CookieProvider-cfg-path'><span id='Ext-state-CookieProvider'>/**
19 </span></span></span></span></span></span> * @class Ext.state.CookieProvider
20 * @extends Ext.state.Provider
21 * A Provider implementation which saves and retrieves state via cookies.
22 * The CookieProvider supports the usual cookie options, such as:
24 * <li>{@link #path}</li>
25 * <li>{@link #expires}</li>
26 * <li>{@link #domain}</li>
27 * <li>{@link #secure}</li>
29 <pre><code>
30 var cp = new Ext.state.CookieProvider({
31 path: "/cgi-bin/",
32 expires: new Date(new Date().getTime()+(1000*60*60*24*30)), //30 days
33 domain: "sencha.com"
35 Ext.state.Manager.setProvider(cp);
36 </code></pre>
39 * @cfg {String} path The path for which the cookie is active (defaults to root '/' which makes it active for all pages in the site)
40 * @cfg {Date} expires The cookie expiration date (defaults to 7 days from now)
41 * @cfg {String} domain The domain to save the cookie for. Note that you cannot specify a different domain than
42 * your page is on, but you can specify a sub-domain, or simply the domain itself like 'sencha.com' to include
43 * all sub-domains if you need to access cookies across different sub-domains (defaults to null which uses the same
44 * domain the page is running on including the 'www' like 'www.sencha.com')
45 * @cfg {Boolean} secure True if the site is using SSL (defaults to false)
47 * Create a new CookieProvider
48 * @param {Object} config The configuration object
50 Ext.define('Ext.state.CookieProvider', {
51 extend: 'Ext.state.Provider',
53 constructor : function(config){
55 me.path = "/";
56 me.expires = new Date(new Date().getTime()+(1000*60*60*24*7)); //7 days
59 me.callParent(arguments);
60 me.state = me.readCookies();
64 set : function(name, value){
67 if(typeof value == "undefined" || value === null){
71 me.setCookie(name, value);
72 me.callParent(arguments);
76 clear : function(name){
77 this.clearCookie(name);
78 this.callParent(arguments);
82 readCookies : function(){
84 c = document.cookie + ";",
85 re = /\s?(.*?)=(.*?);/g,
92 while((matches = re.exec(c)) != null){
95 if (name && name.substring(0, len) == prefix){
96 cookies[name.substr(len)] = this.decodeValue(value);
103 setCookie : function(name, value){
106 document.cookie = me.prefix + name + "=" + me.encodeValue(value) +
107 ((me.expires == null) ? "" : ("; expires=" + me.expires.toGMTString())) +
108 ((me.path == null) ? "" : ("; path=" + me.path)) +
109 ((me.domain == null) ? "" : ("; domain=" + me.domain)) +
110 ((me.secure == true) ? "; secure" : "");
114 clearCookie : function(name){
117 document.cookie = me.prefix + name + "=null; expires=Thu, 01-Jan-70 00:00:01 GMT" +
118 ((me.path == null) ? "" : ("; path=" + me.path)) +
119 ((me.domain == null) ? "" : ("; domain=" + me.domain)) +
120 ((me.secure == true) ? "; secure" : "");