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