author | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2012-03-17 21:08:23 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2012-03-17 21:08:23 (UTC) |
commit | 928f3f3ed3981f7f81b69ed94f2a315205db39fa (patch) (side-by-side diff) | |
tree | 8a47229b56e4c906de8512baf0c5ca100bc03dfb /frontend/gamma/js/MochiKit/Base.js | |
parent | bf7d8191a3a6dbd092a88911098a3e7f6cf30cf7 (diff) | |
download | clipperz-928f3f3ed3981f7f81b69ed94f2a315205db39fa.zip clipperz-928f3f3ed3981f7f81b69ed94f2a315205db39fa.tar.gz clipperz-928f3f3ed3981f7f81b69ed94f2a315205db39fa.tar.bz2 |
Fixed frontend properties and updated MochiKit version
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 @@ -7,50 +7,61 @@ See <http://mochikit.com/> for documentation, downloads, license, etc. (c) 2005 Bob Ippolito. All rights Reserved. ***/ -if (typeof(MochiKit) == 'undefined') { - MochiKit = {}; -} + +// MochiKit module (namespace) +var MochiKit = MochiKit || {}; if (typeof(MochiKit.__export__) == "undefined") { MochiKit.__export__ = true; } -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; module.__repr__ = function () { return "[" + this.NAME + " " + this.VERSION + "]"; }; module.toString = function () { return this.__repr__(); }; - 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", []); /** @id MochiKit.Base.update */ MochiKit.Base.update = function (self, obj/*, ... */) { if (self === null || self === undefined) { @@ -239,8 +250,9 @@ MochiKit.Base.update(MochiKit.Base, { _newNamedError: function (module, name, func) { func.prototype = new MochiKit.Base.NamedError(module.NAME + "." + name); + func.prototype.constructor = func; module[name] = func; }, @@ -350,9 +362,9 @@ MochiKit.Base.update(MochiKit.Base, { value != "undefined" && value != "0"; } else if (typeof(value) === "number" || value instanceof Number) { return !isNaN(value) && value != 0; } else if (value != null && typeof(value.length) === "number") { - return value.length !== 0 + return value.length !== 0; } else { return value != null; } }, @@ -674,8 +686,11 @@ MochiKit.Base.update(MochiKit.Base, { }; newfunc.im_self = im_self; newfunc.im_func = im_func; newfunc.im_preargs = im_preargs; + if (typeof(im_func.NAME) == 'string') { + newfunc.NAME = "bind(" + im_func.NAME + ",...)"; + } return newfunc; }, /** @id MochiKit.Base.bindLate */ @@ -787,13 +802,16 @@ MochiKit.Base.update(MochiKit.Base, { return o.repr(); } return MochiKit.Base.reprRegistry.match(o); } 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) { } } try { var ostring = (o + ""); @@ -839,18 +857,15 @@ 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) + ")"); }, _filterJSON: function (s) { var m = s.match(/^\s*\/\*(.*)\*\/\s*$/); - if (m) { - return m[1]; - } - return s; + return (m) ? m[1] : s; }, /** @id MochiKit.Base.serializeJSON */ serializeJSON: function (o) { @@ -893,8 +908,14 @@ MochiKit.Base.update(MochiKit.Base, { var me = arguments.callee; // short-circuit for objects that support "json" serialization // if they return "self" then just pass-through... var newObj; + if (typeof(o.toJSON) == "function") { + newObj = o.toJSON(); + if (o !== newObj) { + return me(newObj); + } + } if (typeof(o.__json__) == "function") { newObj = o.__json__(); if (o !== newObj) { return me(newObj); @@ -1099,9 +1120,9 @@ MochiKit.Base.update(MochiKit.Base, { var data = MochiKit.Base.flattenArguments(arguments); if (data.length === 0) { throw new TypeError('median() requires at least one argument'); } - data.sort(compare); + data.sort(MochiKit.Base.compare); if (data.length % 2 == 0) { var upper = data.length / 2; return (data[upper] + data[upper - 1]) / 2; } else { @@ -1289,21 +1310,47 @@ MochiKit.Base.AdapterRegistry.prototype = { return false; } }; -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]; + } + } } } } + 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); + } }; /** * Creates a deprecated function alias in the specified module. The @@ -1320,9 +1367,9 @@ MochiKit.Base._exportSymbols = function (globals, module) { * function (e.g. 'MochiKit.Style.getStyle') * @param {String} version the first version when the source function * was deprecated (e.g. '1.4') * @param {Boolean} [exportable] the exportable function flag, - * defaults to true + * defaults to false */ MochiKit.Base._deprecated = function (module, name, target, version, exportable) { if (typeof(module) === 'string') { if (module.indexOf('MochiKit.') === 0) { @@ -1348,23 +1395,21 @@ MochiKit.Base._deprecated = function (module, name, target, version, exportable) throw new Error(msg); } return MochiKit[targetModule][targetName].apply(this, arguments); }; - if (exportable === false) { - func.__export__ = false; - } + func.__export__ = (exportable === true); module[name] = func; -} +}; MochiKit.Base.__new__ = function () { var m = this; /** @id MochiKit.Base.noop */ m.noop = m.operator.identity; // 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'); if (typeof(encodeURIComponent) != "undefined") { /** @id MochiKit.Base.urlEncode */ m.urlEncode = function (unencoded) { @@ -1374,9 +1419,9 @@ MochiKit.Base.__new__ = function () { m.urlEncode = function (unencoded) { return escape(unencoded ).replace(/\+/g, '%2B' ).replace(/\"/g,'%22' - ).rval.replace(/\'/g, '%27'); + ).replace(/\'/g, '%27'); }; } /** @id MochiKit.Base.NamedError */ @@ -1384,8 +1429,9 @@ MochiKit.Base.__new__ = function () { this.message = name; this.name = name; }; m.NamedError.prototype = new Error(); + m.NamedError.prototype.constructor = m.NamedError; m.update(m.NamedError.prototype, { repr: function () { if (this.message && this.message != this.name) { return this.name + "(" + m.repr(this.message) + ")"; @@ -1408,8 +1454,10 @@ MochiKit.Base.__new__ = function () { /** @id MochiKit.Base.isCallable */ m.isCallable = m.typeMatcher('function'); /** @id MochiKit.Base.isUndefined */ m.isUndefined = m.typeMatcher('undefined'); + /** @id MochiKit.Base.isValue */ + m.isValue = m.typeMatcher('boolean', 'number', 'string'); /** @id MochiKit.Base.merge */ m.merge = m.partial(m.update, null); /** @id MochiKit.Base.zip */ |