summaryrefslogtreecommitdiff
path: root/frontend/gamma/js/MochiKit/Base.js
Side-by-side diff
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
@@ -10,5 +10,5 @@ See <http://mochikit.com/> for documentation, downloads, license, etc.
-if (typeof(MochiKit) == 'undefined') {
- MochiKit = {};
-}
+
+// MochiKit module (namespace)
+var MochiKit = MochiKit || {};
if (typeof(MochiKit.__export__) == "undefined") {
@@ -16,23 +16,33 @@ if (typeof(MochiKit.__export__) == "undefined") {
}
-if (typeof(MochiKit.Base) == 'undefined') {
- MochiKit.Base = {};
-}
+MochiKit.NAME = "MochiKit";
+MochiKit.VERSION = "1.5";
+MochiKit.__repr__ = function () {
+ return "[" + this.NAME + " " + this.VERSION + "]";
+};
+MochiKit.toString = function () {
+ return this.__repr__();
+};
+
+
+// MochiKit.Base module
+MochiKit.Base = MochiKit.Base || {};
/**
- * Registers a new MochiKit module. This function will insert a new
- * property into the "MochiKit" object, making sure that all
- * dependency modules have already been inserted. It will also make
- * sure that the appropriate properties and default module functions
- * are defined.
+ * Creates a new module in a parent namespace. This function will
+ * create a new empty module object with "NAME", "VERSION",
+ * "toString" and "__repr__" properties. This object will be inserted into the parent object
+ * using the specified name (i.e. parent[name] = module). It will
+ * also verify that all the dependency modules are defined in the
+ * parent, or an error will be thrown.
*
+ * @param {Object} parent the parent module (use "this" or "window" for
+ * a global module)
* @param {String} name the module name, e.g. "Base"
* @param {String} version the module version, e.g. "1.5"
- * @param {Array} deps the array of module dependencies (as strings)
+ * @param {Array} [deps] the array of module dependencies (as strings)
*/
-MochiKit.Base._module = function (name, version, deps) {
- if (!(name in MochiKit)) {
- MochiKit[name] = {};
- }
- var module = MochiKit[name];
- module.NAME = "MochiKit." + name;
+MochiKit.Base.module = function (parent, name, version, deps) {
+ var module = parent[name] = parent[name] || {};
+ var prefix = (parent.NAME ? parent.NAME + "." : "");
+ module.NAME = prefix + name;
module.VERSION = version;
@@ -44,10 +54,11 @@ MochiKit.Base._module = function (name, version, deps) {
};
- for (var i = 0; i < deps.length; i++) {
- if (!(deps[i] in MochiKit)) {
- throw 'MochiKit.' + name + ' depends on MochiKit.' + deps[i] + '!';
+ for (var i = 0; deps != null && i < deps.length; i++) {
+ if (!(deps[i] in parent)) {
+ throw module.NAME + ' depends on ' + prefix + deps[i] + '!';
}
}
-}
+ return module;
+};
-MochiKit.Base._module("Base", "1.5", []);
+MochiKit.Base.module(MochiKit, "Base", "1.5", []);
@@ -242,2 +253,3 @@ MochiKit.Base.update(MochiKit.Base, {
func.prototype = new MochiKit.Base.NamedError(module.NAME + "." + name);
+ func.prototype.constructor = func;
module[name] = func;
@@ -353,3 +365,3 @@ MochiKit.Base.update(MochiKit.Base, {
} else if (value != null && typeof(value.length) === "number") {
- return value.length !== 0
+ return value.length !== 0;
} else {
@@ -677,2 +689,5 @@ MochiKit.Base.update(MochiKit.Base, {
newfunc.im_preargs = im_preargs;
+ if (typeof(im_func.NAME) == 'string') {
+ newfunc.NAME = "bind(" + im_func.NAME + ",...)";
+ }
return newfunc;
@@ -790,7 +805,10 @@ MochiKit.Base.update(MochiKit.Base, {
} catch (e) {
- if (typeof(o.NAME) == 'string' && (
- o.toString == Function.prototype.toString ||
- o.toString == Object.prototype.toString
- )) {
- return o.NAME;
+ try {
+ if (typeof(o.NAME) == 'string' && (
+ o.toString == Function.prototype.toString ||
+ o.toString == Object.prototype.toString
+ )) {
+ return o.NAME;
+ }
+ } catch (ignore) {
}
@@ -842,4 +860,4 @@ MochiKit.Base.update(MochiKit.Base, {
/** @id MochiKit.Base.evalJSON */
- evalJSON: function () {
- return eval("(" + MochiKit.Base._filterJSON(arguments[0]) + ")");
+ evalJSON: function (jsonText) {
+ return eval("(" + MochiKit.Base._filterJSON(jsonText) + ")");
},
@@ -848,6 +866,3 @@ MochiKit.Base.update(MochiKit.Base, {
var m = s.match(/^\s*\/\*(.*)\*\/\s*$/);
- if (m) {
- return m[1];
- }
- return s;
+ return (m) ? m[1] : s;
},
@@ -896,2 +911,8 @@ MochiKit.Base.update(MochiKit.Base, {
var newObj;
+ if (typeof(o.toJSON) == "function") {
+ newObj = o.toJSON();
+ if (o !== newObj) {
+ return me(newObj);
+ }
+ }
if (typeof(o.__json__) == "function") {
@@ -1102,3 +1123,3 @@ MochiKit.Base.update(MochiKit.Base, {
}
- data.sort(compare);
+ data.sort(MochiKit.Base.compare);
if (data.length % 2 == 0) {
@@ -1292,12 +1313,27 @@ MochiKit.Base.AdapterRegistry.prototype = {
-MochiKit.Base._exportSymbols = function (globals, module) {
- if (MochiKit.__export__ === false || module.__export__ === false) {
- return;
- }
- for (var k in module) {
- var v = module[k];
- if (v != null) {
- var okName = (k[0] !== "_" && k !== "toString");
- if (v.__export__ === true || (v.__export__ !== false && okName)) {
- globals[k] = module[k];
+/**
+ * Exports all symbols from one or more modules into the specified
+ * namespace (or scope). This is similar to MochiKit.Base.update(),
+ * except for special handling of the "__export__" flag, contained
+ * sub-modules (exported recursively), and names starting with "_".
+ *
+ * @param {Object} namespace the object or scope to modify
+ * @param {Object} module the module to export
+ */
+MochiKit.Base.moduleExport = function (namespace, module/*, ...*/) {
+ var SKIP = { toString: true, NAME: true, VERSION: true };
+ var mods = MochiKit.Base.extend([], arguments, 1);
+ while ((module = mods.shift()) != null) {
+ for (var k in module) {
+ var v = module[k];
+ if (v != null) {
+ var flagSet = (typeof(v.__export__) == 'boolean');
+ var nameValid = (k[0] !== "_" && !SKIP[k]);
+ if (flagSet ? v.__export__ : nameValid) {
+ if (typeof(v) == 'object' && v.NAME && v.VERSION) {
+ mods.push(v);
+ } else {
+ namespace[k] = module[k];
+ }
+ }
}
@@ -1305,2 +1341,13 @@ MochiKit.Base._exportSymbols = function (globals, module) {
}
+ return namespace;
+};
+
+/**
+ * Identical to moduleExport, but also considers the global and
+ * module-specific "__export__" flag.
+ */
+MochiKit.Base._exportSymbols = function (namespace, module) {
+ if (MochiKit.__export__ !== false && module.__export__ !== false) {
+ MochiKit.Base.moduleExport(namespace, module);
+ }
};
@@ -1323,3 +1370,3 @@ MochiKit.Base._exportSymbols = function (globals, module) {
* @param {Boolean} [exportable] the exportable function flag,
- * defaults to true
+ * defaults to false
*/
@@ -1351,7 +1398,5 @@ MochiKit.Base._deprecated = function (module, name, target, version, exportable)
};
- if (exportable === false) {
- func.__export__ = false;
- }
+ func.__export__ = (exportable === true);
module[name] = func;
-}
+};
@@ -1364,4 +1409,4 @@ MochiKit.Base.__new__ = function () {
// Backwards compat
- m._deprecated(m, 'forward', 'MochiKit.Base.forwardCall', '1.3', false);
- m._deprecated(m, 'find', 'MochiKit.Base.findValue', '1.3', false);
+ m._deprecated(m, 'forward', 'MochiKit.Base.forwardCall', '1.3');
+ m._deprecated(m, 'find', 'MochiKit.Base.findValue', '1.3');
@@ -1377,3 +1422,3 @@ MochiKit.Base.__new__ = function () {
).replace(/\"/g,'%22'
- ).rval.replace(/\'/g, '%27');
+ ).replace(/\'/g, '%27');
};
@@ -1387,2 +1432,3 @@ MochiKit.Base.__new__ = function () {
m.NamedError.prototype = new Error();
+ m.NamedError.prototype.constructor = m.NamedError;
m.update(m.NamedError.prototype, {
@@ -1411,2 +1457,4 @@ MochiKit.Base.__new__ = function () {
m.isUndefined = m.typeMatcher('undefined');
+ /** @id MochiKit.Base.isValue */
+ m.isValue = m.typeMatcher('boolean', 'number', 'string');