diff options
Diffstat (limited to 'docroot/classes/cookie.class.js')
-rwxr-xr-x | docroot/classes/cookie.class.js | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/docroot/classes/cookie.class.js b/docroot/classes/cookie.class.js new file mode 100755 index 0000000..adf28f2 --- /dev/null +++ b/docroot/classes/cookie.class.js | |||
@@ -0,0 +1,70 @@ | |||
1 | /* | ||
2 | * Material Experience - Cookie Handling Class | ||
3 | * | ||
4 | * EYEMG - Interactive Media Group | ||
5 | * Created by Mike Crute (mcrute@eyemg.com) on 10/2/07 | ||
6 | * Updated by Mike Crute (mcrute@eyemg.com) on 10/3/07 | ||
7 | * | ||
8 | * Class to handle cookie CRUD. Code adapted from: | ||
9 | * http://www.quirksmode.org/js/cookies.html | ||
10 | */ | ||
11 | |||
12 | var Cookie = Object.extend(Class.create(), | ||
13 | { | ||
14 | /* | ||
15 | * Creates a cookie. | ||
16 | */ | ||
17 | create: function(name, value, days) | ||
18 | { | ||
19 | if (days) | ||
20 | { | ||
21 | var date = new Date().setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); | ||
22 | var expires = "; expires=" + date.toGMTString(); | ||
23 | } | ||
24 | |||
25 | document.cookie = name + "=" + value + (expires ? expires : '') + "; path=/"; | ||
26 | }, | ||
27 | |||
28 | /* | ||
29 | * Setting the expiration date of the cookie to -1 effectively deletes | ||
30 | * it. | ||
31 | */ | ||
32 | erase: function(name) | ||
33 | { | ||
34 | createCookie(name,"",-1); | ||
35 | }, | ||
36 | |||
37 | /* | ||
38 | * Reads a cookie and returns the value. | ||
39 | */ | ||
40 | read: function(name) | ||
41 | { | ||
42 | var nameEQ = name + "="; | ||
43 | var ca = document.cookie.split(';'); | ||
44 | |||
45 | for ( var i = 0; i < ca.length; i++ ) | ||
46 | { | ||
47 | var c = ca[i]; | ||
48 | |||
49 | while (c.charAt(0) == ' ') | ||
50 | { | ||
51 | c = c.substring(1,c.length); | ||
52 | } | ||
53 | |||
54 | if (c.indexOf(nameEQ) == 0) | ||
55 | { | ||
56 | return c.substring(nameEQ.length,c.length); | ||
57 | } | ||
58 | } | ||
59 | |||
60 | return null; | ||
61 | } | ||
62 | }); | ||
63 | |||
64 | /* | ||
65 | * Shorthand for Cookie.read | ||
66 | */ | ||
67 | function $C(name) | ||
68 | { | ||
69 | return Cookie.read(name); | ||
70 | } \ No newline at end of file | ||