summaryrefslogtreecommitdiff
path: root/lib/dojo/cookie.js
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2011-03-04 19:02:28 +0300
committerAndrew Dolgov <[email protected]>2011-03-04 19:02:59 +0300
commita089699c8915636ba4f158d77dba9b012bc93208 (patch)
treeb2d7d051f1f55d44a6be07d3ee137e5a7ccfcefb /lib/dojo/cookie.js
parentcfad9259a6feacfa8194b1312770ae6db1ecce50 (diff)
build custom layer of Dojo to speed up loading of tt-rss (refs #293)
Diffstat (limited to 'lib/dojo/cookie.js')
-rw-r--r--lib/dojo/cookie.js126
1 files changed, 89 insertions, 37 deletions
diff --git a/lib/dojo/cookie.js b/lib/dojo/cookie.js
index 0d3b6eac0..67d2cdc6a 100644
--- a/lib/dojo/cookie.js
+++ b/lib/dojo/cookie.js
@@ -5,46 +5,98 @@
*/
-if(!dojo._hasResource["dojo.cookie"]){
-dojo._hasResource["dojo.cookie"]=true;
+if(!dojo._hasResource["dojo.cookie"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
+dojo._hasResource["dojo.cookie"] = true;
dojo.provide("dojo.cookie");
+
dojo.require("dojo.regexp");
-dojo.cookie=function(_1,_2,_3){
-var c=document.cookie;
-if(arguments.length==1){
-var _4=c.match(new RegExp("(?:^|; )"+dojo.regexp.escapeString(_1)+"=([^;]*)"));
-return _4?decodeURIComponent(_4[1]):undefined;
-}else{
-_3=_3||{};
-var _5=_3.expires;
-if(typeof _5=="number"){
-var d=new Date();
-d.setTime(d.getTime()+_5*24*60*60*1000);
-_5=_3.expires=d;
-}
-if(_5&&_5.toUTCString){
-_3.expires=_5.toUTCString();
-}
-_2=encodeURIComponent(_2);
-var _6=_1+"="+_2,_7;
-for(_7 in _3){
-_6+="; "+_7;
-var _8=_3[_7];
-if(_8!==true){
-_6+="="+_8;
-}
-}
-document.cookie=_6;
+
+/*=====
+dojo.__cookieProps = function(){
+ // expires: Date|String|Number?
+ // If a number, the number of days from today at which the cookie
+ // will expire. If a date, the date past which the cookie will expire.
+ // If expires is in the past, the cookie will be deleted.
+ // If expires is omitted or is 0, the cookie will expire when the browser closes. << FIXME: 0 seems to disappear right away? FF3.
+ // path: String?
+ // The path to use for the cookie.
+ // domain: String?
+ // The domain to use for the cookie.
+ // secure: Boolean?
+ // Whether to only send the cookie on secure connections
+ this.expires = expires;
+ this.path = path;
+ this.domain = domain;
+ this.secure = secure;
}
+=====*/
+
+
+dojo.cookie = function(/*String*/name, /*String?*/value, /*dojo.__cookieProps?*/props){
+ // summary:
+ // Get or set a cookie.
+ // description:
+ // If one argument is passed, returns the value of the cookie
+ // For two or more arguments, acts as a setter.
+ // name:
+ // Name of the cookie
+ // value:
+ // Value for the cookie
+ // props:
+ // Properties for the cookie
+ // example:
+ // set a cookie with the JSON-serialized contents of an object which
+ // will expire 5 days from now:
+ // | dojo.cookie("configObj", dojo.toJson(config), { expires: 5 });
+ //
+ // example:
+ // de-serialize a cookie back into a JavaScript object:
+ // | var config = dojo.fromJson(dojo.cookie("configObj"));
+ //
+ // example:
+ // delete a cookie:
+ // | dojo.cookie("configObj", null, {expires: -1});
+ var c = document.cookie;
+ if(arguments.length == 1){
+ var matches = c.match(new RegExp("(?:^|; )" + dojo.regexp.escapeString(name) + "=([^;]*)"));
+ return matches ? decodeURIComponent(matches[1]) : undefined; // String or undefined
+ }else{
+ props = props || {};
+// FIXME: expires=0 seems to disappear right away, not on close? (FF3) Change docs?
+ var exp = props.expires;
+ if(typeof exp == "number"){
+ var d = new Date();
+ d.setTime(d.getTime() + exp*24*60*60*1000);
+ exp = props.expires = d;
+ }
+ if(exp && exp.toUTCString){ props.expires = exp.toUTCString(); }
+
+ value = encodeURIComponent(value);
+ var updatedCookie = name + "=" + value, propName;
+ for(propName in props){
+ updatedCookie += "; " + propName;
+ var propValue = props[propName];
+ if(propValue !== true){ updatedCookie += "=" + propValue; }
+ }
+ document.cookie = updatedCookie;
+ }
};
-dojo.cookie.isSupported=function(){
-if(!("cookieEnabled" in navigator)){
-this("__djCookieTest__","CookiesAllowed");
-navigator.cookieEnabled=this("__djCookieTest__")=="CookiesAllowed";
-if(navigator.cookieEnabled){
-this("__djCookieTest__","",{expires:-1});
-}
-}
-return navigator.cookieEnabled;
+
+dojo.cookie.isSupported = function(){
+ // summary:
+ // Use to determine if the current browser supports cookies or not.
+ //
+ // Returns true if user allows cookies.
+ // Returns false if user doesn't allow cookies.
+
+ if(!("cookieEnabled" in navigator)){
+ this("__djCookieTest__", "CookiesAllowed");
+ navigator.cookieEnabled = this("__djCookieTest__") == "CookiesAllowed";
+ if(navigator.cookieEnabled){
+ this("__djCookieTest__", "", {expires: -1});
+ }
+ }
+ return navigator.cookieEnabled;
};
+
}