'use strict'; { const toggleNavSidebar = document.getElementById('toggle-nav-sidebar'); if (toggleNavSidebar !== null) { const navLinks = document.querySelectorAll('#nav-sidebar a'); function disableNavLinkTabbing() { for (const navLink of navLinks) { navLink.tabIndex = -1; } } function enableNavLinkTabbing() { for (const navLink of navLinks) { navLink.tabIndex = 0; } } function disableNavFilterTabbing() { document.getElementById('nav-filter').tabIndex = -1; } function enableNavFilterTabbing() { document.getElementById('nav-filter').tabIndex = 0; } const main = document.getElementById('main'); let navSidebarIsOpen = localStorage.getItem('django.admin.navSidebarIsOpen'); if (navSidebarIsOpen === null) { navSidebarIsOpen = 'true'; } if (navSidebarIsOpen === 'false') { disableNavLinkTabbing(); disableNavFilterTabbing(); } main.classList.toggle('shifted', navSidebarIsOpen === 'true'); toggleNavSidebar.addEventListener('click', function() { if (navSidebarIsOpen === 'true') { navSidebarIsOpen = 'false'; disableNavLinkTabbing(); disableNavFilterTabbing(); } else { navSidebarIsOpen = 'true'; enableNavLinkTabbing(); enableNavFilterTabbing(); } localStorage.setItem('django.admin.navSidebarIsOpen', navSidebarIsOpen); main.classList.toggle('shifted'); }); } function initSidebarQuickFilter() { const options = []; const navSidebar = document.getElementById('nav-sidebar'); if (!navSidebar) { return; } navSidebar.querySelectorAll('th[scope=row] a').forEach((container) => { options.push({title: container.innerHTML, node: container}); }); function checkValue(event) { let filterValue = event.target.value; if (filterValue) { filterValue = filterValue.toLowerCase(); } if (event.key === 'Escape') { filterValue = ''; event.target.value = ''; // clear input } let matches = false; for (const o of options) { let displayValue = ''; if (filterValue) { if (o.title.toLowerCase().indexOf(filterValue) === -1) { displayValue = 'none'; } else { matches = true; } } // show/hide parent