You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
xshop/resources/js/panel/setting-section-controller.js

60 lines
1.7 KiB
JavaScript

document.addEventListener('DOMContentLoaded', function () {
// Get all section group items
let sectionGroupItems = document.querySelectorAll('.section-group-item');
// Get all sections
let sections = document.querySelectorAll('#setting-sections section');
// Hide all sections initially
sections?.forEach(section => {
section.style.display = 'none';
});
// Show/hide sections on click
sectionGroupItems?.forEach(item => {
item.addEventListener('click', function (event) {
try {
event.preventDefault();
let targetId = this.getAttribute('href').slice(1);
sections.forEach(section => {
if (section.id === targetId) {
section.style.display = 'block';
} else {
section.style.display = 'none';
}
});
sectionGroupItems.forEach(link => {
link.classList.remove('active');
});
this.classList.add('active');
} catch (e) {
console.log(e.message);
}
});
});
// Show section based on hash in URL
let hash = window.location.hash.slice(1);
if (hash) {
sections.forEach(section => {
if (section.id === hash) {
section.style.display = 'block';
} else {
section.style.display = 'none';
}
});
}
try {
// Show the first section on page load
document.querySelector('.section-group-item').dispatchEvent(new Event('click'));
} catch (e) {
}
});