author | Giulio Cesare Solaroli <giulio.cesare@solaroli.it> | 2012-03-17 21:18:52 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@solaroli.it> | 2012-03-17 21:18:52 (UTC) |
commit | 288b8df03a499a2e68ebaad48e687d1eac9df0ff (patch) (unidiff) | |
tree | 1fcaefffee8366b548465a05a6c4cba0c31e131d /frontend/gamma/js/MochiKit/Base.js | |
parent | 6f7ead0446aae6dd9f40b183e402b059a33d0517 (diff) | |
parent | 25029b943781850c76fbf43827af0204f35a98bf (diff) | |
download | clipperz-288b8df03a499a2e68ebaad48e687d1eac9df0ff.zip clipperz-288b8df03a499a2e68ebaad48e687d1eac9df0ff.tar.gz clipperz-288b8df03a499a2e68ebaad48e687d1eac9df0ff.tar.bz2 |
Merge pull request #34 from gcsolaroli/master
Fixed some resources
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 | |||
@@ -9,31 +9,41 @@ See <http://mochikit.com/> for documentation, downloads, license, etc. | |||
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 () { |
@@ -43,12 +53,13 @@ MochiKit.Base._module = function (name, version, deps) { | |||
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 */ |
@@ -241,4 +252,5 @@ MochiKit.Base.update(MochiKit.Base, { | |||
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 | }, |
@@ -352,5 +364,5 @@ MochiKit.Base.update(MochiKit.Base, { | |||
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; |
@@ -676,4 +688,7 @@ MochiKit.Base.update(MochiKit.Base, { | |||
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 | }, |
@@ -789,9 +804,12 @@ MochiKit.Base.update(MochiKit.Base, { | |||
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 | } |
@@ -841,14 +859,11 @@ MochiKit.Base.update(MochiKit.Base, { | |||
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 | ||
@@ -895,4 +910,10 @@ MochiKit.Base.update(MochiKit.Base, { | |||
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__(); |
@@ -1101,5 +1122,5 @@ MochiKit.Base.update(MochiKit.Base, { | |||
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; |
@@ -1291,17 +1312,43 @@ MochiKit.Base.AdapterRegistry.prototype = { | |||
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 | ||
@@ -1322,5 +1369,5 @@ MochiKit.Base._exportSymbols = function (globals, module) { | |||
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) { |
@@ -1350,9 +1397,7 @@ MochiKit.Base._deprecated = function (module, name, target, version, exportable) | |||
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 () { |
@@ -1363,6 +1408,6 @@ MochiKit.Base.__new__ = function () { | |||
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") { |
@@ -1376,5 +1421,5 @@ MochiKit.Base.__new__ = function () { | |||
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 | } |
@@ -1386,4 +1431,5 @@ MochiKit.Base.__new__ = function () { | |||
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 () { |
@@ -1410,4 +1456,6 @@ MochiKit.Base.__new__ = 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 */ |