First version, for githup; UNSTABLE, DO NOT USE!
This commit is contained in:
104
www/intern/js/sidebar.js
Normal file
104
www/intern/js/sidebar.js
Normal file
@@ -0,0 +1,104 @@
|
||||
(function () {
|
||||
const STORAGE_KEY = 'intern_sidebar_open';
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const toggle = document.getElementById('sidebar-toggle');
|
||||
const sidebar = document.getElementById('sidebar-nav');
|
||||
const overlay = document.getElementById('sidebar-overlay');
|
||||
|
||||
if (!toggle || !sidebar || !overlay) return;
|
||||
|
||||
function openSidebar() {
|
||||
sidebar.classList.add('open');
|
||||
overlay.classList.add('open');
|
||||
toggle.classList.add('open');
|
||||
localStorage.setItem(STORAGE_KEY, 'true');
|
||||
}
|
||||
|
||||
function closeSidebar() {
|
||||
sidebar.classList.remove('open');
|
||||
overlay.classList.remove('open');
|
||||
toggle.classList.remove('open');
|
||||
localStorage.setItem(STORAGE_KEY, 'false');
|
||||
}
|
||||
|
||||
function toggleSidebar() {
|
||||
if (sidebar.classList.contains('open')) {
|
||||
closeSidebar();
|
||||
} else {
|
||||
openSidebar();
|
||||
}
|
||||
}
|
||||
|
||||
toggle.addEventListener('click', toggleSidebar);
|
||||
overlay.addEventListener('click', closeSidebar);
|
||||
|
||||
// Keyboard shortcut: press 'M' to toggle
|
||||
document.addEventListener('keydown', function (e) {
|
||||
if (e.key.toLowerCase() === 'm' && !e.ctrlKey && !e.altKey && !e.metaKey) {
|
||||
const tag = document.activeElement?.tagName;
|
||||
if (tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT') return;
|
||||
toggleSidebar();
|
||||
}
|
||||
});
|
||||
|
||||
// Restore state
|
||||
if (localStorage.getItem(STORAGE_KEY) === 'true') {
|
||||
openSidebar();
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
||||
function changeFreigabe(freigabe) {
|
||||
|
||||
const params = new URLSearchParams();
|
||||
params.append('freigabe', freigabe);
|
||||
params.append('type', siteType);
|
||||
|
||||
fetch('/intern/scripts/kampfrichter/ajax/ajax-update_selected_kampfrichter.php', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
body: params
|
||||
})
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
window.location.reload(); // reload page to reflect changes
|
||||
} else {
|
||||
alert('Error: ' + data.data);
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
alert('AJAX request failed');
|
||||
});
|
||||
}
|
||||
|
||||
$(document).on('click', '.sidebar-nav .selectTrigger', function (e) {
|
||||
e.stopPropagation();
|
||||
$(this).closest('.customSelect').toggleClass('open');
|
||||
});
|
||||
|
||||
$(document).on('click', '.sidebar-nav .selectOptions li', function (e) {
|
||||
e.stopPropagation();
|
||||
const $item = $(this);
|
||||
const $container = $item.closest('.customSelect');
|
||||
const val = $item.data('value');
|
||||
const text = $item.text();
|
||||
const $input = $container.find('.selectValue');
|
||||
const $label = $container.find('.selectLabel');
|
||||
const $allOptions = $container.find('.selectOptions li');
|
||||
|
||||
$allOptions.removeClass('selected');
|
||||
|
||||
$item.addClass('selected');
|
||||
|
||||
$input.val(val);
|
||||
$label.text(text);
|
||||
|
||||
$container.removeClass('open');
|
||||
|
||||
changeFreigabe(val);
|
||||
});
|
||||
|
||||
$(document).on('click', () => $('.sidebar-nav .customSelect').removeClass('open'));
|
||||
Reference in New Issue
Block a user