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
@@ -8,33 +8,43 @@ See <http://mochikit.com/> for documentation, downloads, license, etc.
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 + "]";
@@ -42,14 +52,15 @@ MochiKit.Base._module = function (name, version, deps) {
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/*, ... */) {
@@ -240,6 +251,7 @@ MochiKit.Base.update(MochiKit.Base, {
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
@@ -351,7 +363,7 @@ MochiKit.Base.update(MochiKit.Base, {
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 }
@@ -675,6 +687,9 @@ MochiKit.Base.update(MochiKit.Base, {
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
@@ -788,11 +803,14 @@ MochiKit.Base.update(MochiKit.Base, {
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 {
@@ -840,16 +858,13 @@ MochiKit.Base.update(MochiKit.Base, {
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 */
@@ -894,6 +909,12 @@ MochiKit.Base.update(MochiKit.Base, {
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) {
@@ -1100,7 +1121,7 @@ MochiKit.Base.update(MochiKit.Base, {
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;
@@ -1290,19 +1311,45 @@ MochiKit.Base.AdapterRegistry.prototype = {
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/**
@@ -1321,7 +1368,7 @@ MochiKit.Base._exportSymbols = function (globals, module) {
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') {
@@ -1349,11 +1396,9 @@ MochiKit.Base._deprecated = function (module, name, target, version, exportable)
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;
@@ -1362,8 +1407,8 @@ MochiKit.Base.__new__ = function () {
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 */
@@ -1375,7 +1420,7 @@ MochiKit.Base.__new__ = function () {
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
@@ -1385,6 +1430,7 @@ MochiKit.Base.__new__ = function () {
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) {
@@ -1409,6 +1455,8 @@ MochiKit.Base.__new__ = function () {
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);