PageSourceSearch

https://polsa.gov.pl/wp-content/themes/polsa/js/menu-arrow-navigator.js?ver=1.0

js polsa.gov.pl collected 2026-10-02 05:36:28 UTC 3,216 bytes, 75 lines download raw bytes

1document.addEventListener('DOMContentLoaded', () => {
2  const allLinks = document.querySelectorAll('#fresponsive a'); // Wszystkie linki w menu
3  const mainMenuLinks = Array.from(document.querySelectorAll('#fresponsive > li > a')); // Tylko główne linki
4
5  // Set tabindex dla wszystkich linków
6  allLinks.forEach(link => link.setAttribute('tabindex', '0'));
7
8  // Ustaw aria-expanded na true dla wszystkich linków, które mają podmenu
9  document.querySelectorAll('.menu-item-has-children > a').forEach(link => {
10    link.setAttribute('aria-expanded', 'true'); // Menu jest zawsze rozwinięte
11    link.removeAttribute('aria-haspopup'); // Usuń atrybut aria-haspopup, żeby nie sugerować, że jest rozwijany
12  });
13
14  // Obsługa nawigacji za pomocą klawiatury
15  document.addEventListener('keydown', (e) => {
16    const focusedElement = document.activeElement;
17    if (!focusedElement || !focusedElement.closest('#fresponsive')) return; // Wyjście, jeśli nie ma skupionego elementu w menu
18
19    const currentItem = focusedElement.closest('li');
20    const parentMenu = currentItem.closest('ul');
21    const allItems = Array.from(parentMenu.querySelectorAll('a'));
22    const currentIndex = allItems.indexOf(focusedElement);
23
24    // Obsługuje nawigację za pomocą strzałek w górę i w dół w obrębie podmenu
25    const handleArrowNavigation = (direction) => {
26      if (direction === 'down') {
27        if (currentItem.classList.contains('menu-item-has-children')) {
28          const firstDropdownLink = currentItem.querySelector('.dropdown-menu a');
29          if (firstDropdownLink) firstDropdownLink.focus();
30        } else {
31          if (allItems[currentIndex + 1]) allItems[currentIndex + 1].focus();
32        }
33      } else if (direction === 'up') {
34        if (allItems[currentIndex - 1]) {
35          allItems[currentIndex - 1].focus();
36        } else {
37          const parentItem = currentItem.closest('.dropdown-menu') && currentItem.closest('.dropdown-menu').closest('li.menu-item-has-children');
38          if (parentItem) parentItem.querySelector('a').focus();
39        }
40      }
41    };
42
43    // Obsługuje nawigację strzałkami w lewo i w prawo po głównych elementach menu
44    const handleArrowMainNavigation = (direction) => {
45      const currentMainIndex = mainMenuLinks.indexOf(focusedElement);
46      const nextMainItem = direction === 'right'
47        ? mainMenuLinks[(currentMainIndex + 1) % mainMenuLinks.length]
48        : mainMenuLinks[(currentMainIndex - 1 + mainMenuLinks.length) % mainMenuLinks.length];
49      if (nextMainItem) nextMainItem.focus();
50    };
51
52    switch (e.key) {
53      case 'ArrowRight': 
54        handleArrowMainNavigation('right');
55        break;
56
57      case 'ArrowLeft':
58        handleArrowMainNavigation('left');
59        break;
60
61      case 'ArrowDown': 
62        handleArrowNavigation('down');
63        break;
64
65      case 'ArrowUp': 
66        handleArrowNavigation('up');
67        break;
68
69      case 'Escape':
70        const parentItem = currentItem.closest('.dropdown-menu') && currentItem.closest('.dropdown-menu').closest('li.menu-item-has-children');
71        if (parentItem) parentItem.querySelector('a').focus(); // Escape do linku rodzica
72        break;
73    }
74  });
75});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.