1 if(!dojo._hasResource["dojo.cookie"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojo.cookie"] = true;
3 dojo.provide("dojo.cookie");
5 dojo.require("dojo.regexp");
8 dojo.__cookieProps = function(){
9 // expires: Date|String|Number?
10 // If a number, the number of days from today at which the cookie
11 // will expire. If a date, the date past which the cookie will expire.
12 // If expires is in the past, the cookie will be deleted.
13 // If expires is omitted or is 0, the cookie will expire when the browser closes. << FIXME: 0 seems to disappear right away? FF3.
15 // The path to use for the cookie.
17 // The domain to use for the cookie.
19 // Whether to only send the cookie on secure connections
20 this.expires = expires;
28 dojo.cookie = function(/*String*/name, /*String?*/value, /*dojo.__cookieProps?*/props){
30 // Get or set a cookie.
32 // If one argument is passed, returns the value of the cookie
33 // For two or more arguments, acts as a setter.
37 // Value for the cookie
39 // Properties for the cookie
41 // set a cookie with the JSON-serialized contents of an object which
42 // will expire 5 days from now:
43 // | dojo.cookie("configObj", dojo.toJson(config), { expires: 5 });
46 // de-serialize a cookie back into a JavaScript object:
47 // | var config = dojo.fromJson(dojo.cookie("configObj"));
51 // | dojo.cookie("configObj", null, {expires: -1});
52 var c = document.cookie;
53 if(arguments.length == 1){
54 var matches = c.match(new RegExp("(?:^|; )" + dojo.regexp.escapeString(name) + "=([^;]*)"));
55 return matches ? decodeURIComponent(matches[1]) : undefined; // String or undefined
58 // FIXME: expires=0 seems to disappear right away, not on close? (FF3) Change docs?
59 var exp = props.expires;
60 if(typeof exp == "number"){
62 d.setTime(d.getTime() + exp*24*60*60*1000);
63 exp = props.expires = d;
65 if(exp && exp.toUTCString){ props.expires = exp.toUTCString(); }
67 value = encodeURIComponent(value);
68 var updatedCookie = name + "=" + value;
69 for(propName in props){
70 updatedCookie += "; " + propName;
71 var propValue = props[propName];
72 if(propValue !== true){ updatedCookie += "=" + propValue; }
74 document.cookie = updatedCookie;
78 dojo.cookie.isSupported = function(){
80 // Use to determine if the current browser supports cookies or not.
82 // Returns true if user allows cookies.
83 // Returns false if user doesn't allow cookies.
85 if(!("cookieEnabled" in navigator)){
86 this("__djCookieTest__", "CookiesAllowed");
87 navigator.cookieEnabled = this("__djCookieTest__") == "CookiesAllowed";
88 if(navigator.cookieEnabled){
89 this("__djCookieTest__", "", {expires: -1});
92 return navigator.cookieEnabled;