60 lines
1.5 KiB
JavaScript
60 lines
1.5 KiB
JavaScript
/**
|
|
* UI Helper Utilities
|
|
* Extracted from Legacy/UIALT.js — pure functions that don't map to Vue components.
|
|
*/
|
|
|
|
/**
|
|
* Get values of all input/textarea elements by CSS class name.
|
|
* Returns an array of { id, value } objects.
|
|
*
|
|
* @param {string} className
|
|
* @returns {{ id: string, value: string }[]}
|
|
*/
|
|
export function getInputAndTextareaValuesByClassName(className) {
|
|
const elements = document.getElementsByClassName(className)
|
|
const results = []
|
|
Array.from(elements).forEach(element => {
|
|
results.push({ id: element.id, value: element.value })
|
|
})
|
|
return results
|
|
}
|
|
|
|
/**
|
|
* Get values of all input elements by CSS class name.
|
|
* Returns an object keyed by element id.
|
|
*
|
|
* @param {string} className
|
|
* @returns {Record<string, string>}
|
|
*/
|
|
export function getInputElementsValuesObjectByClassName(className) {
|
|
const elements = document.getElementsByClassName(className)
|
|
const results = {}
|
|
Array.from(elements).forEach(element => {
|
|
results[element.id] = element.value
|
|
})
|
|
return results
|
|
}
|
|
|
|
/**
|
|
* Inject dynamic CSS into a <style> tag with id="dynamic-css".
|
|
* Creates the tag if it doesn't exist.
|
|
*
|
|
* @param {string} cssText
|
|
*/
|
|
export function setDynamicCSS(cssText) {
|
|
let styleTag = document.getElementById('dynamic-css')
|
|
if (!styleTag) {
|
|
styleTag = document.createElement('style')
|
|
styleTag.id = 'dynamic-css'
|
|
document.head.appendChild(styleTag)
|
|
}
|
|
styleTag.innerHTML = cssText
|
|
}
|
|
|
|
/**
|
|
* Clear all dynamic CSS.
|
|
*/
|
|
export function resetDynamicCSS() {
|
|
setDynamicCSS('')
|
|
}
|