Cleanup and DocBlocks

This commit is contained in:
Dennis Eichhorn 2016-05-29 00:00:40 +02:00
parent 7e11669ca3
commit e6a6a80368
16 changed files with 780 additions and 209 deletions

View File

@ -1,19 +1,37 @@
(function (jsOMS, undefined) { /**
jsOMS.Autoloader = {}; * Autoloader.
jsOMS.Autoloader.loaded = []; *
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0 * @since 1.0.0
*/
(function (jsOMS, undefined)
{
jsOMS.Autoloader = {};
jsOMS.Autoloader.loaded = [];
jsOMS.Autoloader.namespaced = []; jsOMS.Autoloader.namespaced = [];
jsOMS.Autoloader.defineNamespace = function(namespace) /**
* Define namespace
*
* @param {string} namespace Namespace
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.Autoloader.defineNamespace = function (namespace)
{ {
if(jsOMS.Autoloader.namespaced.indexOf(namespace) === -1) { if (jsOMS.Autoloader.namespaced.indexOf(namespace) === -1) {
let paths = namespace.split('.'); let paths = namespace.split('.');
paths.splice(0, 1); paths.splice(0, 1);
let length = paths.length, let length = paths.length,
current = jsOMS; current = jsOMS;
for(let i = 0; i < length; i++) { for (let i = 0; i < length; i++) {
if(typeof current[paths[i]] === 'undefined') { if (typeof current[paths[i]] === 'undefined') {
current[paths[i]] = {}; current[paths[i]] = {};
} }
@ -24,33 +42,56 @@
} }
}; };
jsOMS.Autoloader.initPreloaded = function() /**
* Collect all loaded javascript files
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.Autoloader.initPreloaded = function ()
{ {
let scripts = document.getElementsByTagName('script'), let scripts = document.getElementsByTagName('script'),
length = scripts.length; length = scripts.length;
for(let i = 0; i < length; i++) { for (let i = 0; i < length; i++) {
scripts[i].src.replace(URL + '/', ''); scripts[i].src.replace(URL + '/', '');
if(jsOMS.Autoloader.loaded.indexOf(scripts[i].src) === -1) { if (jsOMS.Autoloader.loaded.indexOf(scripts[i].src) === -1) {
jsOMS.Autoloader.loaded.push(scripts[i].src); jsOMS.Autoloader.loaded.push(scripts[i].src);
} }
} }
}; };
jsOMS.Autoloader.setPreloaded = function(file) /**
* Add loaded script
*
* @param {string} file Script URI
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.Autoloader.addPreloaded = function (file)
{ {
if(jsOMS.Autoloader.loaded.indexOf(file) === -1) { if (jsOMS.Autoloader.loaded.indexOf(file) === -1) {
jsOMS.Autoloader.loaded.push(file); jsOMS.Autoloader.loaded.push(file);
} }
}; };
jsOMS.Autoloader.include = function(file, callback) /**
* Include script
*
* @param {string} file Script URI
* @param {callback} callback Callback after script loading
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.Autoloader.include = function (file, callback)
{ {
let length = file.length; let length = file.length;
for(let i = 0; i < length; i++) { for (let i = 0; i < length; i++) {
if(jsOMS.Autoloader.loaded.indexOf(file) === -1) { if (jsOMS.Autoloader.loaded.indexOf(file) === -1) {
// todo: implement asset loading and pass callback // todo: implement asset loading and pass callback
jsOMS.Autoloader.loaded.push(file); jsOMS.Autoloader.loaded.push(file);

View File

@ -28,6 +28,16 @@
this.xhr = new XMLHttpRequest(); this.xhr = new XMLHttpRequest();
}; };
/**
* Get browser.
*
* @return {string}
*
* @method
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.Message.Request.Request.getBrowser = function () jsOMS.Message.Request.Request.getBrowser = function ()
{ {
if ((!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0) { if ((!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0) {
@ -47,6 +57,16 @@
} }
}; };
/**
* Get os.
*
* @return {string}
*
* @method
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.Message.Request.Request.getOS = function () jsOMS.Message.Request.Request.getOS = function ()
{ {
for (let os in jsOMS.Message.Request.OSType) { for (let os in jsOMS.Message.Request.OSType) {

View File

@ -12,7 +12,7 @@
(function (jsOMS, undefined) (function (jsOMS, undefined)
{ {
jsOMS.Autoloader.defineNamespace('jsOMS.Message.Request'); jsOMS.Autoloader.defineNamespace('jsOMS.Message.Request');
/** /**
* @constructor * @constructor
* *
@ -21,22 +21,45 @@
*/ */
jsOMS.Message.Request.RequestManager = function () jsOMS.Message.Request.RequestManager = function ()
{ {
this.groups = {}; this.groups = {};
this.callbacks = {}; this.callbacks = {};
}; };
jsOMS.Message.Request.RequestManager.prototype.addGroup = function(id, group) /**
* Add request group.
*
* @return {string} id Request id
* @return {string} group Group id
*
* @method
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.Message.Request.RequestManager.prototype.addGroup = function (id, group)
{ {
if(typeof this.groups[group] == 'undefined') { if (typeof this.groups[group] == 'undefined') {
this.groups[group] = {}; this.groups[group] = {};
} }
this.groups[group][id] = false; this.groups[group][id] = false;
}; };
jsOMS.Message.Request.RequestManager.prototype.hasOutstanding = function(group) /**
* Group has outstanding/pending requests?
*
* @return {string} group Group id
*
* @return {boolean}
*
* @method
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.Message.Request.RequestManager.prototype.hasOutstanding = function (group)
{ {
if(typeof this.groups[group] === 'undefined') { if (typeof this.groups[group] === 'undefined') {
return false; return false;
} }
@ -49,20 +72,42 @@
return false; return false;
}; };
jsOMS.Message.Request.RequestManager.prototype.triggerDone = function(id, group) /**
* Mark request as done.
*
* @return {string} id Request id
* @return {string} group Group id
*
* @method
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.Message.Request.RequestManager.prototype.triggerDone = function (id, group)
{ {
if(typeof this.groups[group] !== 'undefined') { if (typeof this.groups[group] !== 'undefined') {
this.groups[group][id] = true; this.groups[group][id] = true;
} }
if(!this.hasOutstanding(group)) { if (!this.hasOutstanding(group)) {
this.callbacks[group](); this.callbacks[group]();
delete this.callbacks[group]; delete this.callbacks[group];
delete this.groups[group]; delete this.groups[group];
} }
}; };
jsOMS.Message.Request.RequestManager.prototype.setDone = function(group, callback) /**
* Create callback for request pool.
*
* @return {string} group Group id
* @return {callback} callback Callback
*
* @method
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.Message.Request.RequestManager.prototype.setDone = function (group, callback)
{ {
this.callbacks[group] = callback; this.callbacks[group] = callback;
}; };

View File

@ -1,22 +1,35 @@
(function (uriFactory, undefined) { /**
* Response manager class.
*
* Used for auto handling different responses.
*
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0 * @since 1.0.0
*/
(function (uriFactory, undefined)
{
jsOMS.Autoloader.defineNamespace('jsOMS.Message.Response'); jsOMS.Autoloader.defineNamespace('jsOMS.Message.Response');
jsOMS.Message.Response.Response = function (data) { jsOMS.Message.Response.Response = function (data)
{
this.responses = data; this.responses = data;
}; };
jsOMS.Message.Response.Response.prototype.get = function(id) jsOMS.Message.Response.Response.prototype.get = function (id)
{ {
return this.responses[id]; return this.responses[id];
}; };
jsOMS.Message.Response.Response.prototype.getByIndex = function(index) jsOMS.Message.Response.Response.prototype.getByIndex = function (index)
{ {
//return this.responses[Object.keys(this.responses).sort()[index]]; //return this.responses[Object.keys(this.responses).sort()[index]];
return this.responses; return this.responses;
}; };
jsOMS.Message.Response.Response.prototype.count = function() jsOMS.Message.Response.Response.prototype.count = function ()
{ {
return 1; return 1;
}; };

View File

@ -24,21 +24,53 @@
this.ignore = {}; this.ignore = {};
}; };
/**
* Get form
*
* @param {string} id Form Id
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.UI.FormManager.prototype.get = function (id) jsOMS.UI.FormManager.prototype.get = function (id)
{ {
return this.forms[id]; return this.forms[id];
}; };
/**
* Is form ignored?
*
* @param {string} id Form Id
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.UI.FormManager.prototype.isIgnored = function (id) jsOMS.UI.FormManager.prototype.isIgnored = function (id)
{ {
return this.ignore.indexOf(id) !== -1; return this.ignore.indexOf(id) !== -1;
}; };
/**
* Unbind form
*
* @param {string} id Form Id
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.UI.FormManager.prototype.unbind = function (id) jsOMS.UI.FormManager.prototype.unbind = function (id)
{ {
}; };
/**
* Bind form
*
* @param {string} id Form Id (optional)
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.UI.FormManager.prototype.bind = function (id) jsOMS.UI.FormManager.prototype.bind = function (id)
{ {
if (typeof id !== 'undefined' && typeof this.ignore[id] === 'undefined') { if (typeof id !== 'undefined' && typeof this.ignore[id] === 'undefined') {
@ -55,6 +87,14 @@
} }
}; };
/**
* Bind form
*
* @param {string} id Form Id
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.UI.FormManager.prototype.bindForm = function (id) jsOMS.UI.FormManager.prototype.bindForm = function (id)
{ {
if (typeof id === 'undefined' || !id) { if (typeof id === 'undefined' || !id) {
@ -74,6 +114,14 @@
}); });
}; };
/**
* Unbind form
*
* @param {string} id Form Id
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.UI.FormManager.prototype.unbindForm = function (id) jsOMS.UI.FormManager.prototype.unbindForm = function (id)
{ {
// todo: do i need the findex? can't i just use id? // todo: do i need the findex? can't i just use id?
@ -89,6 +137,16 @@
return false; return false;
}; };
/**
* Submit form
*
* Calls injections first befor executing the actual form submit
*
* @param {Object} form Form object
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.UI.FormManager.prototype.submit = function (form) jsOMS.UI.FormManager.prototype.submit = function (form)
{ {
/* Handle injects */ /* Handle injects */
@ -110,6 +168,16 @@
this.app.eventManager.triggerDone('?', form.getId()); this.app.eventManager.triggerDone('?', form.getId());
}; };
/**
* Submit form data
*
* Submits the main form data
*
* @param {Object} form Form object
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.UI.FormManager.prototype.submitForm = function (form) jsOMS.UI.FormManager.prototype.submitForm = function (form)
{ {
if (!form.isValid()) { if (!form.isValid()) {
@ -160,6 +228,14 @@
request.send(); request.send();
}; };
/**
* Count the bound forms
*
* @return {number}
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.UI.FormManager.prototype.count = function () jsOMS.UI.FormManager.prototype.count = function ()
{ {
return this.forms.length; return this.forms.length;

View File

@ -13,57 +13,81 @@
jsOMS.Autoloader.defineNamespace('jsOMS.UI'); jsOMS.Autoloader.defineNamespace('jsOMS.UI');
/** /**
* @constructor * Unbind input element
*
* @param {Object} input Input element
* *
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.UI.Input.unbind = function(input) jsOMS.UI.Input.unbind = function (input)
{ {
this.app.inputManager.getKeyboardManager().unbind(input); this.app.inputManager.getKeyboardManager().unbind(input);
input.removeEventListener('change', changeBind, false); input.removeEventListener('change', changeBind, false);
}; };
jsOMS.UI.Input.bind = function(input) /**
* Bind input elment
*
* @param {Object} input Input elment
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.UI.Input.bind = function (input)
{ {
let self = this; let self = this;
input.addEventListener('change', function changeBind(event) { input.addEventListener('change', function changeBind(event)
{
/* Handle remote datalist/autocomplete input element */ /* Handle remote datalist/autocomplete input element */
let listId, list; let listId, list;
if(typeof (listId = this.getAttribute('list')) !== 'undefined' && (list = document.getElementById(listId)).getAttribute('data-list-src') !== 'undefined') { if (typeof (listId = this.getAttribute('list')) !== 'undefined' && (list = document.getElementById(listId)).getAttribute('data-list-src') !== 'undefined') {
self.addRemoteDatalistOptions(this, list); self.addRemoteDatalistOptions(this, list);
} }
/* Handle html defined functions */ /* Handle html defined functions */
let change; let change;
if(typeof (change = this.getAttribute('data-change-func')) !== 'undefined') { if (typeof (change = this.getAttribute('data-change-func')) !== 'undefined') {
change(this); change(this);
} }
/* Handle pre-defined dynamic change events */ /* Handle pre-defined dynamic change events */
let ref; let ref;
if(typeof (ref = this.getAttribute('data-ref')) !== 'undefined') { if (typeof (ref = this.getAttribute('data-ref')) !== 'undefined') {
let e = document.getElementById(ref); let e = document.getElementById(ref);
switch(e.tagName) { switch (e.tagName) {
case 'ul': case 'ul':
break; break;
case 'table': case 'table':
break; break;
}; }
;
} }
}); });
let dataButton; let dataButton;
if(typeof (dataButton = input.getAttribute('data-button')) !== 'undefined') { if (typeof (dataButton = input.getAttribute('data-button')) !== 'undefined') {
this.app.inputManager.getKeyboardManager().bind(input, 13, function() { this.app.inputManager.getKeyboardManager().bind(input, 13, function ()
document.getElementById(dataButton).click(); {
document.getElementById(dataButton).click();
}); });
} }
}; };
jsOMS.UI.Input.addRemoteDatalistOptions = function(input, datalist) /**
* Add remote datalist options
*
* This only applies for datalists that have remote options
*
* @param {Object} input Input elment
* @param {Object} datalist Datalist elment
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.UI.Input.addRemoteDatalistOptions = function (input, datalist)
{ {
this.clearDatalistOptions(datalist); this.clearDatalistOptions(datalist);
@ -73,27 +97,28 @@
request.setUri(datalist.getAttribute('data-list-src')); request.setUri(datalist.getAttribute('data-list-src'));
request.setMethod(jsOMS.Message.Request.RequestMethod.POST); request.setMethod(jsOMS.Message.Request.RequestMethod.POST);
request.setRequestHeader('Content-Type', 'application/json'); request.setRequestHeader('Content-Type', 'application/json');
request.setSuccess(function (xhr) { request.setSuccess(function (xhr)
{
try { try {
let o = JSON.parse(xhr.response), let o = JSON.parse(xhr.response),
response = new Response(o), response = new Response(o),
responseLength = response.count(), responseLength = response.count(),
tempResponse = null, tempResponse = null,
success = null; success = null;
for (let k = 0; k < responseLength; k++) { for (let k = 0; k < responseLength; k++) {
tempResponse = response.getByIndex(k); tempResponse = response.getByIndex(k);
console.log(tempResponse); console.log(tempResponse);
let option = null, let option = null,
data = tempResponse.getData(), data = tempResponse.getData(),
length = data.length; length = data.length;
for(let i = 0; i < length; i++) { for (let i = 0; i < length; i++) {
option = document.createElement('option'); option = document.createElement('option');
option.value = tempResponse.value; option.value = tempResponse.value;
option.text = tempResponse.text; option.text = tempResponse.text;
datalist.appendChild(option); datalist.appendChild(option);
} }
} }
@ -106,12 +131,19 @@
request.send(); request.send();
}; };
jsOMS.UI.Input.clearDatalistOptions = function(datalist) /**
* Remove all datalist options from datalist
*
* @param {Object} datalist Datalist elment
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.UI.Input.clearDatalistOptions = function (datalist)
{ {
let length = datalist.options.length, let length = datalist.options.length;
i = 0;
for(i = 0; i < length; i++) { for (let i = 0; i < length; i++) {
datalist.remove(0); datalist.remove(0);
} }
}; };

View File

@ -1,18 +1,50 @@
(function (jsOMS, undefined) { /**
* UI manager class.
*
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0 * @since 1.0.0
*/
(function (jsOMS, undefined)
{
jsOMS.Autoloader.defineNamespace('jsOMS.UI.Input'); jsOMS.Autoloader.defineNamespace('jsOMS.UI.Input');
jsOMS.UI.Input.InputManager = function () /**
{ * @constructor
this.keyBoardManager = new jsOMS.UI.Input.Keyboard.KeyboardManager(); *
this.mouseManager = new jsOMS.UI.Input.Mouse.MouseManager(); * @since 1.0.0
}; * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.UI.Input.InputManager = function ()
{
this.keyBoardManager = new jsOMS.UI.Input.Keyboard.KeyboardManager();
this.mouseManager = new jsOMS.UI.Input.Mouse.MouseManager();
};
jsOMS.UI.Input.InputManager.prototype.getKeyboardManager = function() /**
{ * Get keyboard manager.
return this.keyBoardManager; *
}; * @return {Object}
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.UI.Input.InputManager.prototype.getKeyboardManager = function ()
{
return this.keyBoardManager;
};
jsOMS.UI.Input.InputManager.prototype.getMouseManager = function() /**
* Get mouse manager.
*
* @return {Object}
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.UI.Input.InputManager.prototype.getMouseManager = function ()
{ {
return this.mouseManager; return this.mouseManager;
}; };

View File

@ -1,13 +1,38 @@
/**
* Keyboard manager class.
*
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0 * @since 1.0.0
*/
(function (jsOMS, undefined) (function (jsOMS, undefined)
{ {
jsOMS.Autoloader.defineNamespace('jsOMS.UI.Input.Keyboard'); jsOMS.Autoloader.defineNamespace('jsOMS.UI.Input.Keyboard');
/**
* @constructor
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.UI.Input.Keyboard.KeyboardManager = function () jsOMS.UI.Input.Keyboard.KeyboardManager = function ()
{ {
this.elements = {}; this.elements = {};
this.down = []; this.down = [];
}; };
/**
* Add input listener.
*
* @param {string} element Container id
* @param {Array} keys Keyboard keys
* @param {callback} callback Callback
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.UI.Input.Keyboard.KeyboardManager.prototype.add = function (element, keys, callback) jsOMS.UI.Input.Keyboard.KeyboardManager.prototype.add = function (element, keys, callback)
{ {
if (typeof this.elements[element] === 'undefined') { if (typeof this.elements[element] === 'undefined') {
@ -19,6 +44,14 @@
this.elements[element].push({keys: keys, callback: callback}); this.elements[element].push({keys: keys, callback: callback});
}; };
/**
* Bind container for keyboard input.
*
* @param {string} element Container id
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.UI.Input.Keyboard.KeyboardManager.prototype.bind = function (element) jsOMS.UI.Input.Keyboard.KeyboardManager.prototype.bind = function (element)
{ {
let self = this; let self = this;
@ -31,14 +64,22 @@
document.addEventListener('keyup', function keyBind(event) document.addEventListener('keyup', function keyBind(event)
{ {
if(self.down.length > 0) { if (self.down.length > 0) {
self.run(element, event); self.run(element);
self.down = []; self.down = [];
} }
}); });
}; };
jsOMS.UI.Input.Keyboard.KeyboardManager.prototype.run = function (element, event) /**
* Execute callback based on key presses.
*
* @param {string} element Container id
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.UI.Input.Keyboard.KeyboardManager.prototype.run = function (element)
{ {
if (typeof this.elements[element] === 'undefined') { if (typeof this.elements[element] === 'undefined') {
throw 'Unexpected elmenet!'; throw 'Unexpected elmenet!';
@ -60,7 +101,7 @@
} }
} }
if(match) { if (match) {
jsOMS.preventAll(event); jsOMS.preventAll(event);
actions[i].callback(); actions[i].callback();

View File

@ -1,5 +1,5 @@
/** /**
* Click type. * Event type.
* *
* @author OMS Development Team <dev@oms.com> * @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>

View File

@ -1,13 +1,40 @@
/**
* Mouse manager class.
*
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0 * @since 1.0.0
*/
(function (jsOMS, undefined) (function (jsOMS, undefined)
{ {
jsOMS.Autoloader.defineNamespace('jsOMS.UI.Input.Mouse'); jsOMS.Autoloader.defineNamespace('jsOMS.UI.Input.Mouse');
/**
* @constructor
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.UI.Input.Mouse.MouseManager = function () jsOMS.UI.Input.Mouse.MouseManager = function ()
{ {
this.elements = {}; this.elements = {};
this.click = {time: 0}; this.click = {time: 0};
}; };
/**
* Add input listener.
*
* @param {string} element Container id
* @param {int} type Action type
* @param {int} button Button
* @param {callback} callback Callback
* @param {bool} exact ??? todo: can't remember why this was important oO!!!
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.UI.Input.Mouse.MouseManager.prototype.add = function (element, type, button, callback, exact) jsOMS.UI.Input.Mouse.MouseManager.prototype.add = function (element, type, button, callback, exact)
{ {
if (typeof this.elements[element] === 'undefined') { if (typeof this.elements[element] === 'undefined') {
@ -18,12 +45,21 @@
this.elements[element].push({callback: callback, type: type, button: button, exact: exact}); this.elements[element].push({callback: callback, type: type, button: button, exact: exact});
}; };
/**
* Add input listener.
*
* @param {string} element Element id
* @param {int} type Action type
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.UI.Input.Mouse.MouseManager.prototype.bind = function (element, type) jsOMS.UI.Input.Mouse.MouseManager.prototype.bind = function (element, type)
{ {
let self = this, let self = this,
e = document.getElementById(element); e = document.getElementById(element);
if(e === null) { if (e === null) {
return; return;
} }
@ -56,6 +92,15 @@
} }
}; };
/**
* Run mouse input callback.
*
* @param {string} element Element id
* @param {Object} event Click event
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.UI.Input.Mouse.MouseManager.prototype.run = function (element, event) jsOMS.UI.Input.Mouse.MouseManager.prototype.run = function (element, event)
{ {
if (typeof this.elements[element] === 'undefined') { if (typeof this.elements[element] === 'undefined') {

View File

@ -1,83 +0,0 @@
/**
* Swipe manager class.
*
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0 * @since 1.0.0
*/
(function (jsOMS, undefined)
{
jsOMS.Autoloader.defineNamespace('jsOMS.UI.Input.Touch');
/**
* @constructor
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.UI.Input.Touch.SwipeManager = function (app)
{
this.app = app;
this.activeSwipe = {};
this.resetSwipe();
};
jsOMS.UI.Input.Touch.SwipeManager.prototype.resetSwipe = function ()
{
this.activeSwipe = {'startX': null, 'startY': null, 'time': null};
};
jsOMS.UI.Input.Touch.SwipeManager.prototype.add = function ()
{
let self = this;
e.addEventListener('touchstart', function (event)
{
let touch = this.changedTouches[0];
self.activeSwipe.startX = touch.pageX;
self.activeSwipe.startY = touch.pageY;
self.activeSwipe.time = new Date().getTime();
jsOMS.preventAll(event);
});
e.addEventListener('touchmove', function (event)
{
jsOMS.preventAll(event);
});
e.addEventListener('touchend', function (event)
{
let touch = this.changedTouches[0],
distX = touch.pageX - self.activeSwipe.startX,
distY = touch.pageY - self.activeSwipe.startY,
elapsedTime = new Date().getTime() - self.activeSwipe.time;
if (elapsedTime < 500) {
let e = new Event('keyup');
if (distY > 100) {
e.keyCode = 38;
document.dispatchEvent(e);
} else if (distX > 100) {
e.keyCode = 39;
document.dispatchEvent(e);
} else if (distY < -100) {
e.keyCode = 40;
document.dispatchEvent(e);
} else if (distX < -100) {
e.keyCode = 37;
document.dispatchEvent(e);
}
}
self.resetSwipe();
jsOMS.preventAll(event);
});
};
}(window.jsOMS = window.jsOMS || {}));

View File

@ -1,4 +1,3 @@
/** /**
* Touch manager class. * Touch manager class.
* *
@ -15,17 +14,89 @@
/** /**
* @constructor * @constructor
* *
* @param {Object} app Application
*
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.UI.Input.Touch.TouchManager = function (app) jsOMS.UI.Input.Touch.TouchManager = function (app)
{ {
this.app = app; this.app = app;
this.swipe = new jsOMS.UI.Input.Touch.SwipeManager(app); this.activeSwipe = {};
this.resetSwipe();
}; };
jsOMS.UI.Input.Touch.TouchManager.prototype.getSwipeManager = function () /**
* Reset swipe data.
*
* This is called in between swipes in order to reset previous swipe data.
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.UI.Input.Touch.TouchManager.prototype.resetSwipe = function ()
{ {
return this.swipe; this.activeSwipe = {'startX': null, 'startY': null, 'time': null};
};
/**
* Adding swipe functionality.
*
* Forwarding swipe to arrow keyes.
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.UI.Input.Touch.TouchManager.prototype.add = function ()
{
let self = this;
e.addEventListener('touchstart', function (event)
{
let touch = this.changedTouches[0];
self.activeSwipe.startX = touch.pageX;
self.activeSwipe.startY = touch.pageY;
self.activeSwipe.time = new Date().getTime();
jsOMS.preventAll(event);
});
e.addEventListener('touchmove', function (event)
{
jsOMS.preventAll(event);
});
e.addEventListener('touchend', function (event)
{
let touch = this.changedTouches[0],
distX = touch.pageX - self.activeSwipe.startX,
distY = touch.pageY - self.activeSwipe.startY,
elapsedTime = new Date().getTime() - self.activeSwipe.time;
self.resetSwipe();
// todo: only prevent all if success
jsOMS.preventAll(event);
if (elapsedTime > 300 && distY < 3 && distX < 3) {
// todo: handle long press here
} else if (elapsedTime < 500) {
let e = new Event('keyup');
if (distY > 100) {
e.keyCode = 38;
document.dispatchEvent(e);
} else if (distX > 100) {
e.keyCode = 39;
document.dispatchEvent(e);
} else if (distY < -100) {
e.keyCode = 40;
document.dispatchEvent(e);
} else if (distX < -100) {
e.keyCode = 37;
document.dispatchEvent(e);
}
}
});
}; };
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -14,6 +14,8 @@
/** /**
* @constructor * @constructor
* *
* @param {Object} app Application object
*
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */

View File

@ -1,23 +1,49 @@
(function (uriFactory, undefined) { /**
* Uri factory.
*
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0 * @since 1.0.0
*/
(function (uriFactory, undefined)
{
jsOMS.Autoloader.defineNamespace('jsOMS.Uri.UriFactory'); jsOMS.Autoloader.defineNamespace('jsOMS.Uri.UriFactory');
/**
* Uri values
*
* @var {Object}
* @since 1.0.0
*/
jsOMS.Uri.UriFactory.uri = {}; jsOMS.Uri.UriFactory.uri = {};
/**
* Parse uri
*
* @return {Object}
*
* @function
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.Uri.UriFactory.parseUrl = function (str) jsOMS.Uri.UriFactory.parseUrl = function (str)
{ {
let query, key = ['source', 'scheme', 'authority', 'userInfo', 'user', 'pass', 'host', 'port', let query, key = ['source', 'scheme', 'authority', 'userInfo', 'user', 'pass', 'host', 'port',
'relative', 'path', 'directory', 'file', 'query', 'fragment' 'relative', 'path', 'directory', 'file', 'query', 'fragment'
], ],
mode = 'php', mode = 'php',
parser = { parser = {
php: /^(?:([^:\/?#]+):)?(?:\/\/()(?:(?:()(?:([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?()(?:(()(?:(?:[^?#\/]*\/)*)()(?:[^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, php: /^(?:([^:\/?#]+):)?(?:\/\/()(?:(?:()(?:([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?()(?:(()(?:(?:[^?#\/]*\/)*)()(?:[^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/\/?)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ // Added one optional slash to post-scheme to catch file:/// (should restrict this) loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/\/?)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ // Added one optional slash to post-scheme to catch file:/// (should restrict this)
}; };
let m = parser[mode].exec(str), let m = parser[mode].exec(str),
uri = {}, uri = {},
i = 14; i = 14;
while (i--) { while (i--) {
if (m[i]) { if (m[i]) {
@ -47,17 +73,31 @@
{ {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
let regex = new RegExp("[\\?&]*" + name + "=([^&#]*)"), let regex = new RegExp("[\\?&]*" + name + "=([^&#]*)"),
results = regex.exec(query); results = regex.exec(query);
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' ')); return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
}; };
jsOMS.Uri.UriFactory.setQuery = function(key, value, overwrite) /**
* Set uri query
*
* @param {string} key Query key
* @param {string} value Query value
* @param {boolean} overwrite Overwrite if already exists?
*
* @return {boolean}
*
* @function
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.Uri.UriFactory.setQuery = function (key, value, overwrite)
{ {
overwrite = typeof overwrite !== 'undefined' ? overwrite : true; overwrite = typeof overwrite !== 'undefined' ? overwrite : true;
if(overwrite || !jsOMS.Uri.UriFactory.uri.hasProperty(key)) { if (overwrite || !jsOMS.Uri.UriFactory.uri.hasProperty(key)) {
jsOMS.Uri.UriFactory.uri[key] = value; jsOMS.Uri.UriFactory.uri[key] = value;
return true; return true;
@ -66,22 +106,34 @@
return false; return false;
}; };
jsOMS.Uri.UriFactory.build = function(uri, toMatch) /**
* Build uri
*
* @param {string} uri Raw uri
* @param {Object} toMatch Key/value pair to replace in raw
*
* @function
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.Uri.UriFactory.build = function (uri, toMatch)
{ {
let current = jsOMS.Uri.UriFactory.parseUrl(window.location.href); let current = jsOMS.Uri.UriFactory.parseUrl(window.location.href);
return uri.replace(new RegExp('\{[\/#\?@\.\$][a-zA-Z0-9]*\}', 'g'), function(match) { return uri.replace(new RegExp('\{[\/#\?@\.\$][a-zA-Z0-9]*\}', 'g'), function (match)
{
match = match.substr(1, match.length - 2); match = match.substr(1, match.length - 2);
if(typeof toMatch !== 'undefined' && toMatch.hasProperty(match)) { if (typeof toMatch !== 'undefined' && toMatch.hasProperty(match)) {
return toMatch[match]; return toMatch[match];
} else if(jsOMS.Uri.UriFactory.uri[match] !== 'undefined') { } else if (jsOMS.Uri.UriFactory.uri[match] !== 'undefined') {
return jsOMS.Uri.UriFactory.uri[match]; return jsOMS.Uri.UriFactory.uri[match];
} else if (match.indexOf('#') === 0) { } else if (match.indexOf('#') === 0) {
return document.getElementById(match.substring(1, match.length)).value; return document.getElementById(match.substring(1, match.length)).value;
} else if(match.indexOf('?') === 0) { } else if (match.indexOf('?') === 0) {
return jsOMS.Uri.UriFactory.getUriQueryParameter(current.query, match.substring(1, match.length)); return jsOMS.Uri.UriFactory.getUriQueryParameter(current.query, match.substring(1, match.length));
} else if(match.indexOf('/') === 0) { } else if (match.indexOf('/') === 0) {
// todo: second match should return second path // todo: second match should return second path
return 'ERROR PATH'; return 'ERROR PATH';
} else { } else {

View File

@ -1,8 +1,25 @@
/**
* Form view.
*
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0 * @since 1.0.0
*/
(function (jsOMS, undefined) (function (jsOMS, undefined)
{ {
"use strict"; "use strict";
jsOMS.Autoloader.defineNamespace('jsOMS.Views'); jsOMS.Autoloader.defineNamespace('jsOMS.Views');
/**
* @constructor
*
* @param {string} id Form id
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.Views.FormView = function (id) jsOMS.Views.FormView = function (id)
{ {
this.id = id; this.id = id;
@ -12,6 +29,14 @@
this.success = null; this.success = null;
}; };
/**
* Initialize members
*
* Pulled out since this is used in a cleanup process
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.Views.FormView.prototype.initializeMembers = function () jsOMS.Views.FormView.prototype.initializeMembers = function ()
{ {
this.submitInjects = []; this.submitInjects = [];
@ -19,48 +44,111 @@
this.action = ''; this.action = '';
}; };
/**
* Get method
*
* @return {string}
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.Views.FormView.prototype.getMethod = function () jsOMS.Views.FormView.prototype.getMethod = function ()
{ {
return this.method; return this.method;
}; };
/**
* Get action
*
* @return {string}
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.Views.FormView.prototype.getAction = function () jsOMS.Views.FormView.prototype.getAction = function ()
{ {
return this.action; return this.action;
}; };
/**
* Get submit elements
*
* @return {Object}
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.Views.FormView.prototype.getSubmit = function () jsOMS.Views.FormView.prototype.getSubmit = function ()
{ {
return document.getElementById(this.id).querySelectorAll('input[type=submit]')[0]; return document.getElementById(this.id).querySelectorAll('input[type=submit]')[0];
}; };
/**
* Get success callback
*
* @return {callback}
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.Views.FormView.prototype.getSuccess = function () jsOMS.Views.FormView.prototype.getSuccess = function ()
{ {
return this.success; return this.success;
}; };
/**
* Set success callback
*
* @param {callback} callback Callback
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.Views.FormView.prototype.setSuccess = function (callback) jsOMS.Views.FormView.prototype.setSuccess = function (callback)
{ {
this.success = callback; this.success = callback;
}; };
jsOMS.Views.FormView.prototype.injectSubmit = function (id, callback) /**
* Inject submit with post callback
*
* @param {callback} callback Callback
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.Views.FormView.prototype.injectSubmit = function (callback)
{ {
this.submitInjects.push(callback); this.submitInjects.push(callback);
}; };
/**
* Get form elements
*
* @return {Array}
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.Views.FormView.prototype.getFormElements = function () jsOMS.Views.FormView.prototype.getFormElements = function ()
{ {
let form = document.getElementById(this.id), let form = document.getElementById(this.id),
selects = form.getElementsByTagName('select'), selects = form.getElementsByTagName('select'),
textareas = form.getElementsByTagName('textarea'), textareas = form.getElementsByTagName('textarea'),
inputs = form.getElementsByTagName('input'), inputs = form.getElementsByTagName('input'),
external = document.querySelectorAll('[form=' + this.id + ']'), external = document.querySelectorAll('[form=' + this.id + ']');
elements = Array.prototype.slice.call(inputs).concat(Array.prototype.slice.call(selects), Array.prototype.slice.call(textareas), Array.prototype.slice.call(external));
return elements; return Array.prototype.slice.call(inputs).concat(Array.prototype.slice.call(selects), Array.prototype.slice.call(textareas), Array.prototype.slice.call(external));
}; };
/**
* Get form data
*
* @return {Object}
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.Views.FormView.prototype.getData = function () jsOMS.Views.FormView.prototype.getData = function ()
{ {
let data = {}, let data = {},
@ -75,11 +163,27 @@
return data; return data;
}; };
/**
* Get form id
*
* @return {string}
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.Views.FormView.prototype.getId = function () jsOMS.Views.FormView.prototype.getId = function ()
{ {
return this.id; return this.id;
}; };
/**
* Validate form
*
* @return {boolean}
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.Views.FormView.prototype.isValid = function () jsOMS.Views.FormView.prototype.isValid = function ()
{ {
let elements = this.getFormElements(), let elements = this.getFormElements(),
@ -98,11 +202,27 @@
return true; return true;
}; };
/**
* Get form element
*
* @return {Object}
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.Views.FormView.prototype.getElement = function () jsOMS.Views.FormView.prototype.getElement = function ()
{ {
return document.getElementById(this.getId()); return document.getElementById(this.getId());
}; };
/**
* Get form element id
*
* @return {string}
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.Views.FormView.getElementId = function (e) jsOMS.Views.FormView.getElementId = function (e)
{ {
let id = e.getAttribute('name'); let id = e.getAttribute('name');
@ -122,11 +242,25 @@
return id; return id;
}; };
/**
* Get submit injects
*
* @return {Object}
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.Views.FormView.prototype.getSubmitInjects = function () jsOMS.Views.FormView.prototype.getSubmitInjects = function ()
{ {
return this.submitInjects; return this.submitInjects;
}; };
/**
* Bind form
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.Views.FormView.prototype.bind = function () jsOMS.Views.FormView.prototype.bind = function ()
{ {
this.clean(); this.clean();
@ -153,17 +287,21 @@
this.bindButton(elements[i]); this.bindButton(elements[i]);
break; break;
} }
;
} }
}; };
/**
* Unbind form
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.Views.FormView.prototype.unbind = function () jsOMS.Views.FormView.prototype.unbind = function ()
{ {
let elements = this.getFormElements(), let elements = this.getFormElements(),
length = elements.length, length = elements.length;
i = 0;
for (i = 0; i < length; i++) { for (let i = 0; i < length; i++) {
switch (elements[i].tagName) { switch (elements[i].tagName) {
case 'input': case 'input':
jsOMS.UI.Input.unbind(elements[i]) jsOMS.UI.Input.unbind(elements[i])
@ -178,10 +316,15 @@
this.bindButton(elements[i]); this.bindButton(elements[i]);
break; break;
} }
;
} }
}; };
/**
* Clean form
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.Views.FormView.prototype.clean = function () jsOMS.Views.FormView.prototype.clean = function ()
{ {
this.unbind(); this.unbind();

View File

@ -1,19 +1,37 @@
(function (jsOMS, undefined) { /**
jsOMS.Autoloader = {}; * Autoloader.
jsOMS.Autoloader.loaded = []; *
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0 * @since 1.0.0
*/
(function (jsOMS, undefined)
{
jsOMS.Autoloader = {};
jsOMS.Autoloader.loaded = [];
jsOMS.Autoloader.namespaced = []; jsOMS.Autoloader.namespaced = [];
jsOMS.Autoloader.defineNamespace = function(namespace) /**
* Define namespace
*
* @param {string} namespace Namespace
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.Autoloader.defineNamespace = function (namespace)
{ {
if(jsOMS.Autoloader.namespaced.indexOf(namespace) === -1) { if (jsOMS.Autoloader.namespaced.indexOf(namespace) === -1) {
let paths = namespace.split('.'); let paths = namespace.split('.');
paths.splice(0, 1); paths.splice(0, 1);
let length = paths.length, let length = paths.length,
current = jsOMS; current = jsOMS;
for(let i = 0; i < length; i++) { for (let i = 0; i < length; i++) {
if(typeof current[paths[i]] === 'undefined') { if (typeof current[paths[i]] === 'undefined') {
current[paths[i]] = {}; current[paths[i]] = {};
} }
@ -24,33 +42,56 @@
} }
}; };
jsOMS.Autoloader.initPreloaded = function() /**
* Collect all loaded javascript files
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.Autoloader.initPreloaded = function ()
{ {
let scripts = document.getElementsByTagName('script'), let scripts = document.getElementsByTagName('script'),
length = scripts.length; length = scripts.length;
for(let i = 0; i < length; i++) { for (let i = 0; i < length; i++) {
scripts[i].src.replace(URL + '/', ''); scripts[i].src.replace(URL + '/', '');
if(jsOMS.Autoloader.loaded.indexOf(scripts[i].src) === -1) { if (jsOMS.Autoloader.loaded.indexOf(scripts[i].src) === -1) {
jsOMS.Autoloader.loaded.push(scripts[i].src); jsOMS.Autoloader.loaded.push(scripts[i].src);
} }
} }
}; };
jsOMS.Autoloader.setPreloaded = function(file) /**
* Add loaded script
*
* @param {string} file Script URI
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.Autoloader.addPreloaded = function (file)
{ {
if(jsOMS.Autoloader.loaded.indexOf(file) === -1) { if (jsOMS.Autoloader.loaded.indexOf(file) === -1) {
jsOMS.Autoloader.loaded.push(file); jsOMS.Autoloader.loaded.push(file);
} }
}; };
jsOMS.Autoloader.include = function(file, callback) /**
* Include script
*
* @param {string} file Script URI
* @param {callback} callback Callback after script loading
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.Autoloader.include = function (file, callback)
{ {
let length = file.length; let length = file.length;
for(let i = 0; i < length; i++) { for (let i = 0; i < length; i++) {
if(jsOMS.Autoloader.loaded.indexOf(file) === -1) { if (jsOMS.Autoloader.loaded.indexOf(file) === -1) {
// todo: implement asset loading and pass callback // todo: implement asset loading and pass callback
jsOMS.Autoloader.loaded.push(file); jsOMS.Autoloader.loaded.push(file);