From 72f2c2e1d106662b9d00582fe457ea10a6ba2d8e Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Thu, 5 Oct 2023 07:44:22 +0000 Subject: [PATCH] make oLib a module --- Asset/AssetManager.js | 2 + Autoloader.js | 2 +- Message/Response/ResponseManager.js | 1 + Model/Action/Dom/Hide.js | 1 + Model/Action/Dom/SetValue.js | 1 + Model/Action/Dom/Show.js | 1 + Model/Action/Event/Prevent.js | 1 + Model/Action/Utils/DataCollector.js | 1 + Model/Message/DomAction.js | 1 + Module/ModuleFactory.js | 2 +- UI/ActionManager.js | 1 + UI/Component/AdvancedInput.js | 1 + UI/Component/AdvancedSelect.js | 2 +- UI/Component/Form.js | 89 ++++++--- UI/Component/Tab.js | 1 + UI/Component/Table.js | 1 + UI/DragNDrop.js | 1 + UI/GeneralUI.js | 10 + UI/Input/Keyboard/KeyboardManager.js | 1 + UI/Input/Mouse/MouseManager.js | 1 + UI/Input/Voice/VoiceManager.js | 1 + UI/Order.js | 1 + UI/RemoteData.js | 1 + Uri/HttpUri.js | 1 + Uri/UriFactory.js | 1 + Utils/ArrayUtils.js | 46 ----- Utils/GeneralUtils.js | 91 --------- Utils/StringUtils.js | 217 ---------------------- Utils/UiUtils.js | 268 --------------------------- Utils/oLib.js | 62 +++---- Views/FormView.js | 1 + 31 files changed, 132 insertions(+), 679 deletions(-) delete mode 100755 Utils/ArrayUtils.js delete mode 100755 Utils/GeneralUtils.js delete mode 100755 Utils/StringUtils.js delete mode 100755 Utils/UiUtils.js diff --git a/Asset/AssetManager.js b/Asset/AssetManager.js index 36798c6..0c53df2 100755 --- a/Asset/AssetManager.js +++ b/Asset/AssetManager.js @@ -1,3 +1,5 @@ +import { jsOMS } from '../Utils/oLib.js'; + /** * Asset manager. * diff --git a/Autoloader.js b/Autoloader.js index 2704881..0b6ef60 100755 --- a/Autoloader.js +++ b/Autoloader.js @@ -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') { diff --git a/Message/Response/ResponseManager.js b/Message/Response/ResponseManager.js index c3f255c..17b49c4 100755 --- a/Message/Response/ResponseManager.js +++ b/Message/Response/ResponseManager.js @@ -1,3 +1,4 @@ +import { jsOMS } from '../../Utils/oLib.js'; /** * @typedef {import('../Request/Request.js').Request} Request */ diff --git a/Model/Action/Dom/Hide.js b/Model/Action/Dom/Hide.js index 3c5320f..69a948d 100755 --- a/Model/Action/Dom/Hide.js +++ b/Model/Action/Dom/Hide.js @@ -1,3 +1,4 @@ +import { jsOMS } from '../../../Utils/oLib.js'; /** * Hide an element. * diff --git a/Model/Action/Dom/SetValue.js b/Model/Action/Dom/SetValue.js index 7b6732a..ccc2f01 100755 --- a/Model/Action/Dom/SetValue.js +++ b/Model/Action/Dom/SetValue.js @@ -1,3 +1,4 @@ +import { jsOMS } from '../../../Utils/oLib.js'; import { UriFactory } from '../../../Uri/UriFactory.js'; /** diff --git a/Model/Action/Dom/Show.js b/Model/Action/Dom/Show.js index a88ca9b..9b94e9f 100755 --- a/Model/Action/Dom/Show.js +++ b/Model/Action/Dom/Show.js @@ -1,3 +1,4 @@ +import { jsOMS } from '../../../Utils/oLib.js'; /** * Show dom element. * diff --git a/Model/Action/Event/Prevent.js b/Model/Action/Event/Prevent.js index 4d4068c..c8ab32f 100755 --- a/Model/Action/Event/Prevent.js +++ b/Model/Action/Event/Prevent.js @@ -1,3 +1,4 @@ +import { jsOMS } from '../../../Utils/oLib.js'; /** * Prevent UI action. * diff --git a/Model/Action/Utils/DataCollector.js b/Model/Action/Utils/DataCollector.js index 04cd446..3446bdb 100755 --- a/Model/Action/Utils/DataCollector.js +++ b/Model/Action/Utils/DataCollector.js @@ -1,3 +1,4 @@ +import { jsOMS } from '../../../Utils/oLib.js'; /** * Collect data. * diff --git a/Model/Message/DomAction.js b/Model/Message/DomAction.js index 9db0721..1a262e8 100755 --- a/Model/Message/DomAction.js +++ b/Model/Message/DomAction.js @@ -1,3 +1,4 @@ +import { jsOMS } from '../../Utils/oLib.js'; /** * Perform DOM action. * diff --git a/Module/ModuleFactory.js b/Module/ModuleFactory.js index 3983800..f5796cb 100755 --- a/Module/ModuleFactory.js +++ b/Module/ModuleFactory.js @@ -20,6 +20,6 @@ export class ModuleFactory */ static getInstance (module, app) { - return new jsOMS.Modules[module](app); + return new omsApp.Modules[module](app); }; }; diff --git a/UI/ActionManager.js b/UI/ActionManager.js index 0ae1c37..d05291a 100755 --- a/UI/ActionManager.js +++ b/UI/ActionManager.js @@ -1,3 +1,4 @@ +import { jsOMS } from '../Utils/oLib.js'; import { Logger } from '../Log/Logger.js'; /** diff --git a/UI/Component/AdvancedInput.js b/UI/Component/AdvancedInput.js index 67051d7..18c29db 100755 --- a/UI/Component/AdvancedInput.js +++ b/UI/Component/AdvancedInput.js @@ -1,3 +1,4 @@ +import { jsOMS } from '../../Utils/oLib.js'; import { Request } from '../../Message/Request/Request.js'; /** diff --git a/UI/Component/AdvancedSelect.js b/UI/Component/AdvancedSelect.js index aa4900b..1ef4e7d 100755 --- a/UI/Component/AdvancedSelect.js +++ b/UI/Component/AdvancedSelect.js @@ -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. diff --git a/UI/Component/Form.js b/UI/Component/Form.js index 262c755..277aa44 100755 --- a/UI/Component/Form.js +++ b/UI/Component/Form.js @@ -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') diff --git a/UI/Component/Tab.js b/UI/Component/Tab.js index 12119ec..bc9e260 100755 --- a/UI/Component/Tab.js +++ b/UI/Component/Tab.js @@ -1,3 +1,4 @@ +import { jsOMS } from '../../Utils/oLib.js'; import { HttpUri } from '../../Uri/HttpUri.js'; import { UriFactory } from '../../Uri/UriFactory.js'; diff --git a/UI/Component/Table.js b/UI/Component/Table.js index e922bff..09b9a89 100755 --- a/UI/Component/Table.js +++ b/UI/Component/Table.js @@ -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'; diff --git a/UI/DragNDrop.js b/UI/DragNDrop.js index 2490ed7..a6a2052 100755 --- a/UI/DragNDrop.js +++ b/UI/DragNDrop.js @@ -1,3 +1,4 @@ +import { jsOMS } from '../Utils/oLib.js'; /** * Drag and drop class. * diff --git a/UI/GeneralUI.js b/UI/GeneralUI.js index e1594ed..850c115 100755 --- a/UI/GeneralUI.js +++ b/UI/GeneralUI.js @@ -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; } diff --git a/UI/Input/Keyboard/KeyboardManager.js b/UI/Input/Keyboard/KeyboardManager.js index b8888d8..2bfafab 100755 --- a/UI/Input/Keyboard/KeyboardManager.js +++ b/UI/Input/Keyboard/KeyboardManager.js @@ -1,3 +1,4 @@ +import { jsOMS } from '../../../Utils/oLib.js'; /** * Keyboard manager class. * diff --git a/UI/Input/Mouse/MouseManager.js b/UI/Input/Mouse/MouseManager.js index 047f767..e1643e0 100755 --- a/UI/Input/Mouse/MouseManager.js +++ b/UI/Input/Mouse/MouseManager.js @@ -1,3 +1,4 @@ +import { jsOMS } from '../../../Utils/oLib.js'; import { EventType } from '../../../../jsOMS/UI/Input/Mouse/EventType.js'; /** diff --git a/UI/Input/Voice/VoiceManager.js b/UI/Input/Voice/VoiceManager.js index 96948cc..64f5086 100755 --- a/UI/Input/Voice/VoiceManager.js +++ b/UI/Input/Voice/VoiceManager.js @@ -1,3 +1,4 @@ +import { jsOMS } from '../../../Utils/oLib.js'; import { Logger } from '../../../Log/Logger.js'; /** diff --git a/UI/Order.js b/UI/Order.js index e3b3684..c9022a4 100755 --- a/UI/Order.js +++ b/UI/Order.js @@ -1,3 +1,4 @@ +import { jsOMS } from '../Utils/oLib.js'; /** * Manual order class. * diff --git a/UI/RemoteData.js b/UI/RemoteData.js index b1319ea..808bf59 100755 --- a/UI/RemoteData.js +++ b/UI/RemoteData.js @@ -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'; diff --git a/Uri/HttpUri.js b/Uri/HttpUri.js index 229b8c8..077d01d 100755 --- a/Uri/HttpUri.js +++ b/Uri/HttpUri.js @@ -1,3 +1,4 @@ +import { jsOMS } from '../Utils/oLib.js'; /** * Http Uri. * diff --git a/Uri/UriFactory.js b/Uri/UriFactory.js index da927ea..8daf364 100755 --- a/Uri/UriFactory.js +++ b/Uri/UriFactory.js @@ -1,3 +1,4 @@ +import { jsOMS } from '../Utils/oLib.js'; import { HttpUri } from './HttpUri.js'; import { FormView } from './../Views/FormView.js'; diff --git a/Utils/ArrayUtils.js b/Utils/ArrayUtils.js deleted file mode 100755 index 4abdcfb..0000000 --- a/Utils/ArrayUtils.js +++ /dev/null @@ -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 || {})); diff --git a/Utils/GeneralUtils.js b/Utils/GeneralUtils.js deleted file mode 100755 index 86e412b..0000000 --- a/Utils/GeneralUtils.js +++ /dev/null @@ -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 || {})); diff --git a/Utils/StringUtils.js b/Utils/StringUtils.js deleted file mode 100755 index ccd8193..0000000 --- a/Utils/StringUtils.js +++ /dev/null @@ -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 = [ - ['&', '&'], - ['<', '<'], - ['>', '>'], - ['"', '"'] - ]; - - /** - * 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 || {})); diff --git a/Utils/UiUtils.js b/Utils/UiUtils.js deleted file mode 100755 index 46ffcd5..0000000 --- a/Utils/UiUtils.js +++ /dev/null @@ -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 || {})); diff --git a/Utils/oLib.js b/Utils/oLib.js index 8354e02..0816760 100755 --- a/Utils/oLib.js +++ b/Utils/oLib.js @@ -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 = [ ['&', '&'], ['<', '<'], ['>', '>'], @@ -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 || {})); +} diff --git a/Views/FormView.js b/Views/FormView.js index 444c874..d199661 100755 --- a/Views/FormView.js +++ b/Views/FormView.js @@ -1,3 +1,4 @@ +import { jsOMS } from '../Utils/oLib.js'; import { Input } from '../UI/Component/Input.js'; /**