Diffstat (limited to 'frontend/gamma/js/MochiKit/Base.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/MochiKit/Base.js | 156 |
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,84 +1,95 @@ | |||
1 | /*** | 1 | /*** |
2 | 2 | ||
3 | MochiKit.Base 1.5 | 3 | MochiKit.Base 1.5 |
4 | 4 | ||
5 | See <http://mochikit.com/> for documentation, downloads, license, etc. | 5 | See <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 | ||
11 | if (typeof(MochiKit) == 'undefined') { | 11 | |
12 | MochiKit = {}; | 12 | // MochiKit module (namespace) |
13 | } | 13 | var MochiKit = MochiKit || {}; |
14 | if (typeof(MochiKit.__export__) == "undefined") { | 14 | if (typeof(MochiKit.__export__) == "undefined") { |
15 | MochiKit.__export__ = true; | 15 | MochiKit.__export__ = true; |
16 | } | 16 | } |
17 | if (typeof(MochiKit.Base) == 'undefined') { | 17 | MochiKit.NAME = "MochiKit"; |
18 | MochiKit.Base = {}; | 18 | MochiKit.VERSION = "1.5"; |
19 | } | 19 | MochiKit.__repr__ = function () { |
20 | return "[" + this.NAME + " " + this.VERSION + "]"; | ||
21 | }; | ||
22 | MochiKit.toString = function () { | ||
23 | return this.__repr__(); | ||
24 | }; | ||
25 | |||
26 | |||
27 | // MochiKit.Base module | ||
28 | MochiKit.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 | */ |
32 | MochiKit.Base._module = function (name, version, deps) { | 44 | MochiKit.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 | ||
52 | MochiKit.Base._module("Base", "1.5", []); | 63 | MochiKit.Base.module(MochiKit, "Base", "1.5", []); |
53 | 64 | ||
54 | /** @id MochiKit.Base.update */ | 65 | /** @id MochiKit.Base.update */ |
55 | MochiKit.Base.update = function (self, obj/*, ... */) { | 66 | MochiKit.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 | ||
70 | MochiKit.Base.update(MochiKit.Base, { | 81 | MochiKit.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) { |
@@ -211,64 +222,65 @@ MochiKit.Base.update(MochiKit.Base, { | |||
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 | ||
@@ -322,65 +334,65 @@ MochiKit.Base.update(MochiKit.Base, { | |||
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 | ||
@@ -646,64 +658,67 @@ MochiKit.Base.update(MochiKit.Base, { | |||
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 | ||
@@ -759,170 +774,176 @@ MochiKit.Base.update(MochiKit.Base, { | |||
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 | } |
@@ -1071,65 +1092,65 @@ MochiKit.Base.update(MochiKit.Base, { | |||
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) { |
@@ -1261,183 +1282,210 @@ MochiKit.Base.AdapterRegistry.prototype = { | |||
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 | ||
1293 | MochiKit.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]; | 1323 | MochiKit.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 | */ | ||
1349 | MochiKit.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 | */ |
1326 | MochiKit.Base._deprecated = function (module, name, target, version, exportable) { | 1373 | MochiKit.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 | ||
1358 | MochiKit.Base.__new__ = function () { | 1403 | MochiKit.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 | ||
1439 | MochiKit.Base.__new__(); | 1487 | MochiKit.Base.__new__(); |
1440 | 1488 | ||
1441 | // | 1489 | // |
1442 | // XXX: Internet Explorer blows | 1490 | // XXX: Internet Explorer blows |
1443 | // | 1491 | // |