Update modulejs.

This commit is contained in:
Lars Jung
2014-08-04 01:26:11 +02:00
parent c777a9f949
commit 80d0952d1f
3 changed files with 94 additions and 46 deletions

View File

@@ -7,6 +7,7 @@
* removes True Type fonts * removes True Type fonts
* outsources themes to [h5ai-themes](https://github.com/lrsjng/h5ai-themes) * outsources themes to [h5ai-themes](https://github.com/lrsjng/h5ai-themes)
* replaces `markdown` with [`marked`](https://github.com/chjj/marked) * replaces `markdown` with [`marked`](https://github.com/chjj/marked)
* updates `modulejs` to 0.4.5
## v0.25.2 - *2014-07-01* ## v0.25.2 - *2014-07-01*
@@ -44,13 +45,13 @@
* fixes QR code URI origin (issue [#287](https://github.com/lrsjng/h5ai/issues/287)) * fixes QR code URI origin (issue [#287](https://github.com/lrsjng/h5ai/issues/287))
* replaces PHP backtick operator with `exec` * replaces PHP backtick operator with `exec`
* removes server side file manipulation extensions `dropbox`, `delete` and `rename` * removes server side file manipulation extensions `dropbox`, `delete` and `rename`
* updates H5BP to 4.3.0 * updates `H5BP` to 4.3.0
* updates jQuery to 2.1.1 * updates `jQuery` to 2.1.1
* updates json2.js to 2014-02-04 * updates `json2.js` to 2014-02-04
* updates markdown-js to 0.5.0 * updates `markdown-js` to 0.5.0
* updates Modernizr to 2.8.2 * updates `Modernizr` to 2.8.2
* updates Moment.js to 2.6.0 * updates `Moment.js` to 2.6.0
* updates Underscore.js to 1.6.0 * updates `Underscore.js` to 1.6.0
* language updates (`bg`, `ko`, `pt`, `sl`, `sv`, `zh-cn`) * language updates (`bg`, `ko`, `pt`, `sl`, `sv`, `zh-cn`)
@@ -95,12 +96,12 @@
* now uses scalable images for the interface * now uses scalable images for the interface
* fixes filter (ignore parent folder, display of `no match`) * fixes filter (ignore parent folder, display of `no match`)
* lots of small fixes * lots of small fixes
* updates H5BP to 4.2.0 * updates `H5BP` to 4.2.0
* updates jQuery to 2.0.3 * updates `jQuery` to 2.0.3
* updates jQuery.mousewheel to 3.1.3 * updates `jQuery.mousewheel` to 3.1.3
* updates Moment.js to 2.1.0 * updates `Moment.js` to 2.1.0
* updates markdown-js to 0.4.0-9c21acdf08 * updates `markdown-js` to 0.4.0-9c21acdf08
* updates json2.js to 2013-05-26 * updates `json2.js` to 2013-05-26
* adds `uk` translation by Viktor Matveenko * adds `uk` translation by Viktor Matveenko
* updates to `pl` translation by Mark * updates to `pl` translation by Mark

View File

@@ -14,6 +14,7 @@ modulejs.define('view/ensure', ['$', 'config', 'core/event'], function ($, confi
if ( if (
$(selr).text() !== sequence || $(selr).text() !== sequence ||
$(sela).attr('href') !== url ||
$(sela).filter(isVisible).length !== 1 || $(sela).filter(isVisible).length !== 1 ||
$(selr).filter(isVisible).length !== 1 || $(selr).filter(isVisible).length !== 1 ||
$(selb).filter(isVisible).length !== 1 $(selb).filter(isVisible).length !== 1

View File

@@ -1,35 +1,53 @@
/*! modulejs 0.2 - //larsjung.de/modulejs - MIT License */ /*! modulejs 0.4.5 - //larsjung.de/modulejs/ - MIT License */
(function (global, name) { (function (global, name) {
'use strict'; 'use strict';
// Helpers
// -------
// References.
var objProto = Object.prototype, var objProto = Object.prototype,
arrayForEach = Array.prototype.forEach, arrayForEach = Array.prototype.forEach,
isType = function (arg, type) {
return objProto.toString.call(arg) === '[object ' + type + ']'; // Returns a function that returns `true` if `arg` is of the correct `type`, otherwise `false`.
}, createIsTypeFn = function (type) {
isString = function (arg) {
return isType(arg, 'String'); return function (arg) {
},
isFunction = function (arg) {
return isType(arg, 'Function'); return objProto.toString.call(arg) === '[object ' + type + ']';
};
}, },
isArray = Array.isArray || function (arg) {
return isType(arg, 'Array'); // ### isString
}, // Returns `true` if argument is a string, otherwise `false`.
isString = createIsTypeFn('String'),
// ### isFunction
// Returns `true` if argument is a function, otherwise `false`.
isFunction = createIsTypeFn('Function'),
// ### isArray
// Returns `true` if argument is an array, otherwise `false`.
isArray = Array.isArray || createIsTypeFn('Array'),
// ### isObject
// Returns `true` if argument is an object, otherwise `false`.
isObject = function (arg) { isObject = function (arg) {
return arg === new Object(arg); return arg === new Object(arg);
}, },
// ### has
// Short cut for `hasOwnProperty`.
has = function (arg, id) { has = function (arg, id) {
return objProto.hasOwnProperty.call(arg, id); return objProto.hasOwnProperty.call(arg, id);
}, },
// ### each
// Iterates over all elements af an array or all own keys of an object.
each = function (obj, iterator, context) { each = function (obj, iterator, context) {
if (arrayForEach && obj.forEach === arrayForEach) { if (arrayForEach && obj.forEach === arrayForEach) {
@@ -46,15 +64,21 @@
} }
} }
}, },
contains = function (array, item) {
// ### contains
// Returns `true` if array contains element, otherwise `false`.
contains = function (array, element) {
for (var i = 0, l = array.length; i < l; i += 1) { for (var i = 0, l = array.length; i < l; i += 1) {
if (array[i] === item) { if (array[i] === element) {
return true; return true;
} }
} }
return false; return false;
}, },
// ### uniq
// Returns an new array containing no duplicates. Preserves first occurence and order.
uniq = function (array) { uniq = function (array) {
var elements = {}, var elements = {},
@@ -70,57 +94,84 @@
return result; return result;
}, },
// ### err
// Throws an error if `condition` is `true`.
err = function (condition, code, message) { err = function (condition, code, message) {
if (condition) { if (condition) {
throw { throw {
// machine readable
code: code, code: code,
// human readable
msg: message, msg: message,
// let it be helpful in consoles
toString: function () { toString: function () {
return name + ' error ' + code + ': ' + message; return name + ' error ' + code + ': ' + message;
} }
}; };
} }
}, },
// Private
// -------
// ### definitions
// Module definitions. // Module definitions.
definitions = {}, definitions = {},
// ### instances
// Module instances. // Module instances.
instances = {}, instances = {},
resolve = function (id, cold, stack) { // ### resolve
// Resolves an `id` to an object, or if `onlyDepIds` is `true` only returns dependency-ids.
// `stack` is used internal to check for circular dependencies.
resolve = function (id, onlyDepIds, stack) {
// check arguments
err(!isString(id), 31, 'id must be a string "' + id + '"'); err(!isString(id), 31, 'id must be a string "' + id + '"');
if (!cold && has(instances, id)) { // if a module is required that was already created return that object
if (!onlyDepIds && has(instances, id)) {
return instances[id]; return instances[id];
} }
// check if `id` is defined
var def = definitions[id]; var def = definitions[id];
err(!def, 32, 'id not defined "' + id + '"'); err(!def, 32, 'id not defined "' + id + '"');
// copy resolve stack and add this `id`
stack = (stack || []).slice(0); stack = (stack || []).slice(0);
stack.push(id); stack.push(id);
// if onlyDepIds this will hold the dependency-ids, otherwise it will hold the dependency-objects
var deps = []; var deps = [];
each(def.deps, function (depId, idx) { each(def.deps, function (depId) {
err(contains(stack, depId), 33, 'cyclic dependencies: ' + stack + ' & ' + depId); // check for circular dependencies
err(contains(stack, depId), 33, 'circular dependencies: ' + stack + ' & ' + depId);
if (cold) { if (onlyDepIds) {
deps = deps.concat(resolve(depId, cold, stack)); deps = deps.concat(resolve(depId, onlyDepIds, stack));
deps.push(depId); deps.push(depId);
} else { } else {
deps[idx] = resolve(depId, cold, stack); deps.push(resolve(depId, onlyDepIds, stack));
} }
}); });
if (cold) { // if `onlyDepIds` return only dependency-ids in right order
if (onlyDepIds) {
return uniq(deps); return uniq(deps);
} }
// create, memorize and return object
var obj = def.fn.apply(global, deps); var obj = def.fn.apply(global, deps);
instances[id] = obj; instances[id] = obj;
return obj; return obj;
@@ -128,8 +179,8 @@
// Public methods // Public
// -------------- // ------
// ### define // ### define
// Defines a module for `id: String`, optional `deps: Array[String]`, // Defines a module for `id: String`, optional `deps: Array[String]`,
@@ -222,13 +273,8 @@
define: define, define: define,
require: require, require: require,
state: state, state: state,
log: log log: log,
}; _private: {
// Uncomment to run internal tests.
/*
if (global[name.toUpperCase()] === true) {
global[name.toUpperCase()] = {
isString: isString, isString: isString,
isFunction: isFunction, isFunction: isFunction,
isArray: isArray, isArray: isArray,
@@ -241,7 +287,7 @@
definitions: definitions, definitions: definitions,
instances: instances, instances: instances,
resolve: resolve resolve: resolve
}; }
} // */ };
}(this, 'modulejs')); }(this, 'modulejs'));