39331-vm/assets/js/main.js
Flatlogic Bot 522a55296c arsip_demo
2026-03-26 11:04:24 +00:00

47 lines
1.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

document.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('.tree-toggle').forEach((toggle) => {
const targetSelector = toggle.getAttribute('data-tree-target');
const target = targetSelector ? document.querySelector(targetSelector) : null;
const icon = toggle.querySelector('.tree-icon');
const syncState = () => {
const open = target && target.classList.contains('show');
toggle.classList.toggle('open', !!open);
toggle.setAttribute('aria-expanded', open ? 'true' : 'false');
if (icon) {
icon.textContent = open ? '' : '+';
}
};
syncState();
toggle.addEventListener('click', () => {
if (target) {
target.classList.toggle('show');
}
syncState();
});
});
document.querySelectorAll('.toast').forEach((el) => {
const toast = new bootstrap.Toast(el, { delay: 4500 });
toast.show();
});
const folderSelect = document.getElementById('folder_path');
const mainMenuSelect = document.getElementById('main_menu');
if (folderSelect && mainMenuSelect) {
const syncMenuFromFolder = () => {
const selectedOption = folderSelect.options[folderSelect.selectedIndex];
if (!selectedOption || !selectedOption.value) return;
const mainMenu = selectedOption.value.split(' / ')[0];
if ([...mainMenuSelect.options].some((option) => option.value === mainMenu)) {
mainMenuSelect.value = mainMenu;
}
};
folderSelect.addEventListener('change', syncMenuFromFolder);
syncMenuFromFolder();
}
document.querySelectorAll('[data-print-trigger]').forEach((button) => {
button.addEventListener('click', () => window.print());
});
});