-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcookie.js
More file actions
46 lines (39 loc) · 1.27 KB
/
cookie.js
File metadata and controls
46 lines (39 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
;(function(){
"use strict";
var Cookie = function(){
this.cookieList = document.cookie;
this.cookieToObject = function($str){
if(!$str.length){
return [];
}
if($str.indexOf(';') === -1){
var _cookie = $str.split('=');
return [_cookie[0].trim(),_cookie[1]];
}
var cookieArr = $str.split(';'),
len = cookieArr.length,
result = [],
i = 0;
for(; i<len; ++i){
var item = cookieArr[i].split('=');
result.push([item[0].trim(),item[1]]);
}
return result;
};
this.list = this.cookieToObject(this.cookieList);
this.length = this.list.length;
};
Cookie.prototype.get = function(name){
for (var i=0; i<this.length; ++i){
console.log(this.list[i][0] == name);
if(this.list[i][0] != name){
continue;
}
return this.list[i][1];
}
};
Cookie.prototype.set = function(key,value){
document.cookie = key + '=' + value;
};
window.Coockie = new Cookie();
})();