chore: update templ and templui
This commit is contained in:
parent
b5d195baea
commit
61eaa268ab
89 changed files with 25776 additions and 8231 deletions
58
assets/js/label.js
Normal file
58
assets/js/label.js
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
(function () {
|
||||
'use strict';
|
||||
|
||||
function updateLabelStyle(label) {
|
||||
const forId = label.getAttribute('for');
|
||||
const targetElement = forId ? document.getElementById(forId) : null;
|
||||
const disabledStyle = label.getAttribute('data-tui-label-disabled-style');
|
||||
|
||||
if (!targetElement || !disabledStyle) return;
|
||||
|
||||
const classes = disabledStyle.split(' ').filter(Boolean);
|
||||
|
||||
if (targetElement.disabled) {
|
||||
label.classList.add(...classes);
|
||||
} else {
|
||||
label.classList.remove(...classes);
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const labelsToObserve = new Set();
|
||||
|
||||
// Find all labels and their targets
|
||||
function setupLabels() {
|
||||
document.querySelectorAll('label[for][data-tui-label-disabled-style]').forEach(label => {
|
||||
updateLabelStyle(label);
|
||||
const forId = label.getAttribute('for');
|
||||
if (forId) labelsToObserve.add(forId);
|
||||
});
|
||||
}
|
||||
|
||||
setupLabels();
|
||||
|
||||
// Observe disabled changes on any element
|
||||
const observer = new MutationObserver((mutations) => {
|
||||
mutations.forEach((mutation) => {
|
||||
if (mutation.type === 'attributes' &&
|
||||
mutation.attributeName === 'disabled' &&
|
||||
mutation.target.id &&
|
||||
labelsToObserve.has(mutation.target.id)) {
|
||||
document.querySelectorAll(`label[for="${mutation.target.id}"][data-tui-label-disabled-style]`).forEach(updateLabelStyle);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Observe the whole document for disabled changes
|
||||
observer.observe(document.body, {
|
||||
attributes: true,
|
||||
attributeFilter: ['disabled'],
|
||||
subtree: true
|
||||
});
|
||||
|
||||
// Watch for new labels
|
||||
new MutationObserver(() => {
|
||||
setupLabels();
|
||||
}).observe(document.body, { childList: true, subtree: true });
|
||||
});
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue