author | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2013-08-30 15:56:53 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2013-08-30 21:23:42 (UTC) |
commit | 20bea94ab6b91c85b171dcf86baba0a64169d508 (patch) (unidiff) | |
tree | 6e38e91498dcdb861620eba1e237d1026fe79cc5 /frontend/delta/js/Clipperz/Set.js | |
parent | bde3c7b98523112ade9c5bbf7390c4ecb494cd2e (diff) | |
download | clipperz-20bea94ab6b91c85b171dcf86baba0a64169d508.zip clipperz-20bea94ab6b91c85b171dcf86baba0a64169d508.tar.gz clipperz-20bea94ab6b91c85b171dcf86baba0a64169d508.tar.bz2 |
First release of /delta version
Diffstat (limited to 'frontend/delta/js/Clipperz/Set.js') (more/less context) (show whitespace changes)
-rw-r--r-- | frontend/delta/js/Clipperz/Set.js | 162 |
1 files changed, 162 insertions, 0 deletions
diff --git a/frontend/delta/js/Clipperz/Set.js b/frontend/delta/js/Clipperz/Set.js new file mode 100644 index 0000000..b3831a4 --- a/dev/null +++ b/frontend/delta/js/Clipperz/Set.js | |||
@@ -0,0 +1,162 @@ | |||
1 | /* | ||
2 | |||
3 | Copyright 2008-2013 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz, the online password manager. | ||
6 | For further information about its features and functionalities please | ||
7 | refer to http://www.clipperz.com. | ||
8 | |||
9 | * Clipperz is free software: you can redistribute it and/or modify it | ||
10 | under the terms of the GNU Affero General Public License as published | ||
11 | by the Free Software Foundation, either version 3 of the License, or | ||
12 | (at your option) any later version. | ||
13 | |||
14 | * Clipperz is distributed in the hope that it will be useful, but | ||
15 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
17 | See the GNU Affero General Public License for more details. | ||
18 | |||
19 | * You should have received a copy of the GNU Affero General Public | ||
20 | License along with Clipperz. If not, see http://www.gnu.org/licenses/. | ||
21 | |||
22 | */ | ||
23 | |||
24 | |||
25 | if (typeof(Clipperz) == 'undefined') { | ||
26 | Clipperz = {}; | ||
27 | } | ||
28 | |||
29 | //############################################################################# | ||
30 | |||
31 | Clipperz.Set = function(args) { | ||
32 | args = args || {}; | ||
33 | //MochiKit.Base.bindMethods(this); | ||
34 | |||
35 | if (args.items != null) { | ||
36 | this._items = args.items.slice(); | ||
37 | } else { | ||
38 | this._items = []; | ||
39 | } | ||
40 | |||
41 | return this; | ||
42 | } | ||
43 | |||
44 | //============================================================================= | ||
45 | |||
46 | Clipperz.Set.prototype = MochiKit.Base.update(null, { | ||
47 | |||
48 | //------------------------------------------------------------------------- | ||
49 | |||
50 | 'toString': function() { | ||
51 | return "Clipperz.Set"; | ||
52 | }, | ||
53 | |||
54 | //------------------------------------------------------------------------- | ||
55 | |||
56 | 'items': function() { | ||
57 | return this._items; | ||
58 | }, | ||
59 | |||
60 | //------------------------------------------------------------------------- | ||
61 | |||
62 | 'popAnItem': function() { | ||
63 | var result; | ||
64 | |||
65 | if (this.size() > 0) { | ||
66 | result = this.items().pop(); | ||
67 | } else { | ||
68 | result = null; | ||
69 | } | ||
70 | |||
71 | return result; | ||
72 | }, | ||
73 | |||
74 | //------------------------------------------------------------------------- | ||
75 | |||
76 | 'allItems': function() { | ||
77 | return this.items(); | ||
78 | }, | ||
79 | |||
80 | //------------------------------------------------------------------------- | ||
81 | |||
82 | 'contains': function(anItem) { | ||
83 | return (this.indexOf(anItem) != -1); | ||
84 | }, | ||
85 | |||
86 | //------------------------------------------------------------------------- | ||
87 | |||
88 | 'indexOf': function(anItem) { | ||
89 | varresult; | ||
90 | vari, c; | ||
91 | |||
92 | result = -1; | ||
93 | |||
94 | c = this.items().length; | ||
95 | for (i=0; (i<c) && (result == -1); i++) { | ||
96 | if (this.items()[i] === anItem) { | ||
97 | result = i; | ||
98 | } | ||
99 | } | ||
100 | |||
101 | return result; | ||
102 | }, | ||
103 | |||
104 | //------------------------------------------------------------------------- | ||
105 | |||
106 | 'add': function(anItem) { | ||
107 | if (anItem.constructor == Array) { | ||
108 | MochiKit.Base.map(MochiKit.Base.bind(this,add, this), anItem); | ||
109 | } else { | ||
110 | if (! this.contains(anItem)) { | ||
111 | this.items().push(anItem); | ||
112 | } | ||
113 | } | ||
114 | }, | ||
115 | |||
116 | //------------------------------------------------------------------------- | ||
117 | |||
118 | 'debug': function() { | ||
119 | vari, c; | ||
120 | |||
121 | result = -1; | ||
122 | |||
123 | c = this.items().length; | ||
124 | for (i=0; i<c; i++) { | ||
125 | alert("[" + i + "] " + this.items()[i].label); | ||
126 | } | ||
127 | }, | ||
128 | |||
129 | //------------------------------------------------------------------------- | ||
130 | |||
131 | 'remove': function(anItem) { | ||
132 | if (anItem.constructor == Array) { | ||
133 | MochiKit.Base.map(MochiKit.Base.bind(this.remove, this), anItem); | ||
134 | } else { | ||
135 | varitemIndex; | ||
136 | |||
137 | itemIndex = this.indexOf(anItem); | ||
138 | if (itemIndex != -1) { | ||
139 | this.items().splice(itemIndex, 1); | ||
140 | } | ||
141 | } | ||
142 | }, | ||
143 | |||
144 | //------------------------------------------------------------------------- | ||
145 | |||
146 | 'size': function() { | ||
147 | return this.items().length; | ||
148 | }, | ||
149 | |||
150 | //------------------------------------------------------------------------- | ||
151 | |||
152 | 'empty': function() { | ||
153 | this.items().splice(0, this.items().length); | ||
154 | }, | ||
155 | |||
156 | //------------------------------------------------------------------------- | ||
157 | |||
158 | __syntaxFix__: "syntax fix" | ||
159 | |||
160 | //------------------------------------------------------------------------- | ||
161 | }); | ||
162 | |||