summaryrefslogtreecommitdiff
path: root/frontend/gamma/js/MochiKit/Base.js
Unidiff
Diffstat (limited to 'frontend/gamma/js/MochiKit/Base.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/gamma/js/MochiKit/Base.js156
1 files changed, 102 insertions, 54 deletions
diff --git a/frontend/gamma/js/MochiKit/Base.js b/frontend/gamma/js/MochiKit/Base.js
index d33c269..ca1734c 100644
--- a/frontend/gamma/js/MochiKit/Base.js
+++ b/frontend/gamma/js/MochiKit/Base.js
@@ -1,450 +1,462 @@
1/*** 1/***
2 2
3MochiKit.Base 1.5 3MochiKit.Base 1.5
4 4
5See <http://mochikit.com/> for documentation, downloads, license, etc. 5See <http://mochikit.com/> for documentation, downloads, license, etc.
6 6
7(c) 2005 Bob Ippolito. All rights Reserved. 7(c) 2005 Bob Ippolito. All rights Reserved.
8 8
9***/ 9***/
10 10
11if (typeof(MochiKit) == 'undefined') { 11
12 MochiKit = {}; 12// MochiKit module (namespace)
13} 13var MochiKit = MochiKit || {};
14if (typeof(MochiKit.__export__) == "undefined") { 14if (typeof(MochiKit.__export__) == "undefined") {
15 MochiKit.__export__ = true; 15 MochiKit.__export__ = true;
16} 16}
17if (typeof(MochiKit.Base) == 'undefined') { 17MochiKit.NAME = "MochiKit";
18 MochiKit.Base = {}; 18MochiKit.VERSION = "1.5";
19} 19MochiKit.__repr__ = function () {
20 return "[" + this.NAME + " " + this.VERSION + "]";
21};
22MochiKit.toString = function () {
23 return this.__repr__();
24};
25
26
27// MochiKit.Base module
28MochiKit.Base = MochiKit.Base || {};
20 29
21/** 30/**
22 * Registers a new MochiKit module. This function will insert a new 31 * Creates a new module in a parent namespace. This function will
23 * property into the "MochiKit" object, making sure that all 32 * create a new empty module object with "NAME", "VERSION",
24 * dependency modules have already been inserted. It will also make 33 * "toString" and "__repr__" properties. This object will be inserted into the parent object
25 * sure that the appropriate properties and default module functions 34 * using the specified name (i.e. parent[name] = module). It will
26 * are defined. 35 * also verify that all the dependency modules are defined in the
36 * parent, or an error will be thrown.
27 * 37 *
38 * @param {Object} parent the parent module (use "this" or "window" for
39 * a global module)
28 * @param {String} name the module name, e.g. "Base" 40 * @param {String} name the module name, e.g. "Base"
29 * @param {String} version the module version, e.g. "1.5" 41 * @param {String} version the module version, e.g. "1.5"
30 * @param {Array} deps the array of module dependencies (as strings) 42 * @param {Array} [deps] the array of module dependencies (as strings)
31 */ 43 */
32MochiKit.Base._module = function (name, version, deps) { 44MochiKit.Base.module = function (parent, name, version, deps) {
33 if (!(name in MochiKit)) { 45 var module = parent[name] = parent[name] || {};
34 MochiKit[name] = {}; 46 var prefix = (parent.NAME ? parent.NAME + "." : "");
35 } 47 module.NAME = prefix + name;
36 var module = MochiKit[name];
37 module.NAME = "MochiKit." + name;
38 module.VERSION = version; 48 module.VERSION = version;
39 module.__repr__ = function () { 49 module.__repr__ = function () {
40 return "[" + this.NAME + " " + this.VERSION + "]"; 50 return "[" + this.NAME + " " + this.VERSION + "]";
41 }; 51 };
42 module.toString = function () { 52 module.toString = function () {
43 return this.__repr__(); 53 return this.__repr__();
44 }; 54 };
45 for (var i = 0; i < deps.length; i++) { 55 for (var i = 0; deps != null && i < deps.length; i++) {
46 if (!(deps[i] in MochiKit)) { 56 if (!(deps[i] in parent)) {
47 throw 'MochiKit.' + name + ' depends on MochiKit.' + deps[i] + '!'; 57 throw module.NAME + ' depends on ' + prefix + deps[i] + '!';
48 } 58 }
49 } 59 }
50} 60 return module;
61};
51 62
52MochiKit.Base._module("Base", "1.5", []); 63MochiKit.Base.module(MochiKit, "Base", "1.5", []);
53 64
54/** @id MochiKit.Base.update */ 65/** @id MochiKit.Base.update */
55MochiKit.Base.update = function (self, obj/*, ... */) { 66MochiKit.Base.update = function (self, obj/*, ... */) {
56 if (self === null || self === undefined) { 67 if (self === null || self === undefined) {
57 self = {}; 68 self = {};
58 } 69 }
59 for (var i = 1; i < arguments.length; i++) { 70 for (var i = 1; i < arguments.length; i++) {
60 var o = arguments[i]; 71 var o = arguments[i];
61 if (typeof(o) != 'undefined' && o !== null) { 72 if (typeof(o) != 'undefined' && o !== null) {
62 for (var k in o) { 73 for (var k in o) {
63 self[k] = o[k]; 74 self[k] = o[k];
64 } 75 }
65 } 76 }
66 } 77 }
67 return self; 78 return self;
68}; 79};
69 80
70MochiKit.Base.update(MochiKit.Base, { 81MochiKit.Base.update(MochiKit.Base, {
71 /** @id MochiKit.Base.camelize */ 82 /** @id MochiKit.Base.camelize */
72 camelize: function (selector) { 83 camelize: function (selector) {
73 /* from dojo.style.toCamelCase */ 84 /* from dojo.style.toCamelCase */
74 var arr = selector.split('-'); 85 var arr = selector.split('-');
75 var cc = arr[0]; 86 var cc = arr[0];
76 for (var i = 1; i < arr.length; i++) { 87 for (var i = 1; i < arr.length; i++) {
77 cc += arr[i].charAt(0).toUpperCase() + arr[i].substring(1); 88 cc += arr[i].charAt(0).toUpperCase() + arr[i].substring(1);
78 } 89 }
79 return cc; 90 return cc;
80 }, 91 },
81 92
82 /** @id MochiKit.Base.counter */ 93 /** @id MochiKit.Base.counter */
83 counter: function (n/* = 1 */) { 94 counter: function (n/* = 1 */) {
84 if (arguments.length === 0) { 95 if (arguments.length === 0) {
85 n = 1; 96 n = 1;
86 } 97 }
87 return function () { 98 return function () {
88 return n++; 99 return n++;
89 }; 100 };
90 }, 101 },
91 102
92 /** @id MochiKit.Base.clone */ 103 /** @id MochiKit.Base.clone */
93 clone: function (obj) { 104 clone: function (obj) {
94 var me = arguments.callee; 105 var me = arguments.callee;
95 if (arguments.length == 1) { 106 if (arguments.length == 1) {
96 me.prototype = obj; 107 me.prototype = obj;
97 return new me(); 108 return new me();
98 } 109 }
99 }, 110 },
100 111
101 _flattenArray: function (res, lst) { 112 _flattenArray: function (res, lst) {
102 for (var i = 0; i < lst.length; i++) { 113 for (var i = 0; i < lst.length; i++) {
103 var o = lst[i]; 114 var o = lst[i];
104 if (o instanceof Array) { 115 if (o instanceof Array) {
105 arguments.callee(res, o); 116 arguments.callee(res, o);
106 } else { 117 } else {
107 res.push(o); 118 res.push(o);
108 } 119 }
109 } 120 }
110 return res; 121 return res;
111 }, 122 },
112 123
113 /** @id MochiKit.Base.flattenArray */ 124 /** @id MochiKit.Base.flattenArray */
114 flattenArray: function (lst) { 125 flattenArray: function (lst) {
115 return MochiKit.Base._flattenArray([], lst); 126 return MochiKit.Base._flattenArray([], lst);
116 }, 127 },
117 128
118 /** @id MochiKit.Base.flattenArguments */ 129 /** @id MochiKit.Base.flattenArguments */
119 flattenArguments: function (lst/* ...*/) { 130 flattenArguments: function (lst/* ...*/) {
120 var res = []; 131 var res = [];
121 var m = MochiKit.Base; 132 var m = MochiKit.Base;
122 var args = m.extend(null, arguments); 133 var args = m.extend(null, arguments);
123 while (args.length) { 134 while (args.length) {
124 var o = args.shift(); 135 var o = args.shift();
125 if (o && typeof(o) == "object" && typeof(o.length) == "number") { 136 if (o && typeof(o) == "object" && typeof(o.length) == "number") {
126 for (var i = o.length - 1; i >= 0; i--) { 137 for (var i = o.length - 1; i >= 0; i--) {
127 args.unshift(o[i]); 138 args.unshift(o[i]);
128 } 139 }
129 } else { 140 } else {
130 res.push(o); 141 res.push(o);
131 } 142 }
132 } 143 }
133 return res; 144 return res;
134 }, 145 },
135 146
136 /** @id MochiKit.Base.extend */ 147 /** @id MochiKit.Base.extend */
137 extend: function (self, obj, /* optional */skip) { 148 extend: function (self, obj, /* optional */skip) {
138 // Extend an array with an array-like object starting 149 // Extend an array with an array-like object starting
139 // from the skip index 150 // from the skip index
140 if (!skip) { 151 if (!skip) {
141 skip = 0; 152 skip = 0;
142 } 153 }
143 if (obj) { 154 if (obj) {
144 // allow iterable fall-through, but skip the full isArrayLike 155 // allow iterable fall-through, but skip the full isArrayLike
145 // check for speed, this is called often. 156 // check for speed, this is called often.
146 var l = obj.length; 157 var l = obj.length;
147 if (typeof(l) != 'number' /* !isArrayLike(obj) */) { 158 if (typeof(l) != 'number' /* !isArrayLike(obj) */) {
148 if (typeof(MochiKit.Iter) != "undefined") { 159 if (typeof(MochiKit.Iter) != "undefined") {
149 obj = MochiKit.Iter.list(obj); 160 obj = MochiKit.Iter.list(obj);
150 l = obj.length; 161 l = obj.length;
151 } else { 162 } else {
152 throw new TypeError("Argument not an array-like and MochiKit.Iter not present"); 163 throw new TypeError("Argument not an array-like and MochiKit.Iter not present");
153 } 164 }
154 } 165 }
155 if (!self) { 166 if (!self) {
156 self = []; 167 self = [];
157 } 168 }
158 for (var i = skip; i < l; i++) { 169 for (var i = skip; i < l; i++) {
159 self.push(obj[i]); 170 self.push(obj[i]);
160 } 171 }
161 } 172 }
162 // This mutates, but it's convenient to return because 173 // This mutates, but it's convenient to return because
163 // it's often used like a constructor when turning some 174 // it's often used like a constructor when turning some
164 // ghetto array-like to a real array 175 // ghetto array-like to a real array
165 return self; 176 return self;
166 }, 177 },
167 178
168 179
169 /** @id MochiKit.Base.updatetree */ 180 /** @id MochiKit.Base.updatetree */
170 updatetree: function (self, obj/*, ...*/) { 181 updatetree: function (self, obj/*, ...*/) {
171 if (self === null || self === undefined) { 182 if (self === null || self === undefined) {
172 self = {}; 183 self = {};
173 } 184 }
174 for (var i = 1; i < arguments.length; i++) { 185 for (var i = 1; i < arguments.length; i++) {
175 var o = arguments[i]; 186 var o = arguments[i];
176 if (typeof(o) != 'undefined' && o !== null) { 187 if (typeof(o) != 'undefined' && o !== null) {
177 for (var k in o) { 188 for (var k in o) {
178 var v = o[k]; 189 var v = o[k];
179 if (typeof(self[k]) == 'object' && typeof(v) == 'object') { 190 if (typeof(self[k]) == 'object' && typeof(v) == 'object') {
180 arguments.callee(self[k], v); 191 arguments.callee(self[k], v);
181 } else { 192 } else {
182 self[k] = v; 193 self[k] = v;
183 } 194 }
184 } 195 }
185 } 196 }
186 } 197 }
187 return self; 198 return self;
188 }, 199 },
189 200
190 /** @id MochiKit.Base.setdefault */ 201 /** @id MochiKit.Base.setdefault */
191 setdefault: function (self, obj/*, ...*/) { 202 setdefault: function (self, obj/*, ...*/) {
192 if (self === null || self === undefined) { 203 if (self === null || self === undefined) {
193 self = {}; 204 self = {};
194 } 205 }
195 for (var i = 1; i < arguments.length; i++) { 206 for (var i = 1; i < arguments.length; i++) {
196 var o = arguments[i]; 207 var o = arguments[i];
197 for (var k in o) { 208 for (var k in o) {
198 if (!(k in self)) { 209 if (!(k in self)) {
199 self[k] = o[k]; 210 self[k] = o[k];
200 } 211 }
201 } 212 }
202 } 213 }
203 return self; 214 return self;
204 }, 215 },
205 216
206 /** @id MochiKit.Base.keys */ 217 /** @id MochiKit.Base.keys */
207 keys: function (obj) { 218 keys: function (obj) {
208 var rval = []; 219 var rval = [];
209 for (var prop in obj) { 220 for (var prop in obj) {
210 rval.push(prop); 221 rval.push(prop);
211 } 222 }
212 return rval; 223 return rval;
213 }, 224 },
214 225
215 /** @id MochiKit.Base.values */ 226 /** @id MochiKit.Base.values */
216 values: function (obj) { 227 values: function (obj) {
217 var rval = []; 228 var rval = [];
218 for (var prop in obj) { 229 for (var prop in obj) {
219 rval.push(obj[prop]); 230 rval.push(obj[prop]);
220 } 231 }
221 return rval; 232 return rval;
222 }, 233 },
223 234
224 /** @id MochiKit.Base.items */ 235 /** @id MochiKit.Base.items */
225 items: function (obj) { 236 items: function (obj) {
226 var rval = []; 237 var rval = [];
227 var e; 238 var e;
228 for (var prop in obj) { 239 for (var prop in obj) {
229 var v; 240 var v;
230 try { 241 try {
231 v = obj[prop]; 242 v = obj[prop];
232 } catch (e) { 243 } catch (e) {
233 continue; 244 continue;
234 } 245 }
235 rval.push([prop, v]); 246 rval.push([prop, v]);
236 } 247 }
237 return rval; 248 return rval;
238 }, 249 },
239 250
240 251
241 _newNamedError: function (module, name, func) { 252 _newNamedError: function (module, name, func) {
242 func.prototype = new MochiKit.Base.NamedError(module.NAME + "." + name); 253 func.prototype = new MochiKit.Base.NamedError(module.NAME + "." + name);
254 func.prototype.constructor = func;
243 module[name] = func; 255 module[name] = func;
244 }, 256 },
245 257
246 258
247 /** @id MochiKit.Base.operator */ 259 /** @id MochiKit.Base.operator */
248 operator: { 260 operator: {
249 // unary logic operators 261 // unary logic operators
250 /** @id MochiKit.Base.truth */ 262 /** @id MochiKit.Base.truth */
251 truth: function (a) { return !!a; }, 263 truth: function (a) { return !!a; },
252 /** @id MochiKit.Base.lognot */ 264 /** @id MochiKit.Base.lognot */
253 lognot: function (a) { return !a; }, 265 lognot: function (a) { return !a; },
254 /** @id MochiKit.Base.identity */ 266 /** @id MochiKit.Base.identity */
255 identity: function (a) { return a; }, 267 identity: function (a) { return a; },
256 268
257 // bitwise unary operators 269 // bitwise unary operators
258 /** @id MochiKit.Base.not */ 270 /** @id MochiKit.Base.not */
259 not: function (a) { return ~a; }, 271 not: function (a) { return ~a; },
260 /** @id MochiKit.Base.neg */ 272 /** @id MochiKit.Base.neg */
261 neg: function (a) { return -a; }, 273 neg: function (a) { return -a; },
262 274
263 // binary operators 275 // binary operators
264 /** @id MochiKit.Base.add */ 276 /** @id MochiKit.Base.add */
265 add: function (a, b) { return a + b; }, 277 add: function (a, b) { return a + b; },
266 /** @id MochiKit.Base.sub */ 278 /** @id MochiKit.Base.sub */
267 sub: function (a, b) { return a - b; }, 279 sub: function (a, b) { return a - b; },
268 /** @id MochiKit.Base.div */ 280 /** @id MochiKit.Base.div */
269 div: function (a, b) { return a / b; }, 281 div: function (a, b) { return a / b; },
270 /** @id MochiKit.Base.mod */ 282 /** @id MochiKit.Base.mod */
271 mod: function (a, b) { return a % b; }, 283 mod: function (a, b) { return a % b; },
272 /** @id MochiKit.Base.mul */ 284 /** @id MochiKit.Base.mul */
273 mul: function (a, b) { return a * b; }, 285 mul: function (a, b) { return a * b; },
274 286
275 // bitwise binary operators 287 // bitwise binary operators
276 /** @id MochiKit.Base.and */ 288 /** @id MochiKit.Base.and */
277 and: function (a, b) { return a & b; }, 289 and: function (a, b) { return a & b; },
278 /** @id MochiKit.Base.or */ 290 /** @id MochiKit.Base.or */
279 or: function (a, b) { return a | b; }, 291 or: function (a, b) { return a | b; },
280 /** @id MochiKit.Base.xor */ 292 /** @id MochiKit.Base.xor */
281 xor: function (a, b) { return a ^ b; }, 293 xor: function (a, b) { return a ^ b; },
282 /** @id MochiKit.Base.lshift */ 294 /** @id MochiKit.Base.lshift */
283 lshift: function (a, b) { return a << b; }, 295 lshift: function (a, b) { return a << b; },
284 /** @id MochiKit.Base.rshift */ 296 /** @id MochiKit.Base.rshift */
285 rshift: function (a, b) { return a >> b; }, 297 rshift: function (a, b) { return a >> b; },
286 /** @id MochiKit.Base.zrshift */ 298 /** @id MochiKit.Base.zrshift */
287 zrshift: function (a, b) { return a >>> b; }, 299 zrshift: function (a, b) { return a >>> b; },
288 300
289 // near-worthless built-in comparators 301 // near-worthless built-in comparators
290 /** @id MochiKit.Base.eq */ 302 /** @id MochiKit.Base.eq */
291 eq: function (a, b) { return a == b; }, 303 eq: function (a, b) { return a == b; },
292 /** @id MochiKit.Base.ne */ 304 /** @id MochiKit.Base.ne */
293 ne: function (a, b) { return a != b; }, 305 ne: function (a, b) { return a != b; },
294 /** @id MochiKit.Base.gt */ 306 /** @id MochiKit.Base.gt */
295 gt: function (a, b) { return a > b; }, 307 gt: function (a, b) { return a > b; },
296 /** @id MochiKit.Base.ge */ 308 /** @id MochiKit.Base.ge */
297 ge: function (a, b) { return a >= b; }, 309 ge: function (a, b) { return a >= b; },
298 /** @id MochiKit.Base.lt */ 310 /** @id MochiKit.Base.lt */
299 lt: function (a, b) { return a < b; }, 311 lt: function (a, b) { return a < b; },
300 /** @id MochiKit.Base.le */ 312 /** @id MochiKit.Base.le */
301 le: function (a, b) { return a <= b; }, 313 le: function (a, b) { return a <= b; },
302 314
303 // strict built-in comparators 315 // strict built-in comparators
304 seq: function (a, b) { return a === b; }, 316 seq: function (a, b) { return a === b; },
305 sne: function (a, b) { return a !== b; }, 317 sne: function (a, b) { return a !== b; },
306 318
307 // compare comparators 319 // compare comparators
308 /** @id MochiKit.Base.ceq */ 320 /** @id MochiKit.Base.ceq */
309 ceq: function (a, b) { return MochiKit.Base.compare(a, b) === 0; }, 321 ceq: function (a, b) { return MochiKit.Base.compare(a, b) === 0; },
310 /** @id MochiKit.Base.cne */ 322 /** @id MochiKit.Base.cne */
311 cne: function (a, b) { return MochiKit.Base.compare(a, b) !== 0; }, 323 cne: function (a, b) { return MochiKit.Base.compare(a, b) !== 0; },
312 /** @id MochiKit.Base.cgt */ 324 /** @id MochiKit.Base.cgt */
313 cgt: function (a, b) { return MochiKit.Base.compare(a, b) == 1; }, 325 cgt: function (a, b) { return MochiKit.Base.compare(a, b) == 1; },
314 /** @id MochiKit.Base.cge */ 326 /** @id MochiKit.Base.cge */
315 cge: function (a, b) { return MochiKit.Base.compare(a, b) != -1; }, 327 cge: function (a, b) { return MochiKit.Base.compare(a, b) != -1; },
316 /** @id MochiKit.Base.clt */ 328 /** @id MochiKit.Base.clt */
317 clt: function (a, b) { return MochiKit.Base.compare(a, b) == -1; }, 329 clt: function (a, b) { return MochiKit.Base.compare(a, b) == -1; },
318 /** @id MochiKit.Base.cle */ 330 /** @id MochiKit.Base.cle */
319 cle: function (a, b) { return MochiKit.Base.compare(a, b) != 1; }, 331 cle: function (a, b) { return MochiKit.Base.compare(a, b) != 1; },
320 332
321 // binary logical operators 333 // binary logical operators
322 /** @id MochiKit.Base.logand */ 334 /** @id MochiKit.Base.logand */
323 logand: function (a, b) { return a && b; }, 335 logand: function (a, b) { return a && b; },
324 /** @id MochiKit.Base.logor */ 336 /** @id MochiKit.Base.logor */
325 logor: function (a, b) { return a || b; }, 337 logor: function (a, b) { return a || b; },
326 /** @id MochiKit.Base.contains */ 338 /** @id MochiKit.Base.contains */
327 contains: function (a, b) { return b in a; } 339 contains: function (a, b) { return b in a; }
328 }, 340 },
329 341
330 /** @id MochiKit.Base.forwardCall */ 342 /** @id MochiKit.Base.forwardCall */
331 forwardCall: function (func) { 343 forwardCall: function (func) {
332 return function () { 344 return function () {
333 return this[func].apply(this, arguments); 345 return this[func].apply(this, arguments);
334 }; 346 };
335 }, 347 },
336 348
337 /** @id MochiKit.Base.itemgetter */ 349 /** @id MochiKit.Base.itemgetter */
338 itemgetter: function (func) { 350 itemgetter: function (func) {
339 return function (arg) { 351 return function (arg) {
340 return arg[func]; 352 return arg[func];
341 }; 353 };
342 }, 354 },
343 355
344 /** @id MochiKit.Base.bool */ 356 /** @id MochiKit.Base.bool */
345 bool: function (value) { 357 bool: function (value) {
346 if (typeof(value) === "boolean" || value instanceof Boolean) { 358 if (typeof(value) === "boolean" || value instanceof Boolean) {
347 return value.valueOf(); 359 return value.valueOf();
348 } else if (typeof(value) === "string" || value instanceof String) { 360 } else if (typeof(value) === "string" || value instanceof String) {
349 return value.length > 0 && value != "false" && value != "null" && 361 return value.length > 0 && value != "false" && value != "null" &&
350 value != "undefined" && value != "0"; 362 value != "undefined" && value != "0";
351 } else if (typeof(value) === "number" || value instanceof Number) { 363 } else if (typeof(value) === "number" || value instanceof Number) {
352 return !isNaN(value) && value != 0; 364 return !isNaN(value) && value != 0;
353 } else if (value != null && typeof(value.length) === "number") { 365 } else if (value != null && typeof(value.length) === "number") {
354 return value.length !== 0 366 return value.length !== 0;
355 } else { 367 } else {
356 return value != null; 368 return value != null;
357 } 369 }
358 }, 370 },
359 371
360 /** @id MochiKit.Base.typeMatcher */ 372 /** @id MochiKit.Base.typeMatcher */
361 typeMatcher: function (/* typ */) { 373 typeMatcher: function (/* typ */) {
362 var types = {}; 374 var types = {};
363 for (var i = 0; i < arguments.length; i++) { 375 for (var i = 0; i < arguments.length; i++) {
364 var typ = arguments[i]; 376 var typ = arguments[i];
365 types[typ] = typ; 377 types[typ] = typ;
366 } 378 }
367 return function () { 379 return function () {
368 for (var i = 0; i < arguments.length; i++) { 380 for (var i = 0; i < arguments.length; i++) {
369 if (!(typeof(arguments[i]) in types)) { 381 if (!(typeof(arguments[i]) in types)) {
370 return false; 382 return false;
371 } 383 }
372 } 384 }
373 return true; 385 return true;
374 }; 386 };
375 }, 387 },
376 388
377 /** @id MochiKit.Base.isNull */ 389 /** @id MochiKit.Base.isNull */
378 isNull: function (/* ... */) { 390 isNull: function (/* ... */) {
379 for (var i = 0; i < arguments.length; i++) { 391 for (var i = 0; i < arguments.length; i++) {
380 if (arguments[i] !== null) { 392 if (arguments[i] !== null) {
381 return false; 393 return false;
382 } 394 }
383 } 395 }
384 return true; 396 return true;
385 }, 397 },
386 398
387 /** @id MochiKit.Base.isUndefinedOrNull */ 399 /** @id MochiKit.Base.isUndefinedOrNull */
388 isUndefinedOrNull: function (/* ... */) { 400 isUndefinedOrNull: function (/* ... */) {
389 for (var i = 0; i < arguments.length; i++) { 401 for (var i = 0; i < arguments.length; i++) {
390 var o = arguments[i]; 402 var o = arguments[i];
391 if (!(typeof(o) == 'undefined' || o === null)) { 403 if (!(typeof(o) == 'undefined' || o === null)) {
392 return false; 404 return false;
393 } 405 }
394 } 406 }
395 return true; 407 return true;
396 }, 408 },
397 409
398 /** @id MochiKit.Base.isEmpty */ 410 /** @id MochiKit.Base.isEmpty */
399 isEmpty: function (obj) { 411 isEmpty: function (obj) {
400 return !MochiKit.Base.isNotEmpty.apply(this, arguments); 412 return !MochiKit.Base.isNotEmpty.apply(this, arguments);
401 }, 413 },
402 414
403 /** @id MochiKit.Base.isNotEmpty */ 415 /** @id MochiKit.Base.isNotEmpty */
404 isNotEmpty: function (obj) { 416 isNotEmpty: function (obj) {
405 for (var i = 0; i < arguments.length; i++) { 417 for (var i = 0; i < arguments.length; i++) {
406 var o = arguments[i]; 418 var o = arguments[i];
407 if (!(o && o.length)) { 419 if (!(o && o.length)) {
408 return false; 420 return false;
409 } 421 }
410 } 422 }
411 return true; 423 return true;
412 }, 424 },
413 425
414 /** @id MochiKit.Base.isArrayLike */ 426 /** @id MochiKit.Base.isArrayLike */
415 isArrayLike: function () { 427 isArrayLike: function () {
416 for (var i = 0; i < arguments.length; i++) { 428 for (var i = 0; i < arguments.length; i++) {
417 var o = arguments[i]; 429 var o = arguments[i];
418 var typ = typeof(o); 430 var typ = typeof(o);
419 if ( 431 if (
420 (typ != 'object' && !(typ == 'function' && typeof(o.item) == 'function')) || 432 (typ != 'object' && !(typ == 'function' && typeof(o.item) == 'function')) ||
421 o === null || 433 o === null ||
422 typeof(o.length) != 'number' || 434 typeof(o.length) != 'number' ||
423 o.nodeType === 3 || 435 o.nodeType === 3 ||
424 o.nodeType === 4 436 o.nodeType === 4
425 ) { 437 ) {
426 return false; 438 return false;
427 } 439 }
428 } 440 }
429 return true; 441 return true;
430 }, 442 },
431 443
432 /** @id MochiKit.Base.isDateLike */ 444 /** @id MochiKit.Base.isDateLike */
433 isDateLike: function () { 445 isDateLike: function () {
434 for (var i = 0; i < arguments.length; i++) { 446 for (var i = 0; i < arguments.length; i++) {
435 var o = arguments[i]; 447 var o = arguments[i];
436 if (typeof(o) != "object" || o === null 448 if (typeof(o) != "object" || o === null
437 || typeof(o.getTime) != 'function') { 449 || typeof(o.getTime) != 'function') {
438 return false; 450 return false;
439 } 451 }
440 } 452 }
441 return true; 453 return true;
442 }, 454 },
443 455
444 456
445 /** @id MochiKit.Base.xmap */ 457 /** @id MochiKit.Base.xmap */
446 xmap: function (fn/*, obj... */) { 458 xmap: function (fn/*, obj... */) {
447 if (fn === null) { 459 if (fn === null) {
448 return MochiKit.Base.extend(null, arguments, 1); 460 return MochiKit.Base.extend(null, arguments, 1);
449 } 461 }
450 var rval = []; 462 var rval = [];
@@ -582,411 +594,420 @@ MochiKit.Base.update(MochiKit.Base, {
582 case 2: return func(arguments[0], arguments[1]); 594 case 2: return func(arguments[0], arguments[1]);
583 case 3: return func(arguments[0], arguments[1], arguments[2]); 595 case 3: return func(arguments[0], arguments[1], arguments[2]);
584 } 596 }
585 var args = []; 597 var args = [];
586 for (var i = 0; i < arguments.length; i++) { 598 for (var i = 0; i < arguments.length; i++) {
587 args.push("arguments[" + i + "]"); 599 args.push("arguments[" + i + "]");
588 } 600 }
589 return eval("(func(" + args.join(",") + "))"); 601 return eval("(func(" + args.join(",") + "))");
590 }; 602 };
591 }, 603 },
592 604
593 /** @id MochiKit.Base.methodcaller */ 605 /** @id MochiKit.Base.methodcaller */
594 methodcaller: function (func/*, args... */) { 606 methodcaller: function (func/*, args... */) {
595 var args = MochiKit.Base.extend(null, arguments, 1); 607 var args = MochiKit.Base.extend(null, arguments, 1);
596 if (typeof(func) == "function") { 608 if (typeof(func) == "function") {
597 return function (obj) { 609 return function (obj) {
598 return func.apply(obj, args); 610 return func.apply(obj, args);
599 }; 611 };
600 } else { 612 } else {
601 return function (obj) { 613 return function (obj) {
602 return obj[func].apply(obj, args); 614 return obj[func].apply(obj, args);
603 }; 615 };
604 } 616 }
605 }, 617 },
606 618
607 /** @id MochiKit.Base.method */ 619 /** @id MochiKit.Base.method */
608 method: function (self, func) { 620 method: function (self, func) {
609 var m = MochiKit.Base; 621 var m = MochiKit.Base;
610 return m.bind.apply(this, m.extend([func, self], arguments, 2)); 622 return m.bind.apply(this, m.extend([func, self], arguments, 2));
611 }, 623 },
612 624
613 /** @id MochiKit.Base.compose */ 625 /** @id MochiKit.Base.compose */
614 compose: function (f1, f2/*, f3, ... fN */) { 626 compose: function (f1, f2/*, f3, ... fN */) {
615 var fnlist = []; 627 var fnlist = [];
616 var m = MochiKit.Base; 628 var m = MochiKit.Base;
617 if (arguments.length === 0) { 629 if (arguments.length === 0) {
618 throw new TypeError("compose() requires at least one argument"); 630 throw new TypeError("compose() requires at least one argument");
619 } 631 }
620 for (var i = 0; i < arguments.length; i++) { 632 for (var i = 0; i < arguments.length; i++) {
621 var fn = arguments[i]; 633 var fn = arguments[i];
622 if (typeof(fn) != "function") { 634 if (typeof(fn) != "function") {
623 throw new TypeError(m.repr(fn) + " is not a function"); 635 throw new TypeError(m.repr(fn) + " is not a function");
624 } 636 }
625 fnlist.push(fn); 637 fnlist.push(fn);
626 } 638 }
627 return function () { 639 return function () {
628 var args = arguments; 640 var args = arguments;
629 for (var i = fnlist.length - 1; i >= 0; i--) { 641 for (var i = fnlist.length - 1; i >= 0; i--) {
630 args = [fnlist[i].apply(this, args)]; 642 args = [fnlist[i].apply(this, args)];
631 } 643 }
632 return args[0]; 644 return args[0];
633 }; 645 };
634 }, 646 },
635 647
636 /** @id MochiKit.Base.bind */ 648 /** @id MochiKit.Base.bind */
637 bind: function (func, self/* args... */) { 649 bind: function (func, self/* args... */) {
638 if (typeof(func) == "string") { 650 if (typeof(func) == "string") {
639 func = self[func]; 651 func = self[func];
640 } 652 }
641 var im_func = func.im_func; 653 var im_func = func.im_func;
642 var im_preargs = func.im_preargs; 654 var im_preargs = func.im_preargs;
643 var im_self = func.im_self; 655 var im_self = func.im_self;
644 var m = MochiKit.Base; 656 var m = MochiKit.Base;
645 if (typeof(func) == "function" && typeof(func.apply) == "undefined") { 657 if (typeof(func) == "function" && typeof(func.apply) == "undefined") {
646 // this is for cases where JavaScript sucks ass and gives you a 658 // this is for cases where JavaScript sucks ass and gives you a
647 // really dumb built-in function like alert() that doesn't have 659 // really dumb built-in function like alert() that doesn't have
648 // an apply 660 // an apply
649 func = m._wrapDumbFunction(func); 661 func = m._wrapDumbFunction(func);
650 } 662 }
651 if (typeof(im_func) != 'function') { 663 if (typeof(im_func) != 'function') {
652 im_func = func; 664 im_func = func;
653 } 665 }
654 if (typeof(self) != 'undefined') { 666 if (typeof(self) != 'undefined') {
655 im_self = self; 667 im_self = self;
656 } 668 }
657 if (typeof(im_preargs) == 'undefined') { 669 if (typeof(im_preargs) == 'undefined') {
658 im_preargs = []; 670 im_preargs = [];
659 } else { 671 } else {
660 im_preargs = im_preargs.slice(); 672 im_preargs = im_preargs.slice();
661 } 673 }
662 m.extend(im_preargs, arguments, 2); 674 m.extend(im_preargs, arguments, 2);
663 var newfunc = function () { 675 var newfunc = function () {
664 var args = arguments; 676 var args = arguments;
665 var me = arguments.callee; 677 var me = arguments.callee;
666 if (me.im_preargs.length > 0) { 678 if (me.im_preargs.length > 0) {
667 args = m.concat(me.im_preargs, args); 679 args = m.concat(me.im_preargs, args);
668 } 680 }
669 var self = me.im_self; 681 var self = me.im_self;
670 if (!self) { 682 if (!self) {
671 self = this; 683 self = this;
672 } 684 }
673 return me.im_func.apply(self, args); 685 return me.im_func.apply(self, args);
674 }; 686 };
675 newfunc.im_self = im_self; 687 newfunc.im_self = im_self;
676 newfunc.im_func = im_func; 688 newfunc.im_func = im_func;
677 newfunc.im_preargs = im_preargs; 689 newfunc.im_preargs = im_preargs;
690 if (typeof(im_func.NAME) == 'string') {
691 newfunc.NAME = "bind(" + im_func.NAME + ",...)";
692 }
678 return newfunc; 693 return newfunc;
679 }, 694 },
680 695
681 /** @id MochiKit.Base.bindLate */ 696 /** @id MochiKit.Base.bindLate */
682 bindLate: function (func, self/* args... */) { 697 bindLate: function (func, self/* args... */) {
683 var m = MochiKit.Base; 698 var m = MochiKit.Base;
684 var args = arguments; 699 var args = arguments;
685 if (typeof(func) === "string") { 700 if (typeof(func) === "string") {
686 args = m.extend([m.forwardCall(func)], arguments, 1); 701 args = m.extend([m.forwardCall(func)], arguments, 1);
687 return m.bind.apply(this, args); 702 return m.bind.apply(this, args);
688 } 703 }
689 return m.bind.apply(this, args); 704 return m.bind.apply(this, args);
690 }, 705 },
691 706
692 /** @id MochiKit.Base.bindMethods */ 707 /** @id MochiKit.Base.bindMethods */
693 bindMethods: function (self) { 708 bindMethods: function (self) {
694 var bind = MochiKit.Base.bind; 709 var bind = MochiKit.Base.bind;
695 for (var k in self) { 710 for (var k in self) {
696 var func = self[k]; 711 var func = self[k];
697 if (typeof(func) == 'function') { 712 if (typeof(func) == 'function') {
698 self[k] = bind(func, self); 713 self[k] = bind(func, self);
699 } 714 }
700 } 715 }
701 }, 716 },
702 717
703 /** @id MochiKit.Base.registerComparator */ 718 /** @id MochiKit.Base.registerComparator */
704 registerComparator: function (name, check, comparator, /* optional */ override) { 719 registerComparator: function (name, check, comparator, /* optional */ override) {
705 MochiKit.Base.comparatorRegistry.register(name, check, comparator, override); 720 MochiKit.Base.comparatorRegistry.register(name, check, comparator, override);
706 }, 721 },
707 722
708 _primitives: {'boolean': true, 'string': true, 'number': true}, 723 _primitives: {'boolean': true, 'string': true, 'number': true},
709 724
710 /** @id MochiKit.Base.compare */ 725 /** @id MochiKit.Base.compare */
711 compare: function (a, b) { 726 compare: function (a, b) {
712 if (a == b) { 727 if (a == b) {
713 return 0; 728 return 0;
714 } 729 }
715 var aIsNull = (typeof(a) == 'undefined' || a === null); 730 var aIsNull = (typeof(a) == 'undefined' || a === null);
716 var bIsNull = (typeof(b) == 'undefined' || b === null); 731 var bIsNull = (typeof(b) == 'undefined' || b === null);
717 if (aIsNull && bIsNull) { 732 if (aIsNull && bIsNull) {
718 return 0; 733 return 0;
719 } else if (aIsNull) { 734 } else if (aIsNull) {
720 return -1; 735 return -1;
721 } else if (bIsNull) { 736 } else if (bIsNull) {
722 return 1; 737 return 1;
723 } 738 }
724 var m = MochiKit.Base; 739 var m = MochiKit.Base;
725 // bool, number, string have meaningful comparisons 740 // bool, number, string have meaningful comparisons
726 var prim = m._primitives; 741 var prim = m._primitives;
727 if (!(typeof(a) in prim && typeof(b) in prim)) { 742 if (!(typeof(a) in prim && typeof(b) in prim)) {
728 try { 743 try {
729 return m.comparatorRegistry.match(a, b); 744 return m.comparatorRegistry.match(a, b);
730 } catch (e) { 745 } catch (e) {
731 if (e != m.NotFound) { 746 if (e != m.NotFound) {
732 throw e; 747 throw e;
733 } 748 }
734 } 749 }
735 } 750 }
736 if (a < b) { 751 if (a < b) {
737 return -1; 752 return -1;
738 } else if (a > b) { 753 } else if (a > b) {
739 return 1; 754 return 1;
740 } 755 }
741 // These types can't be compared 756 // These types can't be compared
742 var repr = m.repr; 757 var repr = m.repr;
743 throw new TypeError(repr(a) + " and " + repr(b) + " can not be compared"); 758 throw new TypeError(repr(a) + " and " + repr(b) + " can not be compared");
744 }, 759 },
745 760
746 /** @id MochiKit.Base.compareDateLike */ 761 /** @id MochiKit.Base.compareDateLike */
747 compareDateLike: function (a, b) { 762 compareDateLike: function (a, b) {
748 return MochiKit.Base.compare(a.getTime(), b.getTime()); 763 return MochiKit.Base.compare(a.getTime(), b.getTime());
749 }, 764 },
750 765
751 /** @id MochiKit.Base.compareArrayLike */ 766 /** @id MochiKit.Base.compareArrayLike */
752 compareArrayLike: function (a, b) { 767 compareArrayLike: function (a, b) {
753 var compare = MochiKit.Base.compare; 768 var compare = MochiKit.Base.compare;
754 var count = a.length; 769 var count = a.length;
755 var rval = 0; 770 var rval = 0;
756 if (count > b.length) { 771 if (count > b.length) {
757 rval = 1; 772 rval = 1;
758 count = b.length; 773 count = b.length;
759 } else if (count < b.length) { 774 } else if (count < b.length) {
760 rval = -1; 775 rval = -1;
761 } 776 }
762 for (var i = 0; i < count; i++) { 777 for (var i = 0; i < count; i++) {
763 var cmp = compare(a[i], b[i]); 778 var cmp = compare(a[i], b[i]);
764 if (cmp) { 779 if (cmp) {
765 return cmp; 780 return cmp;
766 } 781 }
767 } 782 }
768 return rval; 783 return rval;
769 }, 784 },
770 785
771 /** @id MochiKit.Base.registerRepr */ 786 /** @id MochiKit.Base.registerRepr */
772 registerRepr: function (name, check, wrap, /* optional */override) { 787 registerRepr: function (name, check, wrap, /* optional */override) {
773 MochiKit.Base.reprRegistry.register(name, check, wrap, override); 788 MochiKit.Base.reprRegistry.register(name, check, wrap, override);
774 }, 789 },
775 790
776 /** @id MochiKit.Base.repr */ 791 /** @id MochiKit.Base.repr */
777 repr: function (o) { 792 repr: function (o) {
778 if (typeof(o) == "undefined") { 793 if (typeof(o) == "undefined") {
779 return "undefined"; 794 return "undefined";
780 } else if (o === null) { 795 } else if (o === null) {
781 return "null"; 796 return "null";
782 } 797 }
783 try { 798 try {
784 if (typeof(o.__repr__) == 'function') { 799 if (typeof(o.__repr__) == 'function') {
785 return o.__repr__(); 800 return o.__repr__();
786 } else if (typeof(o.repr) == 'function' && o.repr != arguments.callee) { 801 } else if (typeof(o.repr) == 'function' && o.repr != arguments.callee) {
787 return o.repr(); 802 return o.repr();
788 } 803 }
789 return MochiKit.Base.reprRegistry.match(o); 804 return MochiKit.Base.reprRegistry.match(o);
790 } catch (e) { 805 } catch (e) {
791 if (typeof(o.NAME) == 'string' && ( 806 try {
792 o.toString == Function.prototype.toString || 807 if (typeof(o.NAME) == 'string' && (
793 o.toString == Object.prototype.toString 808 o.toString == Function.prototype.toString ||
794 )) { 809 o.toString == Object.prototype.toString
795 return o.NAME; 810 )) {
811 return o.NAME;
812 }
813 } catch (ignore) {
796 } 814 }
797 } 815 }
798 try { 816 try {
799 var ostring = (o + ""); 817 var ostring = (o + "");
800 } catch (e) { 818 } catch (e) {
801 return "[" + typeof(o) + "]"; 819 return "[" + typeof(o) + "]";
802 } 820 }
803 if (typeof(o) == "function") { 821 if (typeof(o) == "function") {
804 ostring = ostring.replace(/^\s+/, "").replace(/\s+/g, " "); 822 ostring = ostring.replace(/^\s+/, "").replace(/\s+/g, " ");
805 ostring = ostring.replace(/,(\S)/, ", $1"); 823 ostring = ostring.replace(/,(\S)/, ", $1");
806 var idx = ostring.indexOf("{"); 824 var idx = ostring.indexOf("{");
807 if (idx != -1) { 825 if (idx != -1) {
808 ostring = ostring.substr(0, idx) + "{...}"; 826 ostring = ostring.substr(0, idx) + "{...}";
809 } 827 }
810 } 828 }
811 return ostring; 829 return ostring;
812 }, 830 },
813 831
814 /** @id MochiKit.Base.reprArrayLike */ 832 /** @id MochiKit.Base.reprArrayLike */
815 reprArrayLike: function (o) { 833 reprArrayLike: function (o) {
816 var m = MochiKit.Base; 834 var m = MochiKit.Base;
817 return "[" + m.map(m.repr, o).join(", ") + "]"; 835 return "[" + m.map(m.repr, o).join(", ") + "]";
818 }, 836 },
819 837
820 /** @id MochiKit.Base.reprString */ 838 /** @id MochiKit.Base.reprString */
821 reprString: function (o) { 839 reprString: function (o) {
822 return ('"' + o.replace(/(["\\])/g, '\\$1') + '"' 840 return ('"' + o.replace(/(["\\])/g, '\\$1') + '"'
823 ).replace(/[\f]/g, "\\f" 841 ).replace(/[\f]/g, "\\f"
824 ).replace(/[\b]/g, "\\b" 842 ).replace(/[\b]/g, "\\b"
825 ).replace(/[\n]/g, "\\n" 843 ).replace(/[\n]/g, "\\n"
826 ).replace(/[\t]/g, "\\t" 844 ).replace(/[\t]/g, "\\t"
827 ).replace(/[\v]/g, "\\v" 845 ).replace(/[\v]/g, "\\v"
828 ).replace(/[\r]/g, "\\r"); 846 ).replace(/[\r]/g, "\\r");
829 }, 847 },
830 848
831 /** @id MochiKit.Base.reprNumber */ 849 /** @id MochiKit.Base.reprNumber */
832 reprNumber: function (o) { 850 reprNumber: function (o) {
833 return o + ""; 851 return o + "";
834 }, 852 },
835 853
836 /** @id MochiKit.Base.registerJSON */ 854 /** @id MochiKit.Base.registerJSON */
837 registerJSON: function (name, check, wrap, /* optional */override) { 855 registerJSON: function (name, check, wrap, /* optional */override) {
838 MochiKit.Base.jsonRegistry.register(name, check, wrap, override); 856 MochiKit.Base.jsonRegistry.register(name, check, wrap, override);
839 }, 857 },
840 858
841 859
842 /** @id MochiKit.Base.evalJSON */ 860 /** @id MochiKit.Base.evalJSON */
843 evalJSON: function () { 861 evalJSON: function (jsonText) {
844 return eval("(" + MochiKit.Base._filterJSON(arguments[0]) + ")"); 862 return eval("(" + MochiKit.Base._filterJSON(jsonText) + ")");
845 }, 863 },
846 864
847 _filterJSON: function (s) { 865 _filterJSON: function (s) {
848 var m = s.match(/^\s*\/\*(.*)\*\/\s*$/); 866 var m = s.match(/^\s*\/\*(.*)\*\/\s*$/);
849 if (m) { 867 return (m) ? m[1] : s;
850 return m[1];
851 }
852 return s;
853 }, 868 },
854 869
855 /** @id MochiKit.Base.serializeJSON */ 870 /** @id MochiKit.Base.serializeJSON */
856 serializeJSON: function (o) { 871 serializeJSON: function (o) {
857 var objtype = typeof(o); 872 var objtype = typeof(o);
858 if (objtype == "number" || objtype == "boolean") { 873 if (objtype == "number" || objtype == "boolean") {
859 return o + ""; 874 return o + "";
860 } else if (o === null) { 875 } else if (o === null) {
861 return "null"; 876 return "null";
862 } else if (objtype == "string") { 877 } else if (objtype == "string") {
863 var res = ""; 878 var res = "";
864 for (var i = 0; i < o.length; i++) { 879 for (var i = 0; i < o.length; i++) {
865 var c = o.charAt(i); 880 var c = o.charAt(i);
866 if (c == '\"') { 881 if (c == '\"') {
867 res += '\\"'; 882 res += '\\"';
868 } else if (c == '\\') { 883 } else if (c == '\\') {
869 res += '\\\\'; 884 res += '\\\\';
870 } else if (c == '\b') { 885 } else if (c == '\b') {
871 res += '\\b'; 886 res += '\\b';
872 } else if (c == '\f') { 887 } else if (c == '\f') {
873 res += '\\f'; 888 res += '\\f';
874 } else if (c == '\n') { 889 } else if (c == '\n') {
875 res += '\\n'; 890 res += '\\n';
876 } else if (c == '\r') { 891 } else if (c == '\r') {
877 res += '\\r'; 892 res += '\\r';
878 } else if (c == '\t') { 893 } else if (c == '\t') {
879 res += '\\t'; 894 res += '\\t';
880 } else if (o.charCodeAt(i) <= 0x1F) { 895 } else if (o.charCodeAt(i) <= 0x1F) {
881 var hex = o.charCodeAt(i).toString(16); 896 var hex = o.charCodeAt(i).toString(16);
882 if (hex.length < 2) { 897 if (hex.length < 2) {
883 hex = '0' + hex; 898 hex = '0' + hex;
884 } 899 }
885 res += '\\u00' + hex.toUpperCase(); 900 res += '\\u00' + hex.toUpperCase();
886 } else { 901 } else {
887 res += c; 902 res += c;
888 } 903 }
889 } 904 }
890 return '"' + res + '"'; 905 return '"' + res + '"';
891 } 906 }
892 // recurse 907 // recurse
893 var me = arguments.callee; 908 var me = arguments.callee;
894 // short-circuit for objects that support "json" serialization 909 // short-circuit for objects that support "json" serialization
895 // if they return "self" then just pass-through... 910 // if they return "self" then just pass-through...
896 var newObj; 911 var newObj;
912 if (typeof(o.toJSON) == "function") {
913 newObj = o.toJSON();
914 if (o !== newObj) {
915 return me(newObj);
916 }
917 }
897 if (typeof(o.__json__) == "function") { 918 if (typeof(o.__json__) == "function") {
898 newObj = o.__json__(); 919 newObj = o.__json__();
899 if (o !== newObj) { 920 if (o !== newObj) {
900 return me(newObj); 921 return me(newObj);
901 } 922 }
902 } 923 }
903 if (typeof(o.json) == "function") { 924 if (typeof(o.json) == "function") {
904 newObj = o.json(); 925 newObj = o.json();
905 if (o !== newObj) { 926 if (o !== newObj) {
906 return me(newObj); 927 return me(newObj);
907 } 928 }
908 } 929 }
909 // array 930 // array
910 if (objtype != "function" && typeof(o.length) == "number") { 931 if (objtype != "function" && typeof(o.length) == "number") {
911 var res = []; 932 var res = [];
912 for (var i = 0; i < o.length; i++) { 933 for (var i = 0; i < o.length; i++) {
913 var val = me(o[i]); 934 var val = me(o[i]);
914 if (typeof(val) != "string") { 935 if (typeof(val) != "string") {
915 // skip non-serializable values 936 // skip non-serializable values
916 continue; 937 continue;
917 } 938 }
918 res.push(val); 939 res.push(val);
919 } 940 }
920 return "[" + res.join(", ") + "]"; 941 return "[" + res.join(", ") + "]";
921 } 942 }
922 // look in the registry 943 // look in the registry
923 var m = MochiKit.Base; 944 var m = MochiKit.Base;
924 try { 945 try {
925 newObj = m.jsonRegistry.match(o); 946 newObj = m.jsonRegistry.match(o);
926 if (o !== newObj) { 947 if (o !== newObj) {
927 return me(newObj); 948 return me(newObj);
928 } 949 }
929 } catch (e) { 950 } catch (e) {
930 if (e != m.NotFound) { 951 if (e != m.NotFound) {
931 // something really bad happened 952 // something really bad happened
932 throw e; 953 throw e;
933 } 954 }
934 } 955 }
935 // undefined is outside of the spec 956 // undefined is outside of the spec
936 if (objtype == "undefined") { 957 if (objtype == "undefined") {
937 throw new TypeError("undefined can not be serialized as JSON"); 958 throw new TypeError("undefined can not be serialized as JSON");
938 } 959 }
939 // it's a function with no adapter, bad 960 // it's a function with no adapter, bad
940 if (objtype == "function") { 961 if (objtype == "function") {
941 return null; 962 return null;
942 } 963 }
943 // generic object code path 964 // generic object code path
944 res = []; 965 res = [];
945 for (var k in o) { 966 for (var k in o) {
946 var useKey; 967 var useKey;
947 if (typeof(k) == "number") { 968 if (typeof(k) == "number") {
948 useKey = '"' + k + '"'; 969 useKey = '"' + k + '"';
949 } else if (typeof(k) == "string") { 970 } else if (typeof(k) == "string") {
950 useKey = me(k); 971 useKey = me(k);
951 } else { 972 } else {
952 // skip non-string or number keys 973 // skip non-string or number keys
953 continue; 974 continue;
954 } 975 }
955 val = me(o[k]); 976 val = me(o[k]);
956 if (typeof(val) != "string") { 977 if (typeof(val) != "string") {
957 // skip non-serializable values 978 // skip non-serializable values
958 continue; 979 continue;
959 } 980 }
960 res.push(useKey + ":" + val); 981 res.push(useKey + ":" + val);
961 } 982 }
962 return "{" + res.join(", ") + "}"; 983 return "{" + res.join(", ") + "}";
963 }, 984 },
964 985
965 986
966 /** @id MochiKit.Base.objEqual */ 987 /** @id MochiKit.Base.objEqual */
967 objEqual: function (a, b) { 988 objEqual: function (a, b) {
968 return (MochiKit.Base.compare(a, b) === 0); 989 return (MochiKit.Base.compare(a, b) === 0);
969 }, 990 },
970 991
971 /** @id MochiKit.Base.arrayEqual */ 992 /** @id MochiKit.Base.arrayEqual */
972 arrayEqual: function (self, arr) { 993 arrayEqual: function (self, arr) {
973 if (self.length != arr.length) { 994 if (self.length != arr.length) {
974 return false; 995 return false;
975 } 996 }
976 return (MochiKit.Base.compare(self, arr) === 0); 997 return (MochiKit.Base.compare(self, arr) === 0);
977 }, 998 },
978 999
979 /** @id MochiKit.Base.concat */ 1000 /** @id MochiKit.Base.concat */
980 concat: function (/* lst... */) { 1001 concat: function (/* lst... */) {
981 var rval = []; 1002 var rval = [];
982 var extend = MochiKit.Base.extend; 1003 var extend = MochiKit.Base.extend;
983 for (var i = 0; i < arguments.length; i++) { 1004 for (var i = 0; i < arguments.length; i++) {
984 extend(rval, arguments[i]); 1005 extend(rval, arguments[i]);
985 } 1006 }
986 return rval; 1007 return rval;
987 }, 1008 },
988 1009
989 /** @id MochiKit.Base.keyComparator */ 1010 /** @id MochiKit.Base.keyComparator */
990 keyComparator: function (key/* ... */) { 1011 keyComparator: function (key/* ... */) {
991 // fast-path for single key comparisons 1012 // fast-path for single key comparisons
992 var m = MochiKit.Base; 1013 var m = MochiKit.Base;
@@ -1007,446 +1028,473 @@ MochiKit.Base.update(MochiKit.Base, {
1007 } 1028 }
1008 return rval; 1029 return rval;
1009 }; 1030 };
1010 }, 1031 },
1011 1032
1012 /** @id MochiKit.Base.reverseKeyComparator */ 1033 /** @id MochiKit.Base.reverseKeyComparator */
1013 reverseKeyComparator: function (key) { 1034 reverseKeyComparator: function (key) {
1014 var comparator = MochiKit.Base.keyComparator.apply(this, arguments); 1035 var comparator = MochiKit.Base.keyComparator.apply(this, arguments);
1015 return function (a, b) { 1036 return function (a, b) {
1016 return comparator(b, a); 1037 return comparator(b, a);
1017 }; 1038 };
1018 }, 1039 },
1019 1040
1020 /** @id MochiKit.Base.partial */ 1041 /** @id MochiKit.Base.partial */
1021 partial: function (func) { 1042 partial: function (func) {
1022 var m = MochiKit.Base; 1043 var m = MochiKit.Base;
1023 return m.bind.apply(this, m.extend([func, undefined], arguments, 1)); 1044 return m.bind.apply(this, m.extend([func, undefined], arguments, 1));
1024 }, 1045 },
1025 1046
1026 /** @id MochiKit.Base.listMinMax */ 1047 /** @id MochiKit.Base.listMinMax */
1027 listMinMax: function (which, lst) { 1048 listMinMax: function (which, lst) {
1028 if (lst.length === 0) { 1049 if (lst.length === 0) {
1029 return null; 1050 return null;
1030 } 1051 }
1031 var cur = lst[0]; 1052 var cur = lst[0];
1032 var compare = MochiKit.Base.compare; 1053 var compare = MochiKit.Base.compare;
1033 for (var i = 1; i < lst.length; i++) { 1054 for (var i = 1; i < lst.length; i++) {
1034 var o = lst[i]; 1055 var o = lst[i];
1035 if (compare(o, cur) == which) { 1056 if (compare(o, cur) == which) {
1036 cur = o; 1057 cur = o;
1037 } 1058 }
1038 } 1059 }
1039 return cur; 1060 return cur;
1040 }, 1061 },
1041 1062
1042 /** @id MochiKit.Base.objMax */ 1063 /** @id MochiKit.Base.objMax */
1043 objMax: function (/* obj... */) { 1064 objMax: function (/* obj... */) {
1044 return MochiKit.Base.listMinMax(1, arguments); 1065 return MochiKit.Base.listMinMax(1, arguments);
1045 }, 1066 },
1046 1067
1047 /** @id MochiKit.Base.objMin */ 1068 /** @id MochiKit.Base.objMin */
1048 objMin: function (/* obj... */) { 1069 objMin: function (/* obj... */) {
1049 return MochiKit.Base.listMinMax(-1, arguments); 1070 return MochiKit.Base.listMinMax(-1, arguments);
1050 }, 1071 },
1051 1072
1052 /** @id MochiKit.Base.findIdentical */ 1073 /** @id MochiKit.Base.findIdentical */
1053 findIdentical: function (lst, value, start/* = 0 */, /* optional */end) { 1074 findIdentical: function (lst, value, start/* = 0 */, /* optional */end) {
1054 if (typeof(end) == "undefined" || end === null) { 1075 if (typeof(end) == "undefined" || end === null) {
1055 end = lst.length; 1076 end = lst.length;
1056 } 1077 }
1057 if (typeof(start) == "undefined" || start === null) { 1078 if (typeof(start) == "undefined" || start === null) {
1058 start = 0; 1079 start = 0;
1059 } 1080 }
1060 for (var i = start; i < end; i++) { 1081 for (var i = start; i < end; i++) {
1061 if (lst[i] === value) { 1082 if (lst[i] === value) {
1062 return i; 1083 return i;
1063 } 1084 }
1064 } 1085 }
1065 return -1; 1086 return -1;
1066 }, 1087 },
1067 1088
1068 /** @id MochiKit.Base.mean */ 1089 /** @id MochiKit.Base.mean */
1069 mean: function(/* lst... */) { 1090 mean: function(/* lst... */) {
1070 /* http://www.nist.gov/dads/HTML/mean.html */ 1091 /* http://www.nist.gov/dads/HTML/mean.html */
1071 var sum = 0; 1092 var sum = 0;
1072 1093
1073 var m = MochiKit.Base; 1094 var m = MochiKit.Base;
1074 var args = m.extend(null, arguments); 1095 var args = m.extend(null, arguments);
1075 var count = args.length; 1096 var count = args.length;
1076 1097
1077 while (args.length) { 1098 while (args.length) {
1078 var o = args.shift(); 1099 var o = args.shift();
1079 if (o && typeof(o) == "object" && typeof(o.length) == "number") { 1100 if (o && typeof(o) == "object" && typeof(o.length) == "number") {
1080 count += o.length - 1; 1101 count += o.length - 1;
1081 for (var i = o.length - 1; i >= 0; i--) { 1102 for (var i = o.length - 1; i >= 0; i--) {
1082 sum += o[i]; 1103 sum += o[i];
1083 } 1104 }
1084 } else { 1105 } else {
1085 sum += o; 1106 sum += o;
1086 } 1107 }
1087 } 1108 }
1088 1109
1089 if (count <= 0) { 1110 if (count <= 0) {
1090 throw new TypeError('mean() requires at least one argument'); 1111 throw new TypeError('mean() requires at least one argument');
1091 } 1112 }
1092 1113
1093 return sum/count; 1114 return sum/count;
1094 }, 1115 },
1095 1116
1096 /** @id MochiKit.Base.median */ 1117 /** @id MochiKit.Base.median */
1097 median: function(/* lst... */) { 1118 median: function(/* lst... */) {
1098 /* http://www.nist.gov/dads/HTML/median.html */ 1119 /* http://www.nist.gov/dads/HTML/median.html */
1099 var data = MochiKit.Base.flattenArguments(arguments); 1120 var data = MochiKit.Base.flattenArguments(arguments);
1100 if (data.length === 0) { 1121 if (data.length === 0) {
1101 throw new TypeError('median() requires at least one argument'); 1122 throw new TypeError('median() requires at least one argument');
1102 } 1123 }
1103 data.sort(compare); 1124 data.sort(MochiKit.Base.compare);
1104 if (data.length % 2 == 0) { 1125 if (data.length % 2 == 0) {
1105 var upper = data.length / 2; 1126 var upper = data.length / 2;
1106 return (data[upper] + data[upper - 1]) / 2; 1127 return (data[upper] + data[upper - 1]) / 2;
1107 } else { 1128 } else {
1108 return data[(data.length - 1) / 2]; 1129 return data[(data.length - 1) / 2];
1109 } 1130 }
1110 }, 1131 },
1111 1132
1112 /** @id MochiKit.Base.findValue */ 1133 /** @id MochiKit.Base.findValue */
1113 findValue: function (lst, value, start/* = 0 */, /* optional */end) { 1134 findValue: function (lst, value, start/* = 0 */, /* optional */end) {
1114 if (typeof(end) == "undefined" || end === null) { 1135 if (typeof(end) == "undefined" || end === null) {
1115 end = lst.length; 1136 end = lst.length;
1116 } 1137 }
1117 if (typeof(start) == "undefined" || start === null) { 1138 if (typeof(start) == "undefined" || start === null) {
1118 start = 0; 1139 start = 0;
1119 } 1140 }
1120 var cmp = MochiKit.Base.compare; 1141 var cmp = MochiKit.Base.compare;
1121 for (var i = start; i < end; i++) { 1142 for (var i = start; i < end; i++) {
1122 if (cmp(lst[i], value) === 0) { 1143 if (cmp(lst[i], value) === 0) {
1123 return i; 1144 return i;
1124 } 1145 }
1125 } 1146 }
1126 return -1; 1147 return -1;
1127 }, 1148 },
1128 1149
1129 /** @id MochiKit.Base.nodeWalk */ 1150 /** @id MochiKit.Base.nodeWalk */
1130 nodeWalk: function (node, visitor) { 1151 nodeWalk: function (node, visitor) {
1131 var nodes = [node]; 1152 var nodes = [node];
1132 var extend = MochiKit.Base.extend; 1153 var extend = MochiKit.Base.extend;
1133 while (nodes.length) { 1154 while (nodes.length) {
1134 var res = visitor(nodes.shift()); 1155 var res = visitor(nodes.shift());
1135 if (res) { 1156 if (res) {
1136 extend(nodes, res); 1157 extend(nodes, res);
1137 } 1158 }
1138 } 1159 }
1139 }, 1160 },
1140 1161
1141 1162
1142 /** @id MochiKit.Base.nameFunctions */ 1163 /** @id MochiKit.Base.nameFunctions */
1143 nameFunctions: function (namespace) { 1164 nameFunctions: function (namespace) {
1144 var base = namespace.NAME; 1165 var base = namespace.NAME;
1145 if (typeof(base) == 'undefined') { 1166 if (typeof(base) == 'undefined') {
1146 base = ''; 1167 base = '';
1147 } else { 1168 } else {
1148 base = base + '.'; 1169 base = base + '.';
1149 } 1170 }
1150 for (var name in namespace) { 1171 for (var name in namespace) {
1151 var o = namespace[name]; 1172 var o = namespace[name];
1152 if (typeof(o) == 'function' && typeof(o.NAME) == 'undefined') { 1173 if (typeof(o) == 'function' && typeof(o.NAME) == 'undefined') {
1153 try { 1174 try {
1154 o.NAME = base + name; 1175 o.NAME = base + name;
1155 } catch (e) { 1176 } catch (e) {
1156 // pass 1177 // pass
1157 } 1178 }
1158 } 1179 }
1159 } 1180 }
1160 }, 1181 },
1161 1182
1162 1183
1163 /** @id MochiKit.Base.queryString */ 1184 /** @id MochiKit.Base.queryString */
1164 queryString: function (names, values) { 1185 queryString: function (names, values) {
1165 // check to see if names is a string or a DOM element, and if 1186 // check to see if names is a string or a DOM element, and if
1166 // MochiKit.DOM is available. If so, drop it like it's a form 1187 // MochiKit.DOM is available. If so, drop it like it's a form
1167 // Ugliest conditional in MochiKit? Probably! 1188 // Ugliest conditional in MochiKit? Probably!
1168 if (typeof(MochiKit.DOM) != "undefined" && arguments.length == 1 1189 if (typeof(MochiKit.DOM) != "undefined" && arguments.length == 1
1169 && (typeof(names) == "string" || ( 1190 && (typeof(names) == "string" || (
1170 typeof(names.nodeType) != "undefined" && names.nodeType > 0 1191 typeof(names.nodeType) != "undefined" && names.nodeType > 0
1171 )) 1192 ))
1172 ) { 1193 ) {
1173 var kv = MochiKit.DOM.formContents(names); 1194 var kv = MochiKit.DOM.formContents(names);
1174 names = kv[0]; 1195 names = kv[0];
1175 values = kv[1]; 1196 values = kv[1];
1176 } else if (arguments.length == 1) { 1197 } else if (arguments.length == 1) {
1177 // Allow the return value of formContents to be passed directly 1198 // Allow the return value of formContents to be passed directly
1178 if (typeof(names.length) == "number" && names.length == 2) { 1199 if (typeof(names.length) == "number" && names.length == 2) {
1179 return arguments.callee(names[0], names[1]); 1200 return arguments.callee(names[0], names[1]);
1180 } 1201 }
1181 var o = names; 1202 var o = names;
1182 names = []; 1203 names = [];
1183 values = []; 1204 values = [];
1184 for (var k in o) { 1205 for (var k in o) {
1185 var v = o[k]; 1206 var v = o[k];
1186 if (typeof(v) == "function") { 1207 if (typeof(v) == "function") {
1187 continue; 1208 continue;
1188 } else if (MochiKit.Base.isArrayLike(v)){ 1209 } else if (MochiKit.Base.isArrayLike(v)){
1189 for (var i = 0; i < v.length; i++) { 1210 for (var i = 0; i < v.length; i++) {
1190 names.push(k); 1211 names.push(k);
1191 values.push(v[i]); 1212 values.push(v[i]);
1192 } 1213 }
1193 } else { 1214 } else {
1194 names.push(k); 1215 names.push(k);
1195 values.push(v); 1216 values.push(v);
1196 } 1217 }
1197 } 1218 }
1198 } 1219 }
1199 var rval = []; 1220 var rval = [];
1200 var len = Math.min(names.length, values.length); 1221 var len = Math.min(names.length, values.length);
1201 var urlEncode = MochiKit.Base.urlEncode; 1222 var urlEncode = MochiKit.Base.urlEncode;
1202 for (var i = 0; i < len; i++) { 1223 for (var i = 0; i < len; i++) {
1203 v = values[i]; 1224 v = values[i];
1204 if (typeof(v) != 'undefined' && v !== null) { 1225 if (typeof(v) != 'undefined' && v !== null) {
1205 rval.push(urlEncode(names[i]) + "=" + urlEncode(v)); 1226 rval.push(urlEncode(names[i]) + "=" + urlEncode(v));
1206 } 1227 }
1207 } 1228 }
1208 return rval.join("&"); 1229 return rval.join("&");
1209 }, 1230 },
1210 1231
1211 1232
1212 /** @id MochiKit.Base.parseQueryString */ 1233 /** @id MochiKit.Base.parseQueryString */
1213 parseQueryString: function (encodedString, useArrays) { 1234 parseQueryString: function (encodedString, useArrays) {
1214 // strip a leading '?' from the encoded string 1235 // strip a leading '?' from the encoded string
1215 var qstr = (encodedString.charAt(0) == "?") 1236 var qstr = (encodedString.charAt(0) == "?")
1216 ? encodedString.substring(1) 1237 ? encodedString.substring(1)
1217 : encodedString; 1238 : encodedString;
1218 var pairs = qstr.replace(/\+/g, "%20").split(/\&amp\;|\&\#38\;|\&#x26;|\&/); 1239 var pairs = qstr.replace(/\+/g, "%20").split(/\&amp\;|\&\#38\;|\&#x26;|\&/);
1219 var o = {}; 1240 var o = {};
1220 var decode; 1241 var decode;
1221 if (typeof(decodeURIComponent) != "undefined") { 1242 if (typeof(decodeURIComponent) != "undefined") {
1222 decode = decodeURIComponent; 1243 decode = decodeURIComponent;
1223 } else { 1244 } else {
1224 decode = unescape; 1245 decode = unescape;
1225 } 1246 }
1226 if (useArrays) { 1247 if (useArrays) {
1227 for (var i = 0; i < pairs.length; i++) { 1248 for (var i = 0; i < pairs.length; i++) {
1228 var pair = pairs[i].split("="); 1249 var pair = pairs[i].split("=");
1229 var name = decode(pair.shift()); 1250 var name = decode(pair.shift());
1230 if (!name) { 1251 if (!name) {
1231 continue; 1252 continue;
1232 } 1253 }
1233 var arr = o[name]; 1254 var arr = o[name];
1234 if (!(arr instanceof Array)) { 1255 if (!(arr instanceof Array)) {
1235 arr = []; 1256 arr = [];
1236 o[name] = arr; 1257 o[name] = arr;
1237 } 1258 }
1238 arr.push(decode(pair.join("="))); 1259 arr.push(decode(pair.join("=")));
1239 } 1260 }
1240 } else { 1261 } else {
1241 for (var i = 0; i < pairs.length; i++) { 1262 for (var i = 0; i < pairs.length; i++) {
1242 pair = pairs[i].split("="); 1263 pair = pairs[i].split("=");
1243 var name = pair.shift(); 1264 var name = pair.shift();
1244 if (!name) { 1265 if (!name) {
1245 continue; 1266 continue;
1246 } 1267 }
1247 o[decode(name)] = decode(pair.join("=")); 1268 o[decode(name)] = decode(pair.join("="));
1248 } 1269 }
1249 } 1270 }
1250 return o; 1271 return o;
1251 } 1272 }
1252}); 1273});
1253 1274
1254/** @id MochiKit.Base.AdapterRegistry */ 1275/** @id MochiKit.Base.AdapterRegistry */
1255MochiKit.Base.AdapterRegistry = function () { 1276MochiKit.Base.AdapterRegistry = function () {
1256 this.pairs = []; 1277 this.pairs = [];
1257}; 1278};
1258 1279
1259MochiKit.Base.AdapterRegistry.prototype = { 1280MochiKit.Base.AdapterRegistry.prototype = {
1260 /** @id MochiKit.Base.AdapterRegistry.prototype.register */ 1281 /** @id MochiKit.Base.AdapterRegistry.prototype.register */
1261 register: function (name, check, wrap, /* optional */ override) { 1282 register: function (name, check, wrap, /* optional */ override) {
1262 if (override) { 1283 if (override) {
1263 this.pairs.unshift([name, check, wrap]); 1284 this.pairs.unshift([name, check, wrap]);
1264 } else { 1285 } else {
1265 this.pairs.push([name, check, wrap]); 1286 this.pairs.push([name, check, wrap]);
1266 } 1287 }
1267 }, 1288 },
1268 1289
1269 /** @id MochiKit.Base.AdapterRegistry.prototype.match */ 1290 /** @id MochiKit.Base.AdapterRegistry.prototype.match */
1270 match: function (/* ... */) { 1291 match: function (/* ... */) {
1271 for (var i = 0; i < this.pairs.length; i++) { 1292 for (var i = 0; i < this.pairs.length; i++) {
1272 var pair = this.pairs[i]; 1293 var pair = this.pairs[i];
1273 if (pair[1].apply(this, arguments)) { 1294 if (pair[1].apply(this, arguments)) {
1274 return pair[2].apply(this, arguments); 1295 return pair[2].apply(this, arguments);
1275 } 1296 }
1276 } 1297 }
1277 throw MochiKit.Base.NotFound; 1298 throw MochiKit.Base.NotFound;
1278 }, 1299 },
1279 1300
1280 /** @id MochiKit.Base.AdapterRegistry.prototype.unregister */ 1301 /** @id MochiKit.Base.AdapterRegistry.prototype.unregister */
1281 unregister: function (name) { 1302 unregister: function (name) {
1282 for (var i = 0; i < this.pairs.length; i++) { 1303 for (var i = 0; i < this.pairs.length; i++) {
1283 var pair = this.pairs[i]; 1304 var pair = this.pairs[i];
1284 if (pair[0] == name) { 1305 if (pair[0] == name) {
1285 this.pairs.splice(i, 1); 1306 this.pairs.splice(i, 1);
1286 return true; 1307 return true;
1287 } 1308 }
1288 } 1309 }
1289 return false; 1310 return false;
1290 } 1311 }
1291}; 1312};
1292 1313
1293MochiKit.Base._exportSymbols = function (globals, module) { 1314/**
1294 if (MochiKit.__export__ === false || module.__export__ === false) { 1315 * Exports all symbols from one or more modules into the specified
1295 return; 1316 * namespace (or scope). This is similar to MochiKit.Base.update(),
1296 } 1317 * except for special handling of the "__export__" flag, contained
1297 for (var k in module) { 1318 * sub-modules (exported recursively), and names starting with "_".
1298 var v = module[k]; 1319 *
1299 if (v != null) { 1320 * @param {Object} namespace the object or scope to modify
1300 var okName = (k[0] !== "_" && k !== "toString"); 1321 * @param {Object} module the module to export
1301 if (v.__export__ === true || (v.__export__ !== false && okName)) { 1322 */
1302 globals[k] = module[k]; 1323MochiKit.Base.moduleExport = function (namespace, module/*, ...*/) {
1324 var SKIP = { toString: true, NAME: true, VERSION: true };
1325 var mods = MochiKit.Base.extend([], arguments, 1);
1326 while ((module = mods.shift()) != null) {
1327 for (var k in module) {
1328 var v = module[k];
1329 if (v != null) {
1330 var flagSet = (typeof(v.__export__) == 'boolean');
1331 var nameValid = (k[0] !== "_" && !SKIP[k]);
1332 if (flagSet ? v.__export__ : nameValid) {
1333 if (typeof(v) == 'object' && v.NAME && v.VERSION) {
1334 mods.push(v);
1335 } else {
1336 namespace[k] = module[k];
1337 }
1338 }
1303 } 1339 }
1304 } 1340 }
1305 } 1341 }
1342 return namespace;
1343};
1344
1345/**
1346 * Identical to moduleExport, but also considers the global and
1347 * module-specific "__export__" flag.
1348 */
1349MochiKit.Base._exportSymbols = function (namespace, module) {
1350 if (MochiKit.__export__ !== false && module.__export__ !== false) {
1351 MochiKit.Base.moduleExport(namespace, module);
1352 }
1306}; 1353};
1307 1354
1308/** 1355/**
1309 * Creates a deprecated function alias in the specified module. The 1356 * Creates a deprecated function alias in the specified module. The
1310 * deprecated function will forward all calls and arguments to a 1357 * deprecated function will forward all calls and arguments to a
1311 * target function, while also logging a debug message on the first 1358 * target function, while also logging a debug message on the first
1312 * call (if MochiKit.Logging is loaded). The destination function may 1359 * call (if MochiKit.Logging is loaded). The destination function may
1313 * be located in another module, which must be loaded, or an 1360 * be located in another module, which must be loaded, or an
1314 * exception will be thrown. 1361 * exception will be thrown.
1315 * 1362 *
1316 * @param {Object/String} module the source module or module name 1363 * @param {Object/String} module the source module or module name
1317 * (e.g. 'DOM' or 'MochiKit.DOM') 1364 * (e.g. 'DOM' or 'MochiKit.DOM')
1318 * @param {String} name the deprecated function name (e.g. 'getStyle') 1365 * @param {String} name the deprecated function name (e.g. 'getStyle')
1319 * @param {String} target the fully qualified name of the target 1366 * @param {String} target the fully qualified name of the target
1320 * function (e.g. 'MochiKit.Style.getStyle') 1367 * function (e.g. 'MochiKit.Style.getStyle')
1321 * @param {String} version the first version when the source function 1368 * @param {String} version the first version when the source function
1322 * was deprecated (e.g. '1.4') 1369 * was deprecated (e.g. '1.4')
1323 * @param {Boolean} [exportable] the exportable function flag, 1370 * @param {Boolean} [exportable] the exportable function flag,
1324 * defaults to true 1371 * defaults to false
1325 */ 1372 */
1326MochiKit.Base._deprecated = function (module, name, target, version, exportable) { 1373MochiKit.Base._deprecated = function (module, name, target, version, exportable) {
1327 if (typeof(module) === 'string') { 1374 if (typeof(module) === 'string') {
1328 if (module.indexOf('MochiKit.') === 0) { 1375 if (module.indexOf('MochiKit.') === 0) {
1329 module = module.substring(9); 1376 module = module.substring(9);
1330 } 1377 }
1331 module = MochiKit[module]; 1378 module = MochiKit[module];
1332 } 1379 }
1333 var targetModule = target.split('.')[1]; 1380 var targetModule = target.split('.')[1];
1334 var targetName = target.split('.')[2]; 1381 var targetName = target.split('.')[2];
1335 var func = function () { 1382 var func = function () {
1336 var self = arguments.callee; 1383 var self = arguments.callee;
1337 var msg = module.NAME + '.' + name + ' is deprecated since version ' + 1384 var msg = module.NAME + '.' + name + ' is deprecated since version ' +
1338 version + '. Use ' + target + ' instead.'; 1385 version + '. Use ' + target + ' instead.';
1339 if (self.logged !== true) { 1386 if (self.logged !== true) {
1340 self.logged = true; 1387 self.logged = true;
1341 if (MochiKit.Logging) { 1388 if (MochiKit.Logging) {
1342 MochiKit.Logging.logDebug(msg); 1389 MochiKit.Logging.logDebug(msg);
1343 } else if (console && console.log) { 1390 } else if (console && console.log) {
1344 console.log(msg); 1391 console.log(msg);
1345 } 1392 }
1346 } 1393 }
1347 if (!MochiKit[targetModule]) { 1394 if (!MochiKit[targetModule]) {
1348 throw new Error(msg); 1395 throw new Error(msg);
1349 } 1396 }
1350 return MochiKit[targetModule][targetName].apply(this, arguments); 1397 return MochiKit[targetModule][targetName].apply(this, arguments);
1351 }; 1398 };
1352 if (exportable === false) { 1399 func.__export__ = (exportable === true);
1353 func.__export__ = false;
1354 }
1355 module[name] = func; 1400 module[name] = func;
1356} 1401};
1357 1402
1358MochiKit.Base.__new__ = function () { 1403MochiKit.Base.__new__ = function () {
1359 var m = this; 1404 var m = this;
1360 1405
1361 /** @id MochiKit.Base.noop */ 1406 /** @id MochiKit.Base.noop */
1362 m.noop = m.operator.identity; 1407 m.noop = m.operator.identity;
1363 1408
1364 // Backwards compat 1409 // Backwards compat
1365 m._deprecated(m, 'forward', 'MochiKit.Base.forwardCall', '1.3', false); 1410 m._deprecated(m, 'forward', 'MochiKit.Base.forwardCall', '1.3');
1366 m._deprecated(m, 'find', 'MochiKit.Base.findValue', '1.3', false); 1411 m._deprecated(m, 'find', 'MochiKit.Base.findValue', '1.3');
1367 1412
1368 if (typeof(encodeURIComponent) != "undefined") { 1413 if (typeof(encodeURIComponent) != "undefined") {
1369 /** @id MochiKit.Base.urlEncode */ 1414 /** @id MochiKit.Base.urlEncode */
1370 m.urlEncode = function (unencoded) { 1415 m.urlEncode = function (unencoded) {
1371 return encodeURIComponent(unencoded).replace(/\'/g, '%27'); 1416 return encodeURIComponent(unencoded).replace(/\'/g, '%27');
1372 }; 1417 };
1373 } else { 1418 } else {
1374 m.urlEncode = function (unencoded) { 1419 m.urlEncode = function (unencoded) {
1375 return escape(unencoded 1420 return escape(unencoded
1376 ).replace(/\+/g, '%2B' 1421 ).replace(/\+/g, '%2B'
1377 ).replace(/\"/g,'%22' 1422 ).replace(/\"/g,'%22'
1378 ).rval.replace(/\'/g, '%27'); 1423 ).replace(/\'/g, '%27');
1379 }; 1424 };
1380 } 1425 }
1381 1426
1382 /** @id MochiKit.Base.NamedError */ 1427 /** @id MochiKit.Base.NamedError */
1383 m.NamedError = function (name) { 1428 m.NamedError = function (name) {
1384 this.message = name; 1429 this.message = name;
1385 this.name = name; 1430 this.name = name;
1386 }; 1431 };
1387 m.NamedError.prototype = new Error(); 1432 m.NamedError.prototype = new Error();
1433 m.NamedError.prototype.constructor = m.NamedError;
1388 m.update(m.NamedError.prototype, { 1434 m.update(m.NamedError.prototype, {
1389 repr: function () { 1435 repr: function () {
1390 if (this.message && this.message != this.name) { 1436 if (this.message && this.message != this.name) {
1391 return this.name + "(" + m.repr(this.message) + ")"; 1437 return this.name + "(" + m.repr(this.message) + ")";
1392 } else { 1438 } else {
1393 return this.name + "()"; 1439 return this.name + "()";
1394 } 1440 }
1395 }, 1441 },
1396 toString: m.forwardCall("repr") 1442 toString: m.forwardCall("repr")
1397 }); 1443 });
1398 1444
1399 /** @id MochiKit.Base.NotFound */ 1445 /** @id MochiKit.Base.NotFound */
1400 m.NotFound = new m.NamedError("MochiKit.Base.NotFound"); 1446 m.NotFound = new m.NamedError("MochiKit.Base.NotFound");
1401 1447
1402 1448
1403 /** @id MochiKit.Base.listMax */ 1449 /** @id MochiKit.Base.listMax */
1404 m.listMax = m.partial(m.listMinMax, 1); 1450 m.listMax = m.partial(m.listMinMax, 1);
1405 /** @id MochiKit.Base.listMin */ 1451 /** @id MochiKit.Base.listMin */
1406 m.listMin = m.partial(m.listMinMax, -1); 1452 m.listMin = m.partial(m.listMinMax, -1);
1407 1453
1408 /** @id MochiKit.Base.isCallable */ 1454 /** @id MochiKit.Base.isCallable */
1409 m.isCallable = m.typeMatcher('function'); 1455 m.isCallable = m.typeMatcher('function');
1410 /** @id MochiKit.Base.isUndefined */ 1456 /** @id MochiKit.Base.isUndefined */
1411 m.isUndefined = m.typeMatcher('undefined'); 1457 m.isUndefined = m.typeMatcher('undefined');
1458 /** @id MochiKit.Base.isValue */
1459 m.isValue = m.typeMatcher('boolean', 'number', 'string');
1412 1460
1413 /** @id MochiKit.Base.merge */ 1461 /** @id MochiKit.Base.merge */
1414 m.merge = m.partial(m.update, null); 1462 m.merge = m.partial(m.update, null);
1415 /** @id MochiKit.Base.zip */ 1463 /** @id MochiKit.Base.zip */
1416 m.zip = m.partial(m.map, null); 1464 m.zip = m.partial(m.map, null);
1417 1465
1418 /** @id MochiKit.Base.average */ 1466 /** @id MochiKit.Base.average */
1419 m.average = m.mean; 1467 m.average = m.mean;
1420 1468
1421 /** @id MochiKit.Base.comparatorRegistry */ 1469 /** @id MochiKit.Base.comparatorRegistry */
1422 m.comparatorRegistry = new m.AdapterRegistry(); 1470 m.comparatorRegistry = new m.AdapterRegistry();
1423 m.registerComparator("dateLike", m.isDateLike, m.compareDateLike); 1471 m.registerComparator("dateLike", m.isDateLike, m.compareDateLike);
1424 m.registerComparator("arrayLike", m.isArrayLike, m.compareArrayLike); 1472 m.registerComparator("arrayLike", m.isArrayLike, m.compareArrayLike);
1425 1473
1426 /** @id MochiKit.Base.reprRegistry */ 1474 /** @id MochiKit.Base.reprRegistry */
1427 m.reprRegistry = new m.AdapterRegistry(); 1475 m.reprRegistry = new m.AdapterRegistry();
1428 m.registerRepr("arrayLike", m.isArrayLike, m.reprArrayLike); 1476 m.registerRepr("arrayLike", m.isArrayLike, m.reprArrayLike);
1429 m.registerRepr("string", m.typeMatcher("string"), m.reprString); 1477 m.registerRepr("string", m.typeMatcher("string"), m.reprString);
1430 m.registerRepr("numbers", m.typeMatcher("number", "boolean"), m.reprNumber); 1478 m.registerRepr("numbers", m.typeMatcher("number", "boolean"), m.reprNumber);
1431 1479
1432 /** @id MochiKit.Base.jsonRegistry */ 1480 /** @id MochiKit.Base.jsonRegistry */
1433 m.jsonRegistry = new m.AdapterRegistry(); 1481 m.jsonRegistry = new m.AdapterRegistry();
1434 1482
1435 m.nameFunctions(this); 1483 m.nameFunctions(this);
1436 1484
1437}; 1485};
1438 1486
1439MochiKit.Base.__new__(); 1487MochiKit.Base.__new__();
1440 1488
1441// 1489//
1442// XXX: Internet Explorer blows 1490// XXX: Internet Explorer blows
1443// 1491//
1444if (MochiKit.__export__) { 1492if (MochiKit.__export__) {
1445 compare = MochiKit.Base.compare; 1493 compare = MochiKit.Base.compare;
1446 compose = MochiKit.Base.compose; 1494 compose = MochiKit.Base.compose;
1447 serializeJSON = MochiKit.Base.serializeJSON; 1495 serializeJSON = MochiKit.Base.serializeJSON;
1448 mean = MochiKit.Base.mean; 1496 mean = MochiKit.Base.mean;
1449 median = MochiKit.Base.median; 1497 median = MochiKit.Base.median;
1450} 1498}
1451 1499
1452MochiKit.Base._exportSymbols(this, MochiKit.Base); 1500MochiKit.Base._exportSymbols(this, MochiKit.Base);