From a0f2097b1bca5a75ee1bb764d124452aea766cd4 Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Wed, 15 Mar 2023 21:30:12 +0530 Subject: [PATCH] Move the createElement() function to utils.js --- ui/media/js/main.js | 31 ------------------------------- ui/media/js/utils.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/ui/media/js/main.js b/ui/media/js/main.js index 63683b65..57789cef 100644 --- a/ui/media/js/main.js +++ b/ui/media/js/main.js @@ -1703,34 +1703,3 @@ prettifyInputs(document); // set the textbox as focused on start promptField.focus() promptField.selectionStart = promptField.value.length - -/** - * - * @param {string} tag - * @param {object} attributes - * @param {string | Array} classes - * @param {string | HTMLElement | Array} - * @returns {HTMLElement} - */ - function createElement(tagName, attributes, classes, textOrElements) { - const element = document.createElement(tagName) - if (attributes) { - Object.entries(attributes).forEach(([key, value]) => { - element.setAttribute(key, value) - }); - } - if (classes) { - (Array.isArray(classes) ? classes : [classes]).forEach(className => element.classList.add(className)) - } - if (textOrElements) { - const children = Array.isArray(textOrElements) ? textOrElements : [textOrElements] - children.forEach(textOrElem => { - if (textOrElem instanceof HTMLElement) { - element.appendChild(textOrElem) - } else { - element.appendChild(document.createTextNode(textOrElem)) - } - }) - } - return element -} diff --git a/ui/media/js/utils.js b/ui/media/js/utils.js index 3f8d3fab..6eb0d643 100644 --- a/ui/media/js/utils.js +++ b/ui/media/js/utils.js @@ -677,3 +677,34 @@ class ServiceContainer { return typeof definition === 'function' } } + +/** + * + * @param {string} tag + * @param {object} attributes + * @param {string | Array} classes + * @param {string | HTMLElement | Array} + * @returns {HTMLElement} + */ +function createElement(tagName, attributes, classes, textOrElements) { + const element = document.createElement(tagName) + if (attributes) { + Object.entries(attributes).forEach(([key, value]) => { + element.setAttribute(key, value) + }); + } + if (classes) { + (Array.isArray(classes) ? classes : [classes]).forEach(className => element.classList.add(className)) + } + if (textOrElements) { + const children = Array.isArray(textOrElements) ? textOrElements : [textOrElements] + children.forEach(textOrElem => { + if (textOrElem instanceof HTMLElement) { + element.appendChild(textOrElem) + } else { + element.appendChild(document.createTextNode(textOrElem)) + } + }) + } + return element +}