make oLib a module

This commit is contained in:
Dennis Eichhorn 2023-10-05 07:44:22 +00:00
parent 751f655522
commit 72f2c2e1d1
31 changed files with 132 additions and 679 deletions

View File

@ -1,3 +1,5 @@
import { jsOMS } from '../Utils/oLib.js';
/**
* Asset manager.
*

View File

@ -40,7 +40,7 @@ Autoloader.defineNamespace = function (namespace)
paths.splice(0, 1);
const length = paths.length;
let current = jsOMS;
let current = omsApp;
for (let i = 0; i < length; ++i) {
if (typeof current[paths[i]] === 'undefined') {

View File

@ -1,3 +1,4 @@
import { jsOMS } from '../../Utils/oLib.js';
/**
* @typedef {import('../Request/Request.js').Request} Request
*/

View File

@ -1,3 +1,4 @@
import { jsOMS } from '../../../Utils/oLib.js';
/**
* Hide an element.
*

View File

@ -1,3 +1,4 @@
import { jsOMS } from '../../../Utils/oLib.js';
import { UriFactory } from '../../../Uri/UriFactory.js';
/**

View File

@ -1,3 +1,4 @@
import { jsOMS } from '../../../Utils/oLib.js';
/**
* Show dom element.
*

View File

@ -1,3 +1,4 @@
import { jsOMS } from '../../../Utils/oLib.js';
/**
* Prevent UI action.
*

View File

@ -1,3 +1,4 @@
import { jsOMS } from '../../../Utils/oLib.js';
/**
* Collect data.
*

View File

@ -1,3 +1,4 @@
import { jsOMS } from '../../Utils/oLib.js';
/**
* Perform DOM action.
*

View File

@ -20,6 +20,6 @@ export class ModuleFactory
*/
static getInstance (module, app)
{
return new jsOMS.Modules[module](app);
return new omsApp.Modules[module](app);
};
};

View File

@ -1,3 +1,4 @@
import { jsOMS } from '../Utils/oLib.js';
import { Logger } from '../Log/Logger.js';
/**

View File

@ -1,3 +1,4 @@
import { jsOMS } from '../../Utils/oLib.js';
import { Request } from '../../Message/Request/Request.js';
/**

View File

@ -5,7 +5,7 @@
// isn't this very similar to the advanced input? just a little different?
// maybe not...
import { jsOMS } from '../../Utils/oLib.js';
import { Request } from '../../Message/Request/Request.js';
/**
* Advanced input class.

View File

@ -1,3 +1,4 @@
import { jsOMS } from '../../Utils/oLib.js';
import { Logger } from '../../Log/Logger.js';
import { NotificationLevel } from '../../Message/Notification/NotificationLevel.js';
import { NotificationMessage } from '../../Message/Notification/NotificationMessage.js';
@ -309,8 +310,8 @@ export class Form
const addTpl = formElement.getAttribute('data-add-tpl').split(',');
const addTplLength = addTpl.length;
/** @var {string[]} values Values to add (values can be different from the displayed text) */
let values = [];
/** @var {string[]} vals Values to add (values can be different from the displayed text) */
let vals = [];
/** @var {string[]} texts Text to add (values can be different from the displayed text) */
let texts = [];
@ -338,7 +339,7 @@ export class Form
// is this a @todo ? probably yes.
// maybe first use local data and then if remote data available replace local data?
values = values.concat(
vals = vals.concat(
dataOriginElement.hasAttribute('data-tpl-value')
? dataOriginElement
: Array.prototype.slice.call(dataOriginElement.querySelectorAll('[data-tpl-value]'))
@ -363,7 +364,7 @@ export class Form
}
// insert values into form (populate values)
Form.setDataInElement('value', newElements, values, remoteUrls);
Form.setDataInElement('value', newElements, vals, remoteUrls);
// insert text data into form (populate text)
Form.setDataInElement('text', newElements, texts, remoteUrls);
@ -380,13 +381,13 @@ export class Form
// fill elements with remote data after submit (if the template expects data from a remote source)
// this is usually the case for element ids, which can only be generated by the backend
Form.setDataFromRemoteUrls(remoteUrls);
// reset the form after adding an element
self.forms[id].resetValues();
});
// submit to api
self.submit(self.forms[id], self.forms[id].getAdd()[elementIndex]);
// reset the form after adding an element
self.forms[id].resetValues();
}
formActionSave (self, event, id, elementIndex)
@ -434,8 +435,8 @@ export class Form
/** @var {Element} elementContainer Element container that holds the data that should get updated */
const elementContainer = event.target.closest(formElement.getAttribute('data-ui-element'));
/** @var {string[]} values New values */
let values = [];
/** @var {string[]} vals New values */
let vals = [];
/** @var {string[]} texts New texts */
let texts = [];
@ -472,7 +473,7 @@ export class Form
// is this a @todo ? probably yes.
// maybe first use local data and then if remote data available replace local data?
values = values.concat(
vals = vals.concat(
dataOriginElement.hasAttribute('data-tpl-value')
? dataOriginElement
: Array.prototype.slice.call(dataOriginElement.querySelectorAll('[data-tpl-value]'))
@ -497,7 +498,7 @@ export class Form
}
// insert values into form (populate values)
Form.setDataInElement('value', newElements, values, remoteUrls);
Form.setDataInElement('value', newElements, vals, remoteUrls);
// insert text data into form (populate text)
Form.setDataInElement('text', newElements, texts, remoteUrls);
@ -541,7 +542,7 @@ export class Form
// is this a @todo ? probably yes.
// maybe first use local data and then if remote data available replace local data?
values = values.concat(
vals = vals.concat(
dataOriginElement.hasAttribute('data-tpl-value')
? dataOriginElement
: Array.prototype.slice.call(dataOriginElement.querySelectorAll('[data-tpl-value]'))
@ -567,7 +568,7 @@ export class Form
}
// update values in form (overwrite values)
Form.setDataInElement('value', [element], values, remoteUrls);
Form.setDataInElement('value', [element], vals, remoteUrls);
// update text data in form (overwrite text)
Form.setDataInElement('text', [element], texts, remoteUrls);
@ -610,8 +611,8 @@ export class Form
*/
const updateElements = [];
/** @var {string[]} values New values */
let values = [];
/** @var {string[]} vals New values */
let vals = [];
/** @var {string[]} texts New texts */
let texts = [];
@ -636,7 +637,7 @@ export class Form
// is this a @todo ? probably yes.
// maybe first use local data and then if remote data available replace local data?
values = values.concat(
vals = vals.concat(
dataOriginElement.hasAttribute('data-tpl-value')
? dataOriginElement
: Array.prototype.slice.call(dataOriginElement.querySelectorAll('[data-tpl-value]'))
@ -651,6 +652,19 @@ export class Form
/** @var {object} remoteUrls Texts and values which come from remote sources */
const remoteUrls = {};
for (let i = 0; i < updateElementLength; ++i) {
jsOMS.removeClass(updateElements[i], 'animated');
jsOMS.removeClass(updateElements[i], 'greenCricleFade');
requestAnimationFrame((time) => {
requestAnimationFrame((time) => {
jsOMS.addClass(updateElements[i], 'animated');
jsOMS.addClass(updateElements[i], 'medium-duration');
jsOMS.addClass(updateElements[i], 'greenCricleFade');
});
});
}
self.forms[externalFormId].setSuccess(function (response, xhr) {
if (xhr.status !== 200) {
// reset form values to default values after performing the update
@ -660,7 +674,7 @@ export class Form
}
// update values in form (overwrite values)
Form.setDataInElement('value', updateElements, values, remoteUrls);
Form.setDataInElement('value', updateElements, vals, remoteUrls);
// update text data in form (overwrite text)
Form.setDataInElement('text', updateElements, texts, remoteUrls);
@ -668,6 +682,20 @@ export class Form
// overwrite old values from remote response
Form.setDataFromRemoteUrls(remoteUrls);
// Color highlight
for (let i = 0; i < updateElementLength; ++i) {
jsOMS.removeClass(updateElements[i], 'animated');
jsOMS.removeClass(updateElements[i], 'greenCircleFade');
jsOMS.removeClass(updateElements[i], 'medium-duration');
requestAnimationFrame((_) => {
requestAnimationFrame((_) => {
// Important: all classes need to be done in one go otherwise it doesn't work (timing issue?)
jsOMS.addClass(updateElements[i], 'animated medium-duration greenCircleFade');
});
});
}
// reset form values to default values after performing the update
self.forms[externalFormId].resetValues();
});
@ -897,6 +925,22 @@ export class Form
// insert values into form (populate values)
Form.insertDataIntoForm(self, 'value', externalFormId, values, remoteUrls);
// This prevents overwriting results from setting data by value in the next step
length = texts.length;
const length2 = values.length;
for (let i = 0; i < length; ++i) {
const tagName = texts[i].tagName.toLowerCase();
if (tagName === 'select') {
for (let j = 0; j < length2; ++j) {
if (values[j].getAttribute('name') === texts[i].getAttribute('name')) {
texts[i] = null;
break;
}
}
}
}
// insert text data into form (populate text)
Form.insertDataIntoForm(self, 'text', externalFormId, texts, remoteUrls);
@ -1146,7 +1190,7 @@ export class Form
const response = new Response(o);
let successInject = null;
const statusCode = xhr.getResponseHeader('status');
const statusCode = parseInt(xhr.getResponseHeader('status'));
if (statusCode === 200 || statusCode === null) {
if ((successInject = form.getSuccess()) !== null) {
@ -1326,10 +1370,7 @@ export class Form
} else {
if (type === 'value') {
GeneralUI.setValueOfElement(matches[c], GeneralUI.getValueFromDataSource(data[i]));
} else if (type === 'text'
&& (data[i].getAttribute('data-tpl-text') !== data[i].getAttribute('data-tpl-value')
|| data[i].getAttribute('data-value') !== null)
) {
} else if (type === 'text') {
GeneralUI.setTextOfElement(matches[c], GeneralUI.getTextFromDataSource(data[i]));
}
}
@ -1342,6 +1383,10 @@ export class Form
{
const length = data.length;
for (let i = 0; i < length; ++i) {
if (data[i] === null) {
continue;
}
const matches = self.forms[formId].getFormElement().querySelectorAll('[data-tpl-' + type + '="' + data[i].getAttribute('data-tpl-' + type) + '"');
const path = data[i].hasAttribute('data-tpl-' + type + '-path')
? data[i].getAttribute('data-tpl-' + type + '-path')

View File

@ -1,3 +1,4 @@
import { jsOMS } from '../../Utils/oLib.js';
import { HttpUri } from '../../Uri/HttpUri.js';
import { UriFactory } from '../../Uri/UriFactory.js';

View File

@ -1,3 +1,4 @@
import { jsOMS } from '../../Utils/oLib.js';
import { TableView } from '../../Views/TableView.js';
import { Request } from '../../Message/Request/Request.js';
import { ResponseType } from '../../Message/Response/ResponseType.js';

View File

@ -1,3 +1,4 @@
import { jsOMS } from '../Utils/oLib.js';
/**
* Drag and drop class.
*

View File

@ -1,4 +1,5 @@
import { jsOMS } from '../Utils/oLib.js';
import { UriFactory } from '../Uri/UriFactory.js';
import { AdvancedInput } from './Component/AdvancedInput.js';
// import { NotificationLevel } from '../Message/Notification/NotificationLevel.js';
@ -353,6 +354,15 @@ export class GeneralUI
if (src.value === '') {
src.value = jsOMS.htmlspecialchars_decode(value);
}
} else if (tagName === 'select') {
const optionLength = src.options.length;
for (let i = 0; i < optionLength; ++i) {
if (src.options[i].text === value) {
src.options[i].selected = true;
break;
}
}
} else {
src.innerHTML = value;
}

View File

@ -1,3 +1,4 @@
import { jsOMS } from '../../../Utils/oLib.js';
/**
* Keyboard manager class.
*

View File

@ -1,3 +1,4 @@
import { jsOMS } from '../../../Utils/oLib.js';
import { EventType } from '../../../../jsOMS/UI/Input/Mouse/EventType.js';
/**

View File

@ -1,3 +1,4 @@
import { jsOMS } from '../../../Utils/oLib.js';
import { Logger } from '../../../Log/Logger.js';
/**

View File

@ -1,3 +1,4 @@
import { jsOMS } from '../Utils/oLib.js';
/**
* Manual order class.
*

View File

@ -1,3 +1,4 @@
import { jsOMS } from '../Utils/oLib.js';
import { Request } from '../Message/Request/Request.js';
import { RequestMethod } from '../Message/Request/RequestMethod.js';
import { RequestType } from '../Message/Request/RequestType.js';

View File

@ -1,3 +1,4 @@
import { jsOMS } from '../Utils/oLib.js';
/**
* Http Uri.
*

View File

@ -1,3 +1,4 @@
import { jsOMS } from '../Utils/oLib.js';
import { HttpUri } from './HttpUri.js';
import { FormView } from './../Views/FormView.js';

View File

@ -1,46 +0,0 @@
/**
* Standard library
*
* This library provides useful functionalities for the DOM and other manipulations.
*
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @since 1.0.0
*/
(function (jsOMS)
{
'use strict';
/**
* Get value from array/object
*
* @param {string} path Array path
* @param {Object} data Object
* @param {string} [delim] Path delimiter
*
* @return {any}
*
* @since 1.0.0
*/
jsOMS.getArray = function (path, data, delim = '/')
{
/** @type {Object} pathParts */
const pathParts = jsOMS.ltrim(path, delim).split(delim);
let current = data;
for (const key in pathParts) {
if (!Object.prototype.hasOwnProperty.call(pathParts, key)) {
continue;
}
if (typeof current === 'undefined' || !Object.prototype.hasOwnProperty.call(current, pathParts[key])) {
return null;
}
current = current[pathParts[key]];
}
return current;
};
}(window.jsOMS = window.jsOMS || {}));

View File

@ -1,91 +0,0 @@
/**
* Standard library
*
* This library provides useful functionalities for the DOM and other manipulations.
*
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @since 1.0.0
*/
(function (jsOMS)
{
'use strict';
/**
* Delayed watcher
*
* Used to fire event after delay
*
* @return {callback}
*
* @since 1.0.0
*/
jsOMS.watcher = (function ()
{
var timer = 0; // eslint-disable-line no-var
return function (callback, ms)
{
clearTimeout(timer);
timer = setTimeout(callback, ms);
};
})();
/**
* Merging two arrays recursively
*
* @param target Target array
* @param source Source array
*
* @return {Array}
*
* @since 1.0.0
*/
jsOMS.merge = function (target, source)
{
const out = jsOMS.clone(target);
for (const p in source) {
if (Object.prototype.hasOwnProperty.call(source, p)) {
// Property in destination object set; update its value.
if (typeof source[p] === 'object') {
out[p] = jsOMS.merge(out[p], source[p]);
} else {
out[p] = source[p];
}
} else {
out[p] = source[p];
}
}
return out;
};
/**
* Shallow clones an object.
*
* @param {Object} obj Object to clone
*
* @returns {Object}
*
* @since 1.0.0
*/
jsOMS.clone = function (obj)
{
return { ...obj };
};
/**
* Check if a value/variable is set
*
* @param variable Variable to check for existence.
*
* @return {boolean}
*
* @since 1.0.0
*/
jsOMS.isset = function (variable)
{
return typeof variable !== 'undefined' && variable !== null;
};
}(window.jsOMS = window.jsOMS || {}));

View File

@ -1,217 +0,0 @@
/**
* Standard library
*
* This library provides useful functionalities for the DOM and other manipulations.
*
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @since 1.0.0
*/
(function (jsOMS)
{
'use strict';
/**
* Trim char from string
*
* @param {string} str String to trim from
* @param {string} [char] Char to trim
*
* @return {string}
*
* @since 1.0.0
*/
jsOMS.trim = function (str, char = ' ')
{
return jsOMS.ltrim(jsOMS.rtrim(str, char), char);
};
/**
* Trim char from right part of string
*
* @param {string} str String to trim from
* @param {string} [char] Char to trim
*
* @return {string}
*
* @since 1.0.0
*/
jsOMS.rtrim = function (str, char = ' ')
{
return str.replace(new RegExp('[' + char + ']*$'), '');
};
/**
* Trim char from left part of string
*
* @param {string} str String to trim from
* @param {string} [char] Char to trim
*
* @return {string}
*
* @since 1.0.0
*/
jsOMS.ltrim = function (str, char = ' ')
{
return str.replace(new RegExp('^[' + char + ']*'), '');
};
jsOMS.htmlspecialchars = [
['&', '&amp;'],
['<', '&lt;'],
['>', '&gt;'],
['"', '&quot;']
];
/**
* Encode none-html string
*
* @param {string} str String to encode
*
* @return {string}
*
* @since 1.0.0
*/
jsOMS.htmlspecialchars_encode = function (str)
{
let escaped = str;
const length = jsOMS.htmlspecialchars.length;
for (let i = 0; i < length; ++i) {
escaped = escaped.replace(
new RegExp(jsOMS.htmlspecialchars[i][0], 'g'),
jsOMS.htmlspecialchars[i][1]
);
}
return escaped;
};
/**
* Decode html string
*
* @param {string} str String to encode
*
* @return {string}
*
* @since 1.0.0
*/
jsOMS.htmlspecialchars_decode = function (str)
{
let decoded = str;
const length = jsOMS.htmlspecialchars.length;
for (let i = 0; i < length; ++i) {
decoded = decoded.replace(
new RegExp(jsOMS.htmlspecialchars[i][1], 'g'),
jsOMS.htmlspecialchars[i][0]
);
}
return decoded;
};
/**
* Validate json string
*
* @param {string} jsonString String to validate
*
* @return {boolean}
*
* @since 1.0.0
*/
jsOMS.isValidJson = function (jsonString)
{
try {
JSON.parse(jsonString);
} catch (e) {
return false;
}
return true;
};
/**
* Count string in string
*
* @param {string} str String to inspect
* @param {string} substr Substring to count
*
* @return {number}
*
* @since 1.0.0
*/
jsOMS.substr_count = function (str, substr)
{
str += '';
substr += '';
const step = substr.length;
if (step <= 0) {
return (str.length + 1);
}
let n = 0;
let pos = 0;
while (true) {
pos = str.indexOf(substr, pos);
if (pos >= 0) {
++n;
pos += step;
} else {
break;
}
}
return n;
};
/**
* Integer hash
*
* @param {string} str String to hash
*
* @return {number}
*
* @since 1.0.0
*/
jsOMS.hash = function (str)
{
let res = 0;
const len = str.length;
for (let i = 0; i < len; ++i) {
res = res * 31 + str.charCodeAt(i);
}
return res;
};
/**
* Get the remaining string after finding a certain char
*
* @param {string} haystack String to to search in
* @param {Array} chars Chars to search for
*
* @return {string}
*
* @since 1.0.0
*/
jsOMS.strpbrk = function (haystack, chars)
{
const length = chars.length;
let found = haystack.length;
let min = haystack.length;
for (let i = 0; i < length; ++i) {
if ((found = haystack.indexOf(chars.charAt(i))) >= 0 && min > found) {
min = found;
}
}
return haystack.slice(min);
};
}(window.jsOMS = window.jsOMS || {}));

View File

@ -1,268 +0,0 @@
/**
* Standard library
*
* This library provides useful functionalities for the DOM and other manipulations.
*
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @since 1.0.0
*/
(function (jsOMS)
{
'use strict';
/**
* Class finder
*
* Checking if a element has a class
*
* @param {Object} ele DOM Element
* @param {string} cls Class to find
*
* @return {boolean}
*
* @since 1.0.0
*/
jsOMS.hasClass = function (ele, cls)
{
return typeof ele !== 'undefined'
&& ele !== null
&& typeof ele.className !== 'undefined'
&& ele.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)')) !== null;
};
/**
* Trigger an event
*
* @param {Element} element Element where the event is assigned
* @param {string} eventName Name of the event
*
* @return void
*
* @function
*
* @since 1.0.0
*/
jsOMS.triggerEvent = function (element, eventName)
{
if (document.createEvent) {
const event = document.createEvent('HTMLEvents');
event.initEvent(eventName, true, true);
event.eventName = eventName;
element.dispatchEvent(event);
} else {
const event = document.createEventObject();
event.eventName = eventName;
event.eventType = eventName;
element.fireEvent(event.eventType, event);
}
};
/**
* Add class
*
* Adding a class to an element
*
* @param {Element} DOM Element
* @param {string} Class to add
*
* @return {void}
*
* @since 1.0.0
*/
jsOMS.addClass = function (ele, cls)
{
if (!jsOMS.hasClass(ele, cls)) {
ele.className += ele.className !== '' ? ' ' + cls : cls;
}
};
/**
* Remove class
*
* Removing a class form an element
*
* @param {Element} DOM Element
* @param {string} Class to remove
*
* @return {void}
*
* @since 1.0.0
*/
jsOMS.removeClass = function (ele, cls)
{
if (jsOMS.hasClass(ele, cls)) {
const reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
ele.className = ele.className.replace(reg, '');
}
};
/**
* Get element value
*
* @param {Element} DOM Element
*
* @return {string}
*
* @since 1.0.0
*/
jsOMS.getValue = function (ele)
{
switch (ele.tagName.toLowerCase()) {
case 'div':
case 'pre':
case 'article':
case 'section':
return ele.innerHTML;
default:
return ele.value;
}
};
/**
* Action prevent
*
* Preventing event from firing and passing through
*
* @param {Event} event Event to stop
*
* @return {void}
*
* @since 1.0.0
*/
jsOMS.preventAll = function (event)
{
event.preventDefault();
event.stopImmediatePropagation();
event.stopPropagation();
event.cancelBubble = true;
};
/**
* Ready invoke
*
* Invoking a function after page load
*
* @param {function} func Callback function
*
* @return {void}
*
* @since 1.0.0
*/
jsOMS.ready = function (func)
{
if (document.readyState === 'complete'
|| document.readyState === 'loaded'
|| document.readyState === 'interactive'
) {
func();
} else {
document.addEventListener('DOMContentLoaded', function (event)
{
func();
});
}
};
/**
* Empty element
*
* Deleting content from element
*
* @param {Element} DOM Element
*
* @return {void}
*
* @since 1.0.0
*/
jsOMS.empty = function (ele)
{
while (ele.firstChild) {
ele.removeChild(ele.firstChild);
}
};
/**
* Check node
*
* Checking if a selection is a node
*
* @param {Node} DOM Node
*
* @return {boolean}
*
* @since 1.0.0
*/
jsOMS.isNode = function (ele)
{
/** global: Node */
return (
typeof Node === 'object' ? ele instanceof Node : ele && typeof ele === 'object' && typeof ele.nodeType === 'number' && typeof ele.nodeName === 'string'
);
};
/**
* Check element
*
* Checking if a selection is a element
*
* @param {HTMLElement} DOM Element
*
* @return {boolean}
*
* @since 1.0.0
*/
jsOMS.isElement = function (o)
{
/** global: HTMLElement */
return (
typeof HTMLElement === 'object' ? o instanceof HTMLElement : o && typeof o === 'object' && o !== null && o.nodeType === 1 && typeof o.nodeName === 'string'
);
};
/**
* Getting element by class
*
* Getting a element by class in the first level
*
* @param {Element} DOM Element
* @param {string} Class to find
*
* @return {null|Element}
*
* @since 1.0.0
*/
jsOMS.getByClass = function (ele, cls)
{
const length = ele.childNodes.length;
for (let i = 0; i < length; ++i) {
if (jsOMS.hasClass(ele.childNodes[i], cls)) {
return ele.childNodes[i];
}
}
return null;
};
/**
* Adding event listener to multiple elements
*
* @param {Element} e DOM Elements
* @param {string} event Event name
* @param {function} callback Event callback
*
* @return {void}
*
* @since 1.0.0
*/
jsOMS.addEventListenerToAll = function (e, event, callback)
{
const length = e.length;
for (let i = 0; i < length; ++i) {
e[i].addEventListener(event, callback);
}
};
}(window.jsOMS = window.jsOMS || {}));

View File

@ -8,10 +8,8 @@
* @version 1.0.0
* @since 1.0.0
*/
(function (jsOMS)
export class jsOMS
{
'use strict';
/**
* Trigger an event
*
@ -24,7 +22,7 @@
*
* @since 1.0.0
*/
jsOMS.triggerEvent = function (element, eventName)
static triggerEvent = function (element, eventName)
{
if (document.createEvent) {
const event = document.createEvent('HTMLEvents');
@ -52,7 +50,7 @@
*
* @since 1.0.0
*/
jsOMS.getArray = function (path, data, delim = '/')
static getArray = function (path, data, delim = '/')
{
const pathParts = jsOMS.ltrim(path, delim).split(delim);
let current = data;
@ -84,7 +82,7 @@
*
* @since 1.0.0
*/
jsOMS.trim = function (str, char = ' ')
static trim = function (str, char = ' ')
{
return jsOMS.ltrim(jsOMS.rtrim(str, char), char);
};
@ -101,7 +99,7 @@
*
* @since 1.0.0
*/
jsOMS.rtrim = function (str, char = ' ')
static rtrim = function (str, char = ' ')
{
return str.replace(new RegExp('[' + char + ']*$'), '');
};
@ -118,12 +116,12 @@
*
* @since 1.0.0
*/
jsOMS.ltrim = function (str, char = ' ')
static ltrim = function (str, char = ' ')
{
return str.replace(new RegExp('^[' + char + ']*'), '');
};
jsOMS.htmlspecialchars = [
static htmlspecialchars = [
['&', '&amp;'],
['<', '&lt;'],
['>', '&gt;'],
@ -139,10 +137,10 @@
*
* @since 1.0.0
*/
jsOMS.htmlspecialchars_encode = function (str)
static htmlspecialchars_encode = function (str)
{
let escaped = str;
const length = jsOMS.htmlspecialchars.length;
const length = htmlspecialchars.length;
for (let i = 0; i < length; ++i) {
escaped = escaped.replace(
@ -163,7 +161,7 @@
*
* @since 1.0.0
*/
jsOMS.htmlspecialchars_decode = function (str)
static htmlspecialchars_decode = function (str)
{
let decoded = str;
const length = jsOMS.htmlspecialchars.length;
@ -190,7 +188,7 @@
*
* @since 1.0.0
*/
jsOMS.substr_count = function (str, substr)
static substr_count = function (str, substr)
{
str += '';
substr += '';
@ -231,7 +229,7 @@
*
* @since 1.0.0
*/
jsOMS.hasClass = function (ele, cls)
static hasClass = function (ele, cls)
{
return typeof ele !== 'undefined'
&& ele !== null
@ -255,7 +253,7 @@
*
* @since 1.0.0
*/
jsOMS.addClass = function (ele, cls)
static addClass = function (ele, cls)
{
if (!jsOMS.hasClass(ele, cls)) {
if (typeof ele.className === 'string') {
@ -280,7 +278,7 @@
*
* @since 1.0.0
*/
jsOMS.removeClass = function (ele, cls)
static removeClass = function (ele, cls)
{
if (jsOMS.hasClass(ele, cls)) {
const reg = new RegExp('(\\s|^)' + cls);
@ -304,7 +302,7 @@
*
* @since 1.0.0
*/
jsOMS.watcher = (function ()
static watcher = (function ()
{
let watcherTimer = 0;
return function (callback, ms)
@ -327,7 +325,7 @@
*
* @since 1.0.0
*/
jsOMS.preventAll = function (event)
static preventAll = function (event)
{
event.preventDefault();
event.stopImmediatePropagation();
@ -350,7 +348,7 @@
*
* @since 1.0.0
*/
jsOMS.ready = function (func)
static ready = function (func)
{
if (document.readyState === 'complete' || document.readyState === 'loaded' || document.readyState === 'interactive') {
func();
@ -371,7 +369,7 @@
*
* @since 1.0.0
*/
jsOMS.getValue = function (ele)
static getValue = function (ele)
{
switch (ele.tagName.toLowerCase()) {
case 'div':
@ -397,7 +395,7 @@
*
* @since 1.0.0
*/
jsOMS.empty = function (ele)
static empty = function (ele)
{
while (ele.firstChild) {
ele.removeChild(ele.firstChild);
@ -415,7 +413,7 @@
*
* @since 1.0.0
*/
jsOMS.hash = function (str)
static hash = function (str)
{
let res = 0;
const len = str.length;
@ -440,7 +438,7 @@
*
* @since 1.0.0
*/
jsOMS.isNode = function (ele)
static isNode = function (ele)
{
/** global: Node */
return (
@ -461,7 +459,7 @@
*
* @since 1.0.0
*/
jsOMS.isElement = function (o)
static isElement = function (o)
{
/** global: HTMLElement */
return (
@ -483,7 +481,7 @@
*
* @since 1.0.0
*/
jsOMS.getByClass = function (ele, cls)
static getByClass = function (ele, cls)
{
const length = ele.childNodes.length;
@ -509,7 +507,7 @@
*
* @since 1.0.0
*/
jsOMS.addEventListenerToAll = function (e, event, callback)
static addEventListenerToAll = function (e, event, callback)
{
const length = e.length;
@ -529,7 +527,7 @@
*
* @since 1.0.0
*/
jsOMS.isValidJson = function (jsonString)
static isValidJson = function (jsonString)
{
try {
JSON.parse(jsonString);
@ -551,7 +549,7 @@
*
* @since 1.0.0
*/
jsOMS.merge = function (target, source)
static merge = function (target, source)
{
const out = jsOMS.clone(target);
@ -580,7 +578,7 @@
*
* @since 1.0.0
*/
jsOMS.clone = function (obj)
static clone = function (obj)
{
return { ...obj };
};
@ -594,7 +592,7 @@
*
* @since 1.0.0
*/
jsOMS.isset = function (variable)
static isset = function (variable)
{
return typeof variable !== 'undefined' && variable !== null;
};
@ -609,7 +607,7 @@
*
* @since 1.0.0
*/
jsOMS.strpbrk = function (haystack, chars)
static strpbrk = function (haystack, chars)
{
const length = chars.length;
let found = haystack.length;
@ -623,4 +621,4 @@
return haystack.slice(min);
};
}(window.jsOMS = window.jsOMS || {}));
}

View File

@ -1,3 +1,4 @@
import { jsOMS } from '../Utils/oLib.js';
import { Input } from '../UI/Component/Input.js';
/**