Line # Revision Author
1 296 ahitrov new function(){
2 var
3 w = window,
4 undef = 'undefined',
5 h = 'length',
6 r = 'replace';
7 w.ra || (w.ra = {});
8 w.ra.cookie = {
9 'get': function(name) {
10 var
11 a = document.cookie.split(/;\s*/g),
12 t = false,
13 d = decodeURIComponent,
14 e = /%[\da-fA-F]{2}/g,
15 c = {};
16 while (a[h]){
17 t=a[a[h]-1].split('=');
18
19 c[t[0][r](e,d)] = t.slice(1).join('');
20 a[h]--
21 }
22 return typeof(name)!=undef ?
23 ( typeof(t=c[name])!=undef ? t[r](e,d) : false ) :
24 c
25 },
26 'set': function(name, value, opt){
27 var i, t, d = encodeURIComponent,
28 e = /[^<>:\^\+\$\?\&#\[\]\\,\.\{\}\'\/]+/g,
29 a = [name[r](e,d),'='],
30 k = 'secure,path,expires,domain'.split(','),
31 f=[
32 function(b, k){return (b && v) ? k : ''},
33 function(b, k, v){return k + ((b && v) ? v : '/')},
34 function(b, k, v){return (b && v.constructor == Date) ? k+v.toGMTString() : ''},
35 function(b, k, v){return k + ((b && v )? v : location.hostname)}
36 ];
37 opt || (opt={});
38 a[a[h]]= typeof opt['encoded'] != undef ? value : value.replace(e,d);
39
40 for (i=k[h]; i--;){
41 t=k[i];
42 a[a[h]]=f[i](typeof opt[t] != undef, '; '+t+'=', opt[t])
43 }
44 if( (i=4*1024-(t=a.join('')).length) < 0 ){
45 t = a[2].slice(0,i);
46 i = a[2].slice(i);
47 a[2]=t;
48 t=a.join('')
49 } else {
50 i = false
51 };
52 document.cookie = t;
53 return i
54 },
55 'del': function(name){
56 var r = this.get(name);
57 this.set(name, '', {'expires':new Date(0)});
58 return r
59 },
60 'test': function(){
61 var testName = 'test_cookie_', testValue = '{value:"%test>"}';
62 this.set(testName,testValue);
63 return this.del(testName) == testValue
64 }
65 };
66 w.ra.cookie.test = w.ra.cookie.test();
67 // w.ra.cookie.test = navigator.cookieEnabled;
68 };