QrRapido/wwwroot/js/simple-opcacity.js
Ricardo Carneiro 1b74de34e6
Some checks failed
Deploy QR Rapido / test (push) Successful in 4m11s
Deploy QR Rapido / build-and-push (push) Failing after 5m52s
Deploy QR Rapido / deploy-staging (push) Has been skipped
Deploy QR Rapido / deploy-production (push) Has been skipped
fix: ajustes de javascript e funcionamento
2025-09-22 14:54:43 -03:00

67 lines
2.1 KiB
JavaScript

class SimpleOpacityController {
constructor(controlSelector, targetSelector) {
this.controlSelector = controlSelector;
this.targetSelector = targetSelector;
this.disabledClass = 'disabled-state';
this.init();
}
init() {
const controls = document.querySelectorAll(this.controlSelector);
const targets = document.querySelectorAll(this.targetSelector);
// Listener para detectar mudanças
controls.forEach(control => {
control.addEventListener('change', () => {
this.updateOpacity();
});
});
// Estado inicial
this.updateOpacity();
// Simple opacity system initialized
}
updateOpacity() {
const hasSelection = this.hasSelection();
const targets = document.querySelectorAll(this.targetSelector);
targets.forEach(target => {
if (hasSelection) {
// TEM seleção = div normal
target.classList.remove(this.disabledClass);
// Div activated - selection detected
} else {
// NÃO tem seleção = div opaca
target.classList.add(this.disabledClass);
// Div deactivated - no selection
}
});
}
hasSelection() {
// Para SELECT: verificar se valor não está vazio
const selects = document.querySelectorAll(this.controlSelector + '[type=""], ' + this.controlSelector + ':not([type])');
for (let select of selects) {
if (select.value && select.value.trim() !== '') {
return true;
}
}
// Para RADIO BUTTONS: verificar se algum está selecionado E não é vazio
const radios = document.querySelectorAll(this.controlSelector + '[type="radio"]');
for (let radio of radios) {
if (radio.checked && radio.value && radio.value.trim() !== '') {
return true;
}
}
return false;
}
}
if (typeof window !== 'undefined') {
window.SimpleOpacityController = SimpleOpacityController;
}