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,64 +1,75 @@ | |||
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 | } |
@@ -231,24 +242,25 @@ MochiKit.Base.update(MochiKit.Base, { | |||
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 */ |
@@ -342,25 +354,25 @@ MochiKit.Base.update(MochiKit.Base, { | |||
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 | } |
@@ -666,24 +678,27 @@ MochiKit.Base.update(MochiKit.Base, { | |||
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); |
@@ -779,29 +794,32 @@ MochiKit.Base.update(MochiKit.Base, { | |||
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) { |
@@ -831,34 +849,31 @@ MochiKit.Base.update(MochiKit.Base, { | |||
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++) { |
@@ -885,24 +900,30 @@ MochiKit.Base.update(MochiKit.Base, { | |||
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 | } |
@@ -1091,25 +1112,25 @@ MochiKit.Base.update(MochiKit.Base, { | |||
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; |
@@ -1281,56 +1302,82 @@ MochiKit.Base.AdapterRegistry.prototype = { | |||
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; |
@@ -1340,84 +1387,85 @@ MochiKit.Base._deprecated = function (module, name, target, version, exportable) | |||
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); |