mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-03-14 01:19:49 +01:00
Update jquery.qrcode, jquery.scrollpanel and modulejs.
This commit is contained in:
parent
709e139b82
commit
6fbe0e5056
@ -8,7 +8,9 @@
|
||||
* adds editorconfig
|
||||
* updates build process, now uses [mkr](http://larsjung.de/mkr/) and [fQuery](http://larsjung.de/fquery/)
|
||||
* removes `jQuery.fracs`
|
||||
* updates `modulejs` to 1.0.0
|
||||
* updates `jQuery.qrcode` to 0.10.1
|
||||
* updates `jQuery.scrollpanel` to 0.4.0
|
||||
* updates `modulejs` to 1.4.0
|
||||
|
||||
|
||||
## v0.26.1 - *2014-08-17*
|
||||
|
2286
src/_h5ai/client/js/lib/jquery.qrcode-0.10.1.js
Normal file
2286
src/_h5ai/client/js/lib/jquery.qrcode-0.10.1.js
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,243 +0,0 @@
|
||||
/*! jQuery.scrollpanel 0.1 - //larsjung.de/scrollpanel - MIT License */
|
||||
|
||||
(function ($) {
|
||||
'use strict';
|
||||
|
||||
var $window = $(window),
|
||||
|
||||
name = 'scrollpanel',
|
||||
|
||||
defaults = {
|
||||
prefix: 'sp-'
|
||||
},
|
||||
|
||||
// Scrollpanel
|
||||
// ===========
|
||||
ScrollPanel = function (element, options) {
|
||||
|
||||
var self = this;
|
||||
|
||||
// Main reference.
|
||||
self.$el = $(element);
|
||||
|
||||
self.settings = $.extend({}, defaults, options);
|
||||
var prefix = self.settings.prefix;
|
||||
|
||||
// Mouse offset on drag start.
|
||||
self.mouseOffsetY = 0;
|
||||
// Interval ID for automatic scrollbar updates.
|
||||
self.updateId = 0;
|
||||
|
||||
// Proxy to easily bind and unbind this method.
|
||||
self.scrollProxy = $.proxy(self.scroll, self);
|
||||
|
||||
// Make content space relative, if not already.
|
||||
if (!self.$el.css('position') || self.$el.css('position') === 'static') {
|
||||
self.$el.css('position', 'relative');
|
||||
}
|
||||
|
||||
|
||||
// Create scrollbar.
|
||||
self.$scrollbar = $('<div class="' + prefix + 'scrollbar" />');
|
||||
self.$thumb = $('<div class="' + prefix + 'thumb" />').appendTo(self.$scrollbar);
|
||||
|
||||
// Wrap element's content and add scrollbar.
|
||||
self.$el
|
||||
.addClass(prefix + 'host')
|
||||
.wrapInner('<div class="' + prefix + 'viewport"><div class="' + prefix + 'container" /></div>')
|
||||
.append(self.$scrollbar);
|
||||
|
||||
// // Get references.
|
||||
self.$viewport = self.$el.find('> .' + prefix + 'viewport');
|
||||
self.$container = self.$viewport.find('> .' + prefix + 'container');
|
||||
|
||||
|
||||
// Host
|
||||
// ----
|
||||
self.$el
|
||||
|
||||
// Handle mouse wheel.
|
||||
.on('mousewheel', function (event, delta, deltaX, deltaY) {
|
||||
|
||||
self.$viewport.scrollTop(self.$viewport.scrollTop() - 50 * deltaY);
|
||||
self.update();
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
})
|
||||
|
||||
// Handle scrolling.
|
||||
.on('scroll', function () {
|
||||
|
||||
self.update();
|
||||
});
|
||||
|
||||
|
||||
// Viewport
|
||||
// --------
|
||||
self.$viewport
|
||||
|
||||
// Basic styling.
|
||||
.css({
|
||||
paddingRight: self.$scrollbar.outerWidth(true),
|
||||
height: self.$el.height(),
|
||||
overflow: 'hidden'
|
||||
});
|
||||
|
||||
|
||||
// Container
|
||||
// ---------
|
||||
self.$container
|
||||
|
||||
// Basic styling.
|
||||
.css({
|
||||
overflow: 'hidden'
|
||||
});
|
||||
|
||||
|
||||
// Srollbar
|
||||
// --------
|
||||
self.$scrollbar
|
||||
|
||||
// Basic styling.
|
||||
.css({
|
||||
position: 'absolute',
|
||||
top: 0,
|
||||
right: 0,
|
||||
overflow: 'hidden'
|
||||
})
|
||||
|
||||
// Handle mouse buttons.
|
||||
.on('mousedown', function (event) {
|
||||
|
||||
self.mouseOffsetY = self.$thumb.outerHeight() / 2;
|
||||
self.onMousedown(event);
|
||||
})
|
||||
|
||||
// Disable selection.
|
||||
.each(function () {
|
||||
|
||||
self.onselectstart = function () {
|
||||
|
||||
return false;
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
// Scrollbar Thumb
|
||||
// ---------------
|
||||
self.$thumb
|
||||
|
||||
// Basic styling.
|
||||
.css({
|
||||
position: 'absolute',
|
||||
left: 0,
|
||||
width: '100%'
|
||||
})
|
||||
|
||||
// Handle mouse buttons.
|
||||
.on('mousedown', function (event) {
|
||||
|
||||
self.mouseOffsetY = event.pageY - self.$thumb.offset().top;
|
||||
self.onMousedown(event);
|
||||
});
|
||||
|
||||
// Initial update.
|
||||
self.update();
|
||||
};
|
||||
|
||||
// Scrollpanel methods
|
||||
// ===================
|
||||
$.extend(ScrollPanel.prototype, {
|
||||
|
||||
// Rerender scrollbar.
|
||||
update: function (repeat) {
|
||||
|
||||
var self = this;
|
||||
|
||||
if (self.updateId && !repeat) {
|
||||
clearInterval(self.updateId);
|
||||
self.updateId = 0;
|
||||
} else if (!self.updateId && repeat) {
|
||||
self.updateId = setInterval(function() {
|
||||
self.update(true);
|
||||
}, 50);
|
||||
}
|
||||
|
||||
self.$viewport.css('height', self.$el.height());
|
||||
|
||||
var visibleHeight = self.$el.height(),
|
||||
contentHeight = self.$container.outerHeight(),
|
||||
scrollTop = self.$viewport.scrollTop(),
|
||||
scrollTopFrac = scrollTop / contentHeight,
|
||||
visVertFrac = Math.min(visibleHeight / contentHeight, 1),
|
||||
scrollbarHeight = self.$scrollbar.height();
|
||||
|
||||
if (visVertFrac < 1) {
|
||||
self.$scrollbar
|
||||
.css({
|
||||
height: self.$el.innerHeight() + scrollbarHeight - self.$scrollbar.outerHeight(true)
|
||||
})
|
||||
.fadeIn(50);
|
||||
self.$thumb
|
||||
.css({
|
||||
top: scrollbarHeight * scrollTopFrac,
|
||||
height: scrollbarHeight * visVertFrac
|
||||
});
|
||||
} else {
|
||||
self.$scrollbar.fadeOut(50);
|
||||
}
|
||||
},
|
||||
|
||||
// Scroll content according to mouse position.
|
||||
scroll: function (event) {
|
||||
|
||||
var self = this,
|
||||
clickFrac = (event.pageY - self.$scrollbar.offset().top - self.mouseOffsetY) / self.$scrollbar.height();
|
||||
|
||||
self.$viewport.scrollTop(self.$container.outerHeight() * clickFrac);
|
||||
self.update();
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
},
|
||||
|
||||
// Handle mousedown events on scrollbar.
|
||||
onMousedown: function (event) {
|
||||
|
||||
var self = this;
|
||||
|
||||
self.scroll(event);
|
||||
self.$scrollbar.addClass('active');
|
||||
$window
|
||||
.on('mousemove', self.scrollProxy)
|
||||
.one('mouseup', function (event) {
|
||||
|
||||
self.$scrollbar.removeClass('active');
|
||||
$window.off('mousemove', self.scrollProxy);
|
||||
self.scroll(event);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Register the plug in
|
||||
// --------------------
|
||||
$.fn[name] = function (options, options2) {
|
||||
|
||||
return this.each(function () {
|
||||
|
||||
var $this = $(this),
|
||||
scrollpanel = $this.data(name);
|
||||
|
||||
if (!scrollpanel) {
|
||||
scrollpanel = new ScrollPanel(this, options);
|
||||
scrollpanel.update();
|
||||
$this.data(name, scrollpanel);
|
||||
}
|
||||
|
||||
if (options === 'update') {
|
||||
scrollpanel.update(options2);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
}(jQuery));
|
245
src/_h5ai/client/js/lib/jquery.scrollpanel-0.4.0.js
Normal file
245
src/_h5ai/client/js/lib/jquery.scrollpanel-0.4.0.js
Normal file
@ -0,0 +1,245 @@
|
||||
/* jQuery.scrollpanel 0.4.0 - http://larsjung.de/jquery-scrollpanel/ */
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var $ = jQuery;
|
||||
var $window = $(window);
|
||||
|
||||
var name = 'scrollpanel';
|
||||
|
||||
var defaults = {
|
||||
prefix: 'sp-'
|
||||
};
|
||||
|
||||
|
||||
// Scrollpanel
|
||||
// ===========
|
||||
function ScrollPanel(element, options) {
|
||||
|
||||
var self = this;
|
||||
|
||||
// Main reference.
|
||||
self.$el = $(element);
|
||||
|
||||
self.settings = $.extend({}, defaults, options);
|
||||
var prefix = self.settings.prefix;
|
||||
|
||||
// Mouse offset on drag start.
|
||||
self.mouseOffsetY = 0;
|
||||
// Interval ID for automatic scrollbar updates.
|
||||
self.updateId = 0;
|
||||
|
||||
// Proxy to easily bind and unbind this method.
|
||||
self.scrollProxy = $.proxy(self.scroll, self);
|
||||
|
||||
// Make content space relative, if not already.
|
||||
if (!self.$el.css('position') || self.$el.css('position') === 'static') {
|
||||
self.$el.css('position', 'relative');
|
||||
}
|
||||
|
||||
|
||||
// Create scrollbar.
|
||||
self.$scrollbar = $('<div class="' + prefix + 'scrollbar" />');
|
||||
self.$thumb = $('<div class="' + prefix + 'thumb" />').appendTo(self.$scrollbar);
|
||||
|
||||
// Wrap element's content and add scrollbar.
|
||||
self.$el
|
||||
.addClass(prefix + 'host')
|
||||
.wrapInner('<div class="' + prefix + 'viewport"><div class="' + prefix + 'container" /></div>')
|
||||
.append(self.$scrollbar);
|
||||
|
||||
// // Get references.
|
||||
self.$viewport = self.$el.find('> .' + prefix + 'viewport');
|
||||
self.$container = self.$viewport.find('> .' + prefix + 'container');
|
||||
|
||||
|
||||
// Host
|
||||
// ----
|
||||
self.$el
|
||||
|
||||
// Handle mouse wheel.
|
||||
.on('mousewheel', function (event, delta, deltaX, deltaY) {
|
||||
|
||||
self.$viewport.scrollTop(self.$viewport.scrollTop() - 50 * deltaY);
|
||||
self.update();
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
})
|
||||
|
||||
// Handle scrolling.
|
||||
.on('scroll', function () {
|
||||
|
||||
self.update();
|
||||
});
|
||||
|
||||
|
||||
// Viewport
|
||||
// --------
|
||||
self.$viewport
|
||||
|
||||
// Basic styling.
|
||||
.css({
|
||||
paddingRight: self.$scrollbar.outerWidth(true),
|
||||
height: self.$el.height(),
|
||||
overflow: 'hidden'
|
||||
});
|
||||
|
||||
|
||||
// Container
|
||||
// ---------
|
||||
self.$container
|
||||
|
||||
// Basic styling.
|
||||
.css({
|
||||
overflow: 'hidden'
|
||||
});
|
||||
|
||||
|
||||
// Srollbar
|
||||
// --------
|
||||
self.$scrollbar
|
||||
|
||||
// Basic styling.
|
||||
.css({
|
||||
position: 'absolute',
|
||||
top: 0,
|
||||
right: 0,
|
||||
overflow: 'hidden'
|
||||
})
|
||||
|
||||
// Handle mouse buttons.
|
||||
.on('mousedown', function (event) {
|
||||
|
||||
self.mouseOffsetY = self.$thumb.outerHeight() / 2;
|
||||
self.onMousedown(event);
|
||||
})
|
||||
|
||||
// Disable selection.
|
||||
.each(function () {
|
||||
|
||||
self.onselectstart = function () {
|
||||
|
||||
return false;
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
// Scrollbar Thumb
|
||||
// ---------------
|
||||
self.$thumb
|
||||
|
||||
// Basic styling.
|
||||
.css({
|
||||
position: 'absolute',
|
||||
left: 0,
|
||||
width: '100%'
|
||||
})
|
||||
|
||||
// Handle mouse buttons.
|
||||
.on('mousedown', function (event) {
|
||||
|
||||
self.mouseOffsetY = event.pageY - self.$thumb.offset().top;
|
||||
self.onMousedown(event);
|
||||
});
|
||||
|
||||
// Initial update.
|
||||
self.update();
|
||||
}
|
||||
|
||||
|
||||
// Scrollpanel methods
|
||||
// ===================
|
||||
$.extend(ScrollPanel.prototype, {
|
||||
|
||||
// Rerender scrollbar.
|
||||
update: function (repeat) {
|
||||
|
||||
var self = this;
|
||||
|
||||
if (self.updateId && !repeat) {
|
||||
clearInterval(self.updateId);
|
||||
self.updateId = 0;
|
||||
} else if (!self.updateId && repeat) {
|
||||
self.updateId = setInterval(function() {
|
||||
self.update(true);
|
||||
}, 50);
|
||||
}
|
||||
|
||||
self.$viewport.css('height', self.$el.height());
|
||||
|
||||
var visibleHeight = self.$el.height(),
|
||||
contentHeight = self.$container.outerHeight(),
|
||||
scrollTop = self.$viewport.scrollTop(),
|
||||
scrollTopFrac = scrollTop / contentHeight,
|
||||
visVertFrac = Math.min(visibleHeight / contentHeight, 1),
|
||||
scrollbarHeight = self.$scrollbar.height();
|
||||
|
||||
if (visVertFrac < 1) {
|
||||
self.$scrollbar
|
||||
.css({
|
||||
height: self.$el.innerHeight() + scrollbarHeight - self.$scrollbar.outerHeight(true)
|
||||
})
|
||||
.fadeIn(50);
|
||||
self.$thumb
|
||||
.css({
|
||||
top: scrollbarHeight * scrollTopFrac,
|
||||
height: scrollbarHeight * visVertFrac
|
||||
});
|
||||
} else {
|
||||
self.$scrollbar.fadeOut(50);
|
||||
}
|
||||
},
|
||||
|
||||
// Scroll content according to mouse position.
|
||||
scroll: function (event) {
|
||||
|
||||
var self = this,
|
||||
clickFrac = (event.pageY - self.$scrollbar.offset().top - self.mouseOffsetY) / self.$scrollbar.height();
|
||||
|
||||
self.$viewport.scrollTop(self.$container.outerHeight() * clickFrac);
|
||||
self.update();
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
},
|
||||
|
||||
// Handle mousedown events on scrollbar.
|
||||
onMousedown: function (event) {
|
||||
|
||||
var self = this;
|
||||
|
||||
self.scroll(event);
|
||||
self.$scrollbar.addClass('active');
|
||||
$window
|
||||
.on('mousemove', self.scrollProxy)
|
||||
.one('mouseup', function (event) {
|
||||
|
||||
self.$scrollbar.removeClass('active');
|
||||
$window.off('mousemove', self.scrollProxy);
|
||||
self.scroll(event);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Register the plug in
|
||||
// --------------------
|
||||
$.fn[name] = function (options, options2) {
|
||||
|
||||
return this.each(function () {
|
||||
|
||||
var $this = $(this);
|
||||
var scrollpanel = $this.data(name);
|
||||
|
||||
if (!scrollpanel) {
|
||||
scrollpanel = new ScrollPanel(this, options);
|
||||
scrollpanel.update();
|
||||
$this.data(name, scrollpanel);
|
||||
}
|
||||
|
||||
if (options === 'update') {
|
||||
scrollpanel.update(options2);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
}());
|
@ -1,292 +0,0 @@
|
||||
/* modulejs 1.0.0 - http://larsjung.de/modulejs/ */
|
||||
(function (global, name) {
|
||||
'use strict';
|
||||
|
||||
|
||||
// Helpers
|
||||
// -------
|
||||
|
||||
// References.
|
||||
var objProto = Object.prototype,
|
||||
arrayForEach = Array.prototype.forEach,
|
||||
|
||||
// Returns a function that returns `true` if `arg` is of the correct `type`, otherwise `false`.
|
||||
createIsTypeFn = function (type) {
|
||||
|
||||
return function (arg) {
|
||||
|
||||
return objProto.toString.call(arg) === '[object ' + type + ']';
|
||||
};
|
||||
},
|
||||
|
||||
// ### 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) {
|
||||
|
||||
return arg === new Object(arg);
|
||||
},
|
||||
|
||||
// ### has
|
||||
// Short cut for `hasOwnProperty`.
|
||||
has = function (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) {
|
||||
|
||||
if (arrayForEach && obj.forEach === arrayForEach) {
|
||||
obj.forEach(iterator, context);
|
||||
} else if (obj.length === +obj.length) {
|
||||
for (var i = 0, l = obj.length; i < l; i += 1) {
|
||||
iterator.call(context, obj[i], i, obj);
|
||||
}
|
||||
} else {
|
||||
for (var key in obj) {
|
||||
if (has(obj, key)) {
|
||||
iterator.call(context, obj[key], key, obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// ### contains
|
||||
// Returns `true` if array contains element, otherwise `false`.
|
||||
contains = function (array, element) {
|
||||
|
||||
for (var i = 0, l = array.length; i < l; i += 1) {
|
||||
if (array[i] === element) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
// ### uniq
|
||||
// Returns an new array containing no duplicates. Preserves first occurence and order.
|
||||
uniq = function (array) {
|
||||
|
||||
var elements = {},
|
||||
result = [];
|
||||
|
||||
each(array, function (el) {
|
||||
|
||||
if (!has(elements, el)) {
|
||||
result.push(el);
|
||||
elements[el] = 1;
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
// ### err
|
||||
// Throws an error if `condition` is `true`.
|
||||
err = function (condition, code, message) {
|
||||
|
||||
if (condition) {
|
||||
throw {
|
||||
// machine readable
|
||||
code: code,
|
||||
|
||||
// human readable
|
||||
msg: message,
|
||||
|
||||
// let it be helpful in consoles
|
||||
toString: function () {
|
||||
|
||||
return name + ' error ' + code + ': ' + message;
|
||||
}
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
|
||||
// Private
|
||||
// -------
|
||||
|
||||
// ### definitions
|
||||
// Module definitions.
|
||||
definitions = {},
|
||||
|
||||
// ### instances
|
||||
// Module instances.
|
||||
instances = {},
|
||||
|
||||
// ### 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 + '"');
|
||||
|
||||
// if a module is required that was already created return that object
|
||||
if (!onlyDepIds && has(instances, id)) {
|
||||
return instances[id];
|
||||
}
|
||||
|
||||
// check if `id` is defined
|
||||
var def = definitions[id];
|
||||
err(!def, 32, 'id not defined "' + id + '"');
|
||||
|
||||
// copy resolve stack and add this `id`
|
||||
stack = (stack || []).slice(0);
|
||||
stack.push(id);
|
||||
|
||||
// if onlyDepIds this will hold the dependency-ids, otherwise it will hold the dependency-objects
|
||||
var deps = [];
|
||||
|
||||
each(def.deps, function (depId) {
|
||||
|
||||
// check for circular dependencies
|
||||
err(contains(stack, depId), 33, 'circular dependencies: ' + stack + ' & ' + depId);
|
||||
|
||||
if (onlyDepIds) {
|
||||
deps = deps.concat(resolve(depId, onlyDepIds, stack));
|
||||
deps.push(depId);
|
||||
} else {
|
||||
deps.push(resolve(depId, onlyDepIds, stack));
|
||||
}
|
||||
});
|
||||
|
||||
// if `onlyDepIds` return only dependency-ids in right order
|
||||
if (onlyDepIds) {
|
||||
return uniq(deps);
|
||||
}
|
||||
|
||||
// create, memorize and return object
|
||||
var obj = def.fn.apply(global, deps);
|
||||
instances[id] = obj;
|
||||
return obj;
|
||||
},
|
||||
|
||||
|
||||
|
||||
// Public
|
||||
// ------
|
||||
|
||||
// ### define
|
||||
// Defines a module for `id: String`, optional `deps: Array[String]`,
|
||||
// `arg: Object/function`.
|
||||
define = function (id, deps, arg) {
|
||||
|
||||
// sort arguments
|
||||
if (arg === undefined) {
|
||||
arg = deps;
|
||||
deps = [];
|
||||
}
|
||||
// check arguments
|
||||
err(!isString(id), 11, 'id must be a string "' + id + '"');
|
||||
err(definitions[id], 12, 'id already defined "' + id + '"');
|
||||
err(!isArray(deps), 13, 'dependencies for "' + id + '" must be an array "' + deps + '"');
|
||||
err(!isObject(arg) && !isFunction(arg), 14, 'arg for "' + id + '" must be object or function "' + arg + '"');
|
||||
|
||||
// accept definition
|
||||
definitions[id] = {
|
||||
id: id,
|
||||
deps: deps,
|
||||
fn: isFunction(arg) ? arg : function () { return arg; }
|
||||
};
|
||||
},
|
||||
|
||||
// ### require
|
||||
// Returns an instance for `id`.
|
||||
require = function (id) {
|
||||
|
||||
return resolve(id);
|
||||
},
|
||||
|
||||
// ### state
|
||||
// Returns an object that holds infos about the current definitions and dependencies.
|
||||
state = function () {
|
||||
|
||||
var res = {};
|
||||
|
||||
each(definitions, function (def, id) {
|
||||
|
||||
res[id] = {
|
||||
|
||||
// direct dependencies
|
||||
deps: def.deps.slice(0),
|
||||
|
||||
// transitive dependencies
|
||||
reqs: resolve(id, true),
|
||||
|
||||
// already initiated/required
|
||||
init: has(instances, id)
|
||||
};
|
||||
});
|
||||
|
||||
each(definitions, function (def, id) {
|
||||
|
||||
var inv = [];
|
||||
each(definitions, function (def2, id2) {
|
||||
|
||||
if (contains(res[id2].reqs, id)) {
|
||||
inv.push(id2);
|
||||
}
|
||||
});
|
||||
|
||||
// all inverse dependencies
|
||||
res[id].reqd = inv;
|
||||
});
|
||||
|
||||
return res;
|
||||
},
|
||||
|
||||
// ### log
|
||||
// Returns a string that displays module dependencies.
|
||||
log = function (inv) {
|
||||
|
||||
var out = '\n';
|
||||
|
||||
each(state(), function (st, id) {
|
||||
|
||||
var list = inv ? st.reqd : st.reqs;
|
||||
out += (st.init ? '* ' : ' ') + id + ' -> [ ' + list.join(', ') + ' ]\n';
|
||||
});
|
||||
|
||||
return out;
|
||||
};
|
||||
|
||||
|
||||
// Register Public API
|
||||
// -------------------
|
||||
global[name] = {
|
||||
define: define,
|
||||
require: require,
|
||||
state: state,
|
||||
log: log,
|
||||
_private: {
|
||||
isString: isString,
|
||||
isFunction: isFunction,
|
||||
isArray: isArray,
|
||||
isObject: isObject,
|
||||
has: has,
|
||||
each: each,
|
||||
contains: contains,
|
||||
uniq: uniq,
|
||||
err: err,
|
||||
definitions: definitions,
|
||||
instances: instances,
|
||||
resolve: resolve
|
||||
}
|
||||
};
|
||||
|
||||
}(this, 'modulejs'));
|
291
src/_h5ai/client/js/lib/modulejs-1.4.0.js
Normal file
291
src/_h5ai/client/js/lib/modulejs-1.4.0.js
Normal file
@ -0,0 +1,291 @@
|
||||
/* modulejs 1.4.0 - http://larsjung.de/modulejs/ */
|
||||
(function (global) {
|
||||
'use strict';
|
||||
|
||||
var name = 'modulejs';
|
||||
|
||||
// # Util
|
||||
|
||||
// References.
|
||||
var objectPrototype = Object.prototype;
|
||||
var arrayForEach = Array.prototype.forEach;
|
||||
|
||||
// Returns a function that returns `true` if `arg` is of the correct `type`, otherwise `false`.
|
||||
function createIsTypeFn(type) {
|
||||
|
||||
return function (arg) {
|
||||
|
||||
return objectPrototype.toString.call(arg) === '[object ' + type + ']';
|
||||
};
|
||||
}
|
||||
|
||||
// ## isString
|
||||
// Returns `true` if argument is a string, otherwise `false`.
|
||||
var isString = createIsTypeFn('String');
|
||||
|
||||
// ## isFunction
|
||||
// Returns `true` if argument is a function, otherwise `false`.
|
||||
var isFunction = createIsTypeFn('Function');
|
||||
|
||||
// ## isArray
|
||||
// Returns `true` if argument is an array, otherwise `false`.
|
||||
var isArray = Array.isArray || createIsTypeFn('Array');
|
||||
|
||||
// ## isObject
|
||||
// Returns `true` if argument is an object, otherwise `false`.
|
||||
function isObject(arg) {
|
||||
|
||||
return arg === new Object(arg);
|
||||
}
|
||||
|
||||
// ## has
|
||||
// Short cut for `hasOwnProperty`.
|
||||
function has(arg, id) {
|
||||
|
||||
return objectPrototype.hasOwnProperty.call(arg, id);
|
||||
}
|
||||
|
||||
// ## each
|
||||
// Iterates over all elements af an array or all own keys of an object.
|
||||
function each(obj, iterator, context) {
|
||||
|
||||
if (arrayForEach && obj.forEach === arrayForEach) {
|
||||
obj.forEach(iterator, context);
|
||||
} else if (obj.length === +obj.length) {
|
||||
for (var i = 0, l = obj.length; i < l; i += 1) {
|
||||
iterator.call(context, obj[i], i, obj);
|
||||
}
|
||||
} else {
|
||||
for (var key in obj) {
|
||||
if (has(obj, key)) {
|
||||
iterator.call(context, obj[key], key, obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ## contains
|
||||
// Returns `true` if array contains element, otherwise `false`.
|
||||
function contains(array, element) {
|
||||
|
||||
for (var i = 0, l = array.length; i < l; i += 1) {
|
||||
if (array[i] === element) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ## uniq
|
||||
// Returns an new array containing no duplicates. Preserves first occurence and order.
|
||||
function uniq(array) {
|
||||
|
||||
var elements = {};
|
||||
var result = [];
|
||||
|
||||
each(array, function (el) {
|
||||
|
||||
if (!has(elements, el)) {
|
||||
result.push(el);
|
||||
elements[el] = 1;
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// ## err
|
||||
// Throws an error if `condition` is `true`.
|
||||
function err(condition, code, message) {
|
||||
|
||||
if (condition) {
|
||||
throw {
|
||||
// machine readable
|
||||
code: code,
|
||||
|
||||
// human readable
|
||||
msg: message,
|
||||
|
||||
// let it be helpful in consoles
|
||||
toString: function () {
|
||||
|
||||
return name + ' error ' + code + ': ' + message;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// # Private
|
||||
|
||||
// ## definitions
|
||||
// Module definitions.
|
||||
var definitions = {};
|
||||
|
||||
// ## instances
|
||||
// Module instances.
|
||||
var instances = {};
|
||||
|
||||
// ## 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.
|
||||
function resolve(id, onlyDepIds, stack) {
|
||||
|
||||
// check arguments
|
||||
err(!isString(id), 31, 'id must be a string "' + id + '"');
|
||||
|
||||
// if a module is required that was already created return that object
|
||||
if (!onlyDepIds && has(instances, id)) {
|
||||
return instances[id];
|
||||
}
|
||||
|
||||
// check if `id` is defined
|
||||
var def = definitions[id];
|
||||
err(!def, 32, 'id not defined "' + id + '"');
|
||||
|
||||
// copy resolve stack and add this `id`
|
||||
stack = (stack || []).slice(0);
|
||||
stack.push(id);
|
||||
|
||||
// if onlyDepIds this will hold the dependency-ids, otherwise it will hold the dependency-objects
|
||||
var deps = [];
|
||||
|
||||
each(def.deps, function (depId) {
|
||||
|
||||
// check for circular dependencies
|
||||
err(contains(stack, depId), 33, 'circular dependencies: ' + stack + ' & ' + depId);
|
||||
|
||||
if (onlyDepIds) {
|
||||
deps = deps.concat(resolve(depId, onlyDepIds, stack));
|
||||
deps.push(depId);
|
||||
} else {
|
||||
deps.push(resolve(depId, onlyDepIds, stack));
|
||||
}
|
||||
});
|
||||
|
||||
// if `onlyDepIds` return only dependency-ids in right order
|
||||
if (onlyDepIds) {
|
||||
return uniq(deps);
|
||||
}
|
||||
|
||||
// create, memorize and return object
|
||||
var obj = def.fn.apply(global, deps);
|
||||
instances[id] = obj;
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// # Public
|
||||
|
||||
// ## define
|
||||
// Defines a module for `id: String`, optional `deps: Array[String]`,
|
||||
// `arg: Object/function`.
|
||||
function define(id, deps, arg) {
|
||||
|
||||
// sort arguments
|
||||
if (arg === undefined) {
|
||||
arg = deps;
|
||||
deps = [];
|
||||
}
|
||||
// check arguments
|
||||
err(!isString(id), 11, 'id must be a string "' + id + '"');
|
||||
err(definitions[id], 12, 'id already defined "' + id + '"');
|
||||
err(!isArray(deps), 13, 'dependencies for "' + id + '" must be an array "' + deps + '"');
|
||||
err(!isObject(arg) && !isFunction(arg), 14, 'arg for "' + id + '" must be object or function "' + arg + '"');
|
||||
|
||||
// accept definition
|
||||
definitions[id] = {
|
||||
id: id,
|
||||
deps: deps,
|
||||
fn: isFunction(arg) ? arg : function () { return arg; }
|
||||
};
|
||||
}
|
||||
|
||||
// ## require
|
||||
// Returns an instance for `id`.
|
||||
function require(id) {
|
||||
|
||||
return resolve(id);
|
||||
}
|
||||
|
||||
// ## state
|
||||
// Returns an object that holds infos about the current definitions and dependencies.
|
||||
function state() {
|
||||
|
||||
var res = {};
|
||||
|
||||
each(definitions, function (def, id) {
|
||||
|
||||
res[id] = {
|
||||
|
||||
// direct dependencies
|
||||
deps: def.deps.slice(0),
|
||||
|
||||
// transitive dependencies
|
||||
reqs: resolve(id, true),
|
||||
|
||||
// already initiated/required
|
||||
init: has(instances, id)
|
||||
};
|
||||
});
|
||||
|
||||
each(definitions, function (def, id) {
|
||||
|
||||
var inv = [];
|
||||
each(definitions, function (def2, id2) {
|
||||
|
||||
if (contains(res[id2].reqs, id)) {
|
||||
inv.push(id2);
|
||||
}
|
||||
});
|
||||
|
||||
// all inverse dependencies
|
||||
res[id].reqd = inv;
|
||||
});
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
// ## log
|
||||
// Returns a string that displays module dependencies.
|
||||
function log(inv) {
|
||||
|
||||
var out = '\n';
|
||||
|
||||
each(state(), function (st, id) {
|
||||
|
||||
var list = inv ? st.reqd : st.reqs;
|
||||
out += (st.init ? '* ' : ' ') + id + ' -> [ ' + list.join(', ') + ' ]\n';
|
||||
});
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// # Publish
|
||||
|
||||
global[name] = {
|
||||
define: define,
|
||||
require: require,
|
||||
state: state,
|
||||
log: log,
|
||||
_private: {
|
||||
isString: isString,
|
||||
isFunction: isFunction,
|
||||
isArray: isArray,
|
||||
isObject: isObject,
|
||||
has: has,
|
||||
each: each,
|
||||
contains: contains,
|
||||
uniq: uniq,
|
||||
err: err,
|
||||
definitions: definitions,
|
||||
instances: instances,
|
||||
resolve: resolve
|
||||
}
|
||||
};
|
||||
|
||||
}(this));
|
Loading…
x
Reference in New Issue
Block a user