PageSourceSearch

https://jurix.nl/wp-content/themes/base-wp/js/navigation.js?ver=20151215

js jurix.nl collected 2026-10-02 04:25:20 UTC 3,784 bytes, 99 lines download raw bytes

1/**
2 * File navigation.js.
3 *
4 * Handles toggling the navigation menu for small screens and enables TAB key
5 * navigation support for dropdown menus.
6 */
7(function () {
8    var container, button, menu, links, subMenus, i, len;
9    container = document.getElementById('site-navigation');
10    if (!container) {
11        return;
12    }
13    button = container.getElementsByTagName('button')[0];
14    if ('undefined' === typeof button) {
15        return;
16    }
17    menu = container.getElementsByTagName('ul')[0];
18    // Hide menu toggle button if menu is empty and return early.
19    if ('undefined' === typeof menu) {
20        button.style.display = 'none';
21        return;
22    }
23    menu.setAttribute('aria-expanded', 'false');
24    if (-1 === menu.className.indexOf('nav-menu')) {
25        menu.className += ' nav-menu';
26    }
27    button.onclick = function () {
28        if (-1 !== container.className.indexOf('toggled')) {
29            container.className = container.className.replace(' toggled', '');
30            button.setAttribute('aria-expanded', 'false');
31            menu.setAttribute('aria-expanded', 'false');
32        }
33        else {
34            container.className += ' toggled';
35            button.setAttribute('aria-expanded', 'true');
36            menu.setAttribute('aria-expanded', 'true');
37        }
38    };
39    // Get all the link elements within the menu.
40    links = menu.getElementsByTagName('a');
41    subMenus = menu.getElementsByTagName('ul');
42    // Set menu items with submenus to aria-haspopup="true".
43    for (i = 0, len = subMenus.length; i < len; i++) {
44        subMenus[i].parentNode.setAttribute('aria-haspopup', 'true');
45    }
46    // Each time a menu link is focused or blurred, toggle focus.
47    for (i = 0, len = links.length; i < len; i++) {
48        links[i].addEventListener('focus', toggleFocus, true);
49        links[i].addEventListener('blur', toggleFocus, true);
50    }
51    /**
52     * Sets or removes .focus class on an element.
53     */
54    function toggleFocus() {
55        var self = this;
56        // Move up through the ancestors of the current link until we hit .nav-menu.
57        while (-1 === self.className.indexOf('nav-menu')) {
58            // On li elements toggle the class .focus.
59            if ('li' === self.tagName.toLowerCase()) {
60                if (-1 !== self.className.indexOf('focus')) {
61                    self.className = self.className.replace(' focus', '');
62                }
63                else {
64                    self.className += ' focus';
65                }
66            }
67            self = self.parentElement;
68        }
69    }
70    /**
71     * Toggles `focus` class to allow submenu access on tablets.
72     */
73    (function (container) {
74        var touchStartFn, i
75            , parentLink = container.querySelectorAll('.menu-item-has-children > a, .page_item_has_children > a');
76        if ('ontouchstart' in window) {
77            touchStartFn = function (e) {
78                var menuItem = this.parentNode
79                    , i;
80                if (!menuItem.classList.contains('focus')) {
81                    e.preventDefault();
82                    for (i = 0; i < menuItem.parentNode.children.length; ++i) {
83                        if (menuItem === menuItem.parentNode.children[i]) {
84                            continue;
85                        }
86                        menuItem.parentNode.children[i].classList.remove('focus');
87                    }
88                    menuItem.classList.add('focus');
89                }
90                else {
91                    menuItem.classList.remove('focus');
92                }
93            };
94            for (i = 0; i < parentLink.length; ++i) {
95                parentLink[i].addEventListener('touchstart', touchStartFn, false);
96            }
97        }
98    }(container));
99})();

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.