-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsdictionary.js
78 lines (78 loc) · 1.99 KB
/
jsdictionary.js
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
function jsdictionary() {
this.dictionary = [];
this.type = "JS Dictionary";
this.count = function () {
var count = 0, key;
for (key in this.dictionary) {
count++;
}
return count;
};
this.containsKey = function (k) {
var has = false, key;
for (key in this.dictionary) {
if (key == k) {
has = true;
break;
}
}
return has;
};
this.containsValue = function (v) {
var has = false, key;
for (key in this.dictionary) {
if (typeof (v.outerHTML) == "undefined") {
if (this.dictionary[key].toString() == v.toString()) {
has = true;
break;
}
}
else {
if (this.dictionary[key].outerHTML == v.outerHTML) {
has = true;
break;
}
}
}
return has;
};
this.keys = function () {
var keys = new Array(), i = 0;
for (key in this.dictionary) {
keys[i] = key;
i++;
}
return keys;
}
this.values = function () {
var values = new Array(), i = 0;
for (key in this.dictionary) {
values[i] = this.dictionary[key];
i++;
}
return values;
}
this.add = function (k, v) {
if (!this.containsKey(k) && k != "" && typeof(k) == "string") {
this.dictionary[k] = v;
this[k] = v;
}
};
this.remove = function (k) {
if (this.containsKey(k)) {
delete this.dictionary[k];
delete this[k];
}
};
this.clear = function () {
var ids = new Array();
for (key in this.dictionary) {
ids.push(key)
}
for(id in ids)
{
delete this.dictionary[ids[id]];
delete this[ids[id]];
}
};
}