PageSourceSearch

https://newyorktheater.me/wp-content/themes/gridwp/assets/js/navigation.js

js newyorktheater.me collected 2026-10-02 04:04:00 UTC 8,947 bytes, 208 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 gridwp_secondary_container, gridwp_secondary_button, gridwp_secondary_menu, gridwp_secondary_links, gridwp_secondary_i, gridwp_secondary_len;
9
10    gridwp_secondary_container = document.getElementById( 'gridwp-secondary-navigation' );
11    if ( ! gridwp_secondary_container ) {
12        return;
13    }
14
15    gridwp_secondary_button = gridwp_secondary_container.getElementsByTagName( 'button' )[0];
16    if ( 'undefined' === typeof gridwp_secondary_button ) {
17        return;
18    }
19
20    gridwp_secondary_menu = gridwp_secondary_container.getElementsByTagName( 'ul' )[0];
21
22    // Hide menu toggle button if menu is empty and return early.
23    if ( 'undefined' === typeof gridwp_secondary_menu ) {
24        gridwp_secondary_button.style.display = 'none';
25        return;
26    }
27
28    gridwp_secondary_menu.setAttribute( 'aria-expanded', 'false' );
29    if ( -1 === gridwp_secondary_menu.className.indexOf( 'nav-menu' ) ) {
30        gridwp_secondary_menu.className += ' nav-menu';
31    }
32
33    gridwp_secondary_button.onclick = function() {
34        if ( -1 !== gridwp_secondary_container.className.indexOf( 'gridwp-toggled' ) ) {
35            gridwp_secondary_container.className = gridwp_secondary_container.className.replace( ' gridwp-toggled', '' );
36            gridwp_secondary_button.setAttribute( 'aria-expanded', 'false' );
37            gridwp_secondary_menu.setAttribute( 'aria-expanded', 'false' );
38        } else {
39            gridwp_secondary_container.className += ' gridwp-toggled';
40            gridwp_secondary_button.setAttribute( 'aria-expanded', 'true' );
41            gridwp_secondary_menu.setAttribute( 'aria-expanded', 'true' );
42        }
43    };
44
45    // Get all the link elements within the menu.
46    gridwp_secondary_links    = gridwp_secondary_menu.getElementsByTagName( 'a' );
47
48    // Each time a menu link is focused or blurred, toggle focus.
49    for ( gridwp_secondary_i = 0, gridwp_secondary_len = gridwp_secondary_links.length; gridwp_secondary_i < gridwp_secondary_len; gridwp_secondary_i++ ) {
50        gridwp_secondary_links[gridwp_secondary_i].addEventListener( 'focus', gridwp_secondary_toggleFocus, true );
51        gridwp_secondary_links[gridwp_secondary_i].addEventListener( 'blur', gridwp_secondary_toggleFocus, true );
52    }
53
54    /**
55     * Sets or removes .focus class on an element.
56     */
57    function gridwp_secondary_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( 'gridwp-focus' ) ) {
66                    self.className = self.className.replace( ' gridwp-focus', '' );
67                } else {
68                    self.className += ' gridwp-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( gridwp_secondary_container ) {
80        var touchStartFn, gridwp_secondary_i,
81            parentLink = gridwp_secondary_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, gridwp_secondary_i;
86
87                if ( ! menuItem.classList.contains( 'gridwp-focus' ) ) {
88                    e.preventDefault();
89                    for ( gridwp_secondary_i = 0; gridwp_secondary_i < menuItem.parentNode.children.length; ++gridwp_secondary_i ) {
90                        if ( menuItem === menuItem.parentNode.children[gridwp_secondary_i] ) {
91                            continue;
92                        }
93                        menuItem.parentNode.children[gridwp_secondary_i].classList.remove( 'gridwp-focus' );
94                    }
95                    menuItem.classList.add( 'gridwp-focus' );
96                } else {
97                    menuItem.classList.remove( 'gridwp-focus' );
98                }
99            };
100
101            for ( gridwp_secondary_i = 0; gridwp_secondary_i < parentLink.length; ++gridwp_secondary_i ) {
102                parentLink[gridwp_secondary_i].addEventListener( 'touchstart', touchStartFn, false );
103            }
104        }
105    }( gridwp_secondary_container ) );
106} )();
107
108
109( function() {
110    var gridwp_primary_container, gridwp_primary_button, gridwp_primary_menu, gridwp_primary_links, gridwp_primary_i, gridwp_primary_len;
111
112    gridwp_primary_container = document.getElementById( 'gridwp-primary-navigation' );
113    if ( ! gridwp_primary_container ) {
114        return;
115    }
116
117    gridwp_primary_button = gridwp_primary_container.getElementsByTagName( 'button' )[0];
118    if ( 'undefined' === typeof gridwp_primary_button ) {
119        return;
120    }
121
122    gridwp_primary_menu = gridwp_primary_container.getElementsByTagName( 'ul' )[0];
123
124    // Hide menu toggle button if menu is empty and return early.
125    if ( 'undefined' === typeof gridwp_primary_menu ) {
126        gridwp_primary_button.style.display = 'none';
127        return;
128    }
129
130    gridwp_primary_menu.setAttribute( 'aria-expanded', 'false' );
131    if ( -1 === gridwp_primary_menu.className.indexOf( 'nav-menu' ) ) {
132        gridwp_primary_menu.className += ' nav-menu';
133    }
134
135    gridwp_primary_button.onclick = function() {
136        if ( -1 !== gridwp_primary_container.className.indexOf( 'gridwp-toggled' ) ) {
137            gridwp_primary_container.className = gridwp_primary_container.className.replace( ' gridwp-toggled', '' );
138            gridwp_primary_button.setAttribute( 'aria-expanded', 'false' );
139            gridwp_primary_menu.setAttribute( 'aria-expanded', 'false' );
140        } else {
141            gridwp_primary_container.className += ' gridwp-toggled';
142            gridwp_primary_button.setAttribute( 'aria-expanded', 'true' );
143            gridwp_primary_menu.setAttribute( 'aria-expanded', 'true' );
144        }
145    };
146
147    // Get all the link elements within the menu.
148    gridwp_primary_links    = gridwp_primary_menu.getElementsByTagName( 'a' );
149
150    // Each time a menu link is focused or blurred, toggle focus.
151    for ( gridwp_primary_i = 0, gridwp_primary_len = gridwp_primary_links.length; gridwp_primary_i < gridwp_primary_len; gridwp_primary_i++ ) {
152        gridwp_primary_links[gridwp_primary_i].addEventListener( 'focus', gridwp_primary_toggleFocus, true );
153        gridwp_primary_links[gridwp_primary_i].addEventListener( 'blur', gridwp_primary_toggleFocus, true );
154    }
155
156    /**
157     * Sets or removes .focus class on an element.
158     */
159    function gridwp_primary_toggleFocus() {
160        var self = this;
161
162        // Move up through the ancestors of the current link until we hit .nav-menu.
163        while ( -1 === self.className.indexOf( 'nav-menu' ) ) {
164
165            // On li elements toggle the class .focus.
166            if ( 'li' === self.tagName.toLowerCase() ) {
167                if ( -1 !== self.className.indexOf( 'gridwp-focus' ) ) {
168                    self.className = self.className.replace( ' gridwp-focus', '' );
169                } else {
170                    self.className += ' gridwp-focus';
171                }
172            }
173
174            self = self.parentElement;
175        }
176    }
177
178    /**
179     * Toggles `focus` class to allow submenu access on tablets.
180     */
181    ( function( gridwp_primary_container ) {
182        var touchStartFn, gridwp_primary_i,
183            parentLink = gridwp_primary_container.querySelectorAll( '.menu-item-has-children > a, .page_item_has_children > a' );
184
185        if ( 'ontouchstart' in window ) {
186            touchStartFn = function( e ) {
187                var menuItem = this.parentNode, gridwp_primary_i;
188
189                if ( ! menuItem.classList.contains( 'gridwp-focus' ) ) {
190                    e.preventDefault();
191                    for ( gridwp_primary_i = 0; gridwp_primary_i < menuItem.parentNode.children.length; ++gridwp_primary_i ) {
192                        if ( menuItem === menuItem.parentNode.children[gridwp_primary_i] ) {
193                            continue;
194                        }
195                        menuItem.parentNode.children[gridwp_primary_i].classList.remove( 'gridwp-focus' );
196                    }
197                    menuItem.classList.add( 'gridwp-focus' );
198                } else {
199                    menuItem.classList.remove( 'gridwp-focus' );
200                }
201            };
202
203            for ( gridwp_primary_i = 0; gridwp_primary_i < parentLink.length; ++gridwp_primary_i ) {
204                parentLink[gridwp_primary_i].addEventListener( 'touchstart', touchStartFn, false );
205            }
206        }
207    }( gridwp_primary_container ) );
208} )();

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.