Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 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");
4
 
5
/*=====
6
dojo.__cookieProps = function(kwArgs){
7
	//	expires: Date|Number?
8
	//		If a number, seen as the number of days from today. If a date, the
9
	//		date past which the cookie is invalid. If expires is in the past,
10
	//		the cookie will be deleted If expires is left out or is 0, the
11
	//		cookie will expire when the browser closes.
12
	//	path: String?
13
	//		The path to use for the cookie.
14
	//	domain: String?
15
	//		The domain to use for the cookie.
16
	//	secure: Boolean?
17
	//		Whether to only send the cookie on secure connections
18
}
19
=====*/
20
 
21
 
22
dojo.cookie = function(/*String*/name, /*String?*/value, /*dojo.__cookieProps?*/props){
23
	//	summary:
24
	//		Get or set a cookie.
25
	//	description:
26
	// 		If you pass in one argument, the the value of the cookie is returned
27
	//
28
	// 		If you pass in two arguments, the cookie value is set to the second
29
	// 		argument.
30
	//
31
	// 		If you pass in three arguments, the cookie value is set to the
32
	// 		second argument, and the options on the third argument are used for
33
	// 		extended properties on the cookie
34
	//	name:
35
	//		The name of the cookie
36
	//	value:
37
	//		Optional. The value for the cookie.
38
	//	props:
39
	//		Optional additional properties for the cookie
40
	//	example:
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 });
44
	//
45
	//	example:
46
	//		de-serialize a cookie back into a JavaScript object:
47
	//	|	var config = dojo.fromJson(dojo.cookie("configObj"));
48
	//
49
	//	example:
50
	//		delete a cookie:
51
	//	|	dojo.cookie("configObj", null);
52
	var c = document.cookie;
53
	if(arguments.length == 1){
54
		var idx = c.lastIndexOf(name+'=');
55
		if(idx == -1){ return null; }
56
		var start = idx+name.length+1;
57
		var end = c.indexOf(';', idx+name.length+1);
58
		if(end == -1){ end = c.length; }
59
		return decodeURIComponent(c.substring(start, end));
60
	}else{
61
		props = props || {};
62
		value = encodeURIComponent(value);
63
		if(typeof(props.expires) == "number"){
64
			var d = new Date();
65
			d.setTime(d.getTime()+(props.expires*24*60*60*1000));
66
			props.expires = d;
67
		}
68
		document.cookie = name + "=" + value
69
			+ (props.expires ? "; expires=" + props.expires.toUTCString() : "")
70
			+ (props.path ? "; path=" + props.path : "")
71
			+ (props.domain ? "; domain=" + props.domain : "")
72
			+ (props.secure ? "; secure" : "");
73
		return null;
74
	}
75
};
76
 
77
}