]>
git.wh0rd.org - tt-rss.git/blob - lib/dojo/cookie.js.uncompressed.js
1 define("dojo/cookie", ["./_base/kernel", "./regexp"], function(dojo
, regexp
){
8 // expires: Date|String|Number?
9 // If a number, the number of days from today at which the cookie
10 // will expire. If a date, the date past which the cookie will expire.
11 // If expires is in the past, the cookie will be deleted.
12 // If expires is omitted or is 0, the cookie will expire when the browser closes.
14 // The path to use for the cookie.
16 // The domain to use for the cookie.
18 // Whether to only send the cookie on secure connections
23 dojo
.cookie = function(/*String*/name
, /*String?*/ value
, /*__cookieProps?*/ props
){
25 // Get or set a cookie.
27 // If one argument is passed, returns the value of the cookie
28 // For two or more arguments, acts as a setter.
32 // Value for the cookie
34 // Properties for the cookie
36 // set a cookie with the JSON-serialized contents of an object which
37 // will expire 5 days from now:
38 // | require(["dojo/cookie", "dojo/json"], function(cookie, json){
39 // | cookie("configObj", json.stringify(config, {expires: 5 }));
43 // de-serialize a cookie back into a JavaScript object:
44 // | require(["dojo/cookie", "dojo/json"], function(cookie, json){
45 // | config = json.parse(cookie("configObj"));
50 // | require(["dojo/cookie"], function(cookie){
51 // | cookie("configObj", null, {expires: -1});
53 var c
= document
.cookie
, ret
;
54 if(arguments
.length
== 1){
55 var matches
= c
.match(new RegExp("(?:^|; )" + regexp
.escapeString(name
) + "=([^;]*)"));
56 ret
= matches
? decodeURIComponent(matches
[1]) : undefined;
59 // FIXME: expires=0 seems to disappear right away, not on close? (FF3) Change docs?
60 var exp
= props
.expires
;
61 if(typeof exp
== "number"){
63 d
.setTime(d
.getTime() + exp
*24*60*60*1000);
64 exp
= props
.expires
= d
;
66 if(exp
&& exp
.toUTCString
){ props
.expires
= exp
.toUTCString(); }
68 value
= encodeURIComponent(value
);
69 var updatedCookie
= name
+ "=" + value
, propName
;
70 for(propName
in props
){
71 updatedCookie
+= "; " + propName
;
72 var propValue
= props
[propName
];
73 if(propValue
!== true){ updatedCookie
+= "=" + propValue
; }
75 document
.cookie
= updatedCookie
;
77 return ret
; // String|undefined
80 dojo
.cookie
.isSupported = function(){
82 // Use to determine if the current browser supports cookies or not.
84 // Returns true if user allows cookies.
85 // Returns false if user doesn't allow cookies.
87 if(!("cookieEnabled" in navigator
)){
88 this("__djCookieTest__", "CookiesAllowed");
89 navigator
.cookieEnabled
= this("__djCookieTest__") == "CookiesAllowed";
90 if(navigator
.cookieEnabled
){
91 this("__djCookieTest__", "", {expires
: -1});
94 return navigator
.cookieEnabled
;