1( function() { 2 'use strict'; 3 4 if ( 'querySelector' in document && 'addEventListener' in window ) { 5 /** 6 * Navigation search. 7 * 8 * @param {Object} e The event. 9 * @param {Object} item The clicked item. 10 */ 11 var toggleSearch = function( e, item ) { 12 e.preventDefault(); 13 14 if ( ! item ) { 15 item = this; 16 } 17 18 var forms = document.querySelectorAll( '.navigation-search' ), 19 toggles = document.querySelectorAll( '.search-item' ), 20 focusableEls = document.querySelectorAll( 'a[href], area[href], input:not([disabled]):not(.navigation-search), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), [tabindex="0"]' ), 21 nav = ''; 22 23 if ( item.closest( '.mobile-menu-control-wrapper' ) ) { 24 nav = document.getElementById( 'site-navigation' ); 25 } 26 27 for ( var i = 0; i < forms.length; i++ ) { 28 if ( forms[ i ].classList.contains( 'nav-search-active' ) ) { 29 if ( forms[ i ].closest( '#sticky-placeholder' ) ) { 30 continue; 31 } 32 33 forms[ i ].classList.remove( 'nav-search-active' ); 34 35 var activeSearch = document.querySelector( '.has-active-search' ); 36 37 if ( activeSearch ) { 38 activeSearch.classList.remove( 'has-active-search' ); 39 } 40 41 for ( var t = 0; t < toggles.length; t++ ) { 42 toggles[ t ].classList.remove( 'close-search' ); 43 toggles[ t ].classList.remove( 'active' ); 44 toggles[ t ].querySelector( 'a' ).setAttribute( 'aria-label', generatepressNavSearch.open ); 45 46 // Allow tabindex on items again. 47 for ( var f = 0; f < focusableEls.length; f++ ) { 48 if ( ! focusableEls[ f ].closest( '.navigation-search' ) && ! focusableEls[ f ].closest( '.search-item' ) ) { 49 focusableEls[ f ].removeAttribute( 'tabindex' ); 50 } 51 } 52 } 53 54 document.activeElement.blur(); 55 } else { 56 if ( forms[ i ].closest( '#sticky-placeholder' ) ) { 57 continue; 58 } 59 60 var openedMobileMenu = forms[ i ].closest( '.toggled' ); 61 62 if ( openedMobileMenu ) { 63 // Close the mobile menu. 64 openedMobileMenu.querySelector( 'button.menu-toggle' ).click(); 65 } 66 67 if ( nav ) { 68 nav.classList.add( 'has-active-search' ); 69 } 70 71 forms[ i ].classList.add( 'nav-search-active' ); 72 73 var container = this.closest( 'nav' ); 74 75 if ( container ) { 76 if ( container.classList.contains( 'mobile-menu-control-wrapper' ) ) { 77 container = nav; 78 } 79 80 var searchField = container.querySelector( '.search-field' ); 81 82 if ( searchField ) { 83 searchField.focus(); 84 } 85 } 86 87 for ( t = 0; t < toggles.length; t++ ) { 88 toggles[ t ].classList.add( 'active' ); 89 toggles[ t ].querySelector( 'a' ).setAttribute( 'aria-label', generatepressNavSearch.close ); 90 91 // Trap tabindex within the search element 92 for ( f = 0; f < focusableEls.length; f++ ) { 93 if ( ! focusableEls[ f ].closest( '.navigation-search' ) && ! focusableEls[ f ].closest( '.search-item' ) ) { 94 focusableEls[ f ].setAttribute( 'tabindex', '-1' ); 95 } 96 } 97 98 toggles[ t ].classList.add( 'close-search' ); 99 } 100 } 101 } 102 }; 103 104 if ( document.body.classList.contains( 'nav-search-enabled' ) ) { 105 var searchItems = document.querySelectorAll( '.search-item' ); 106 107 for ( var i = 0; i < searchItems.length; i++ ) { 108 searchItems[ i ].addEventListener( 'click', toggleSearch, false ); 109 } 110 111 // Close navigation search on escape key 112 document.addEventListener( 'keydown', function( e ) { 113 if ( document.querySelector( '.navigation-search.nav-search-active' ) ) { 114 if ( 'Escape' === e.key ) { 115 var activeSearchItems = document.querySelectorAll( '.search-item.active' ); 116 117 for ( var activeSearchItem = 0; activeSearchItem < activeSearchItems.length; activeSearchItem++ ) { 118 toggleSearch( e, activeSearchItems[ activeSearchItem ] ); 119 break; 120 } 121 } 122 } 123 }, false ); 124 } 125 } 126}() );
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.