PageSourceSearch

https://submarinebooks.com/wp-content/themes/clean-gallery/assets/js/navigation.js

js submarinebooks.com collected 2026-10-02 13:19:34 UTC 4,961 bytes, 106 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 clean_gallery_primary_container, clean_gallery_primary_button, clean_gallery_primary_menu, clean_gallery_primary_links, clean_gallery_primary_i, clean_gallery_primary_len;
9
10    clean_gallery_primary_container = document.getElementById( 'clean-gallery-primary-navigation' );
11    if ( ! clean_gallery_primary_container ) {
12        return;
13    }
14
15    clean_gallery_primary_button = clean_gallery_primary_container.getElementsByTagName( 'button' )[0];
16    if ( 'undefined' === typeof clean_gallery_primary_button ) {
17        return;
18    }
19
20    clean_gallery_primary_menu = clean_gallery_primary_container.getElementsByTagName( 'ul' )[0];
21
22    // Hide menu toggle button if menu is empty and return early.
23    if ( 'undefined' === typeof clean_gallery_primary_menu ) {
24        clean_gallery_primary_button.style.display = 'none';
25        return;
26    }
27
28    clean_gallery_primary_menu.setAttribute( 'aria-expanded', 'false' );
29    if ( -1 === clean_gallery_primary_menu.className.indexOf( 'nav-menu' ) ) {
30        clean_gallery_primary_menu.className += ' nav-menu';
31    }
32
33    clean_gallery_primary_button.onclick = function() {
34        if ( -1 !== clean_gallery_primary_container.className.indexOf( 'clean-gallery-toggled' ) ) {
35            clean_gallery_primary_container.className = clean_gallery_primary_container.className.replace( ' clean-gallery-toggled', '' );
36            clean_gallery_primary_button.setAttribute( 'aria-expanded', 'false' );
37            clean_gallery_primary_menu.setAttribute( 'aria-expanded', 'false' );
38        } else {
39            clean_gallery_primary_container.className += ' clean-gallery-toggled';
40            clean_gallery_primary_button.setAttribute( 'aria-expanded', 'true' );
41            clean_gallery_primary_menu.setAttribute( 'aria-expanded', 'true' );
42        }
43    };
44
45    // Get all the link elements within the menu.
46    clean_gallery_primary_links    = clean_gallery_primary_menu.getElementsByTagName( 'a' );
47
48    // Each time a menu link is focused or blurred, toggle focus.
49    for ( clean_gallery_primary_i = 0, clean_gallery_primary_len = clean_gallery_primary_links.length; clean_gallery_primary_i < clean_gallery_primary_len; clean_gallery_primary_i++ ) {
50        clean_gallery_primary_links[clean_gallery_primary_i].addEventListener( 'focus', clean_gallery_primary_toggleFocus, true );
51        clean_gallery_primary_links[clean_gallery_primary_i].addEventListener( 'blur', clean_gallery_primary_toggleFocus, true );
52    }
53
54    /**
55     * Sets or removes .focus class on an element.
56     */
57    function clean_gallery_primary_toggleFocus() {
58        var self = this;
59
60        // Move up through the ancestors of the current link until we hit .nav-menu.
61        while ( -1 === self.className.indexOf( 'nav-menu' ) ) {
62
63            // On li elements toggle the class .focus.
64            if ( 'li' === self.tagName.toLowerCase() ) {
65                if ( -1 !== self.className.indexOf( 'clean-gallery-focus' ) ) {
66                    self.className = self.className.replace( ' clean-gallery-focus', '' );
67                } else {
68                    self.className += ' clean-gallery-focus';
69                }
70            }
71
72            self = self.parentElement;
73        }
74    }
75
76    /**
77     * Toggles `focus` class to allow submenu access on tablets.
78     */
79    ( function( clean_gallery_primary_container ) {
80        var touchStartFn, clean_gallery_primary_i,
81            parentLink = clean_gallery_primary_container.querySelectorAll( '.menu-item-has-children > a, .page_item_has_children > a' );
82
83        if ( 'ontouchstart' in window ) {
84            touchStartFn = function( e ) {
85                var menuItem = this.parentNode, clean_gallery_primary_i;
86
87                if ( ! menuItem.classList.contains( 'clean-gallery-focus' ) ) {
88                    e.preventDefault();
89                    for ( clean_gallery_primary_i = 0; clean_gallery_primary_i < menuItem.parentNode.children.length; ++clean_gallery_primary_i ) {
90                        if ( menuItem === menuItem.parentNode.children[clean_gallery_primary_i] ) {
91                            continue;
92                        }
93                        menuItem.parentNode.children[clean_gallery_primary_i].classList.remove( 'clean-gallery-focus' );
94                    }
95                    menuItem.classList.add( 'clean-gallery-focus' );
96                } else {
97                    menuItem.classList.remove( 'clean-gallery-focus' );
98                }
99            };
100
101            for ( clean_gallery_primary_i = 0; clean_gallery_primary_i < parentLink.length; ++clean_gallery_primary_i ) {
102                parentLink[clean_gallery_primary_i].addEventListener( 'touchstart', touchStartFn, false );
103            }
104        }
105    }( clean_gallery_primary_container ) );
106} )();

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.