Files
TaskHybrid/salesbook.Shared/wwwroot/js/main.js

101 lines
3.5 KiB
JavaScript

// Funzione goBack
window.goBack = function () {
console.log("goBack");
history.back();
};
// Funzione per aggiungere tabindex ai bottoni
function addTabindexToButtons() {
document.querySelectorAll('button.custom-plus-button').forEach(btn => {
if (!btn.hasAttribute('tabindex')) {
btn.setAttribute('tabindex', '0');
}
});
}
// Funzione per monitorare la classe expanded e aggiungere ah-calendar-m
function monitorExpandedClass(mutations) {
mutations.forEach(function (mutation) {
if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
const target = mutation.target;
if (target.classList.contains('week-slider') && target.classList.contains('expanded')) {
const appointments = document.querySelector('.appointments');
if (appointments) {
appointments.classList.add('ah-calendar-m');
console.log('Classe "ah-calendar-m" aggiunta a .appointments');
}
}
// Rimuovi la classe quando expanded viene rimossa
else if (target.classList.contains('week-slider') && !target.classList.contains('expanded')) {
const appointments = document.querySelector('.appointments');
if (appointments) {
appointments.classList.remove('ah-calendar-m');
console.log('Classe "ah-calendar-m" rimossa da .appointments');
}
}
}
});
}
// Funzione per monitorare bottom-sheet-container e gestire la navbar
function monitorBottomSheetClass(mutations) {
const bottomSheet = document.querySelector(".bottom-sheet-container");
const navbar = document.querySelector(".animated-navbar");
if (!bottomSheet || !navbar) return;
mutations.forEach(function (mutation) {
if (mutation.type === 'attributes' && mutation.attributeName === 'class' && mutation.target === bottomSheet) {
if (bottomSheet.classList.contains("show")) {
navbar.classList.remove("show-nav");
navbar.classList.add("hide-nav");
console.log("Navbar nascosta (hide-nav)");
} else {
navbar.classList.remove("hide-nav");
navbar.classList.add("show-nav");
console.log("Navbar mostrata (show-nav)");
}
}
});
}
// Esegui la funzione tabindex inizialmente
addTabindexToButtons();
// Observer combinato per tutte le funzionalità
const observer = new MutationObserver((mutations) => {
// Aggiungi tabindex ai nuovi bottoni
addTabindexToButtons();
// Monitora le classi expanded
monitorExpandedClass(mutations);
// Monitora bottom-sheet-container
monitorBottomSheetClass(mutations);
});
// Osserva sia i cambiamenti nel DOM che gli attributi
observer.observe(document.body, {
childList: true,
subtree: true,
attributes: true,
attributeFilter: ['class']
});
// Sync iniziale per la navbar (nel caso la pagina parte già con .show)
document.addEventListener("DOMContentLoaded", () => {
const bottomSheet = document.querySelector(".bottom-sheet-container");
const navbar = document.querySelector(".animated-navbar");
if (bottomSheet && navbar) {
if (bottomSheet.classList.contains("show")) {
navbar.classList.remove("show-nav");
navbar.classList.add("hide-nav");
} else {
navbar.classList.remove("hide-nav");
navbar.classList.add("show-nav");
}
}
});