1(function ($) { 2 3 "use strict"; 4 5 var search_modal = $('#search-modal'), 6 search_field = search_modal.find('.search-field'); 7 8 $('#search-toggle, #close-search-modal').on('click', function (e) { 9 10 e.preventDefault(); 11 12 search_modal.toggleClass('opened'); 13 14 if (search_modal.hasClass('opened')) { 15 search_field.focus(); 16 } else { 17 search_field.blur(); 18 } 19 20 }); 21 22 var masthead, menuToggle, siteNavigation, siteHeaderMenu; 23 24 function initMainNavigation(container) { 25 // Add dropdown toggle that displays child menu items. 26 var dropdownToggle = $('<button />', { 27 'class': 'dropdown-toggle', 28 'aria-expanded': false, 29 'html': '<span class="lnr lnr-chevron-down"></span><span class="screen-reader-text">Expand dropdown</span>' 30 }); 31 32 container.find('.menu-item-has-children > a').after(dropdownToggle); 33 34 // Toggle buttons and submenu items with active children menu items. 35 container.find('.current-menu-ancestor > button').addClass('toggled-on'); 36 container.find('.current-menu-ancestor > .children, .current-menu-ancestor > .sub-menu').addClass('toggled-on'); 37 38 // Add menu items with submenus to aria-haspopup="true". 39 container.find('.menu-item-has-children').attr('aria-haspopup', 'true'); 40 41 container.on('click', '.dropdown-toggle', function (e) { 42 var _this = $(this); 43 44 e.preventDefault(); 45 _this.toggleClass('toggled-on'); 46 _this.next('.children, .sub-menu').toggleClass('toggled-on'); 47 48 _this.attr('aria-expanded', _this.attr('aria-expanded') === 'false' ? 'true' : 'false'); 49 }); 50 } 51 52 initMainNavigation($('.main-navigation')); 53 54 masthead = $('#masthead'); 55 menuToggle = masthead.find('#menu-toggle'); 56 57 // Enable menuToggle. 58 (function () { 59 // Return early if menuToggle is missing. 60 if (!menuToggle.length) { 61 return; 62 } 63 64 // Add an initial values for the attribute. 65 menuToggle.add(siteNavigation).attr('aria-expanded', 'false'); 66 67 menuToggle.on('click', function () { 68 $(this).add(siteHeaderMenu).toggleClass('toggled-on'); 69 $(this).add(siteNavigation).attr('aria-expanded', $(this).add(siteNavigation).attr('aria-expanded') === 'false' ? 'true' : 'false'); 70 }); 71 })(); 72 73 function subMenuPosition() { 74 $('.sub-menu').each(function () { 75 $(this).removeClass('toleft'); 76 if (($(this).parent().offset().left + $(this).parent().width() - $(window).width() + 230) > 0) { 77 $(this).addClass('toleft'); 78 } 79 }); 80 } 81 82 function prependElement(container, element) { 83 if (container.firstChild) { 84 return container.insertBefore(element, container.firstChild); 85 } else { 86 return container.appendChild(element); 87 } 88 } 89 90 function showButton(element) { 91 // classList.remove is not supported in IE11 92 element.className = element.className.replace('is-empty', ''); 93 } 94 95 function hideButton(element) { 96 // classList.add is not supported in IE11 97 if (!element.classList.contains('is-empty')) { 98 element.className += ' is-empty'; 99 } 100 } 101 102 function getAvailableSpace(button, container) { 103 return container.offsetWidth - button.offsetWidth - 85; 104 } 105 106 function isOverflowingNavivation(list, button, container) { 107 return list.offsetWidth > getAvailableSpace(button, container); 108 } 109 110 function addItemToVisibleList(toggleButton, container, visibleList, hiddenList) { 111 if (getAvailableSpace(toggleButton, container) > breaks[breaks.length - 1]) { 112 // Move the item to the visible list 113 visibleList.appendChild(hiddenList.firstChild); 114 breaks.pop(); 115 addItemToVisibleList(toggleButton, container, visibleList, hiddenList); 116 } 117 } 118 119 120 var navContainer = document.querySelector('.main-navigation-wrapper'); 121 var breaks = []; 122 123 if (navContainer) { 124 function updateNavigationMenu(container) { 125 126 if (!container.parentNode.querySelector('.primary-menu[id]')) { 127 return; 128 } 129 130 // Adds the necessary UI to operate the menu. 131 var visibleList = container.parentNode.querySelector('.primary-menu[id]'); 132 var hiddenList = visibleList.parentNode.nextElementSibling.querySelector('.hidden-links'); 133 var toggleButton = visibleList.parentNode.nextElementSibling.querySelector('.primary-menu-more-toggle'); 134 135 if ((window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth) <= 991) { 136 while (breaks.length > 0) { 137 visibleList.appendChild(hiddenList.firstChild); 138 breaks.pop(); 139 addItemToVisibleList(toggleButton, container, visibleList, hiddenList); 140 } 141 return; 142 } 143 144 if (isOverflowingNavivation(visibleList, toggleButton, container)) { 145 // Record the width of the list 146 breaks.push(visibleList.offsetWidth); 147 // Move last item to the hidden list 148 prependElement(hiddenList, !visibleList.lastChild || null === visibleList.lastChild ? visibleList.previousElementSibling : visibleList.lastChild); 149 // Show the toggle button 150 showButton(toggleButton); 151 152 } else { 153 154 // There is space for another item in the nav 155 addItemToVisibleList(toggleButton, container, visibleList, hiddenList); 156 157 // Hide the dropdown btn if hidden list is empty 158 if (breaks.length < 2) { 159 hideButton(toggleButton); 160 } 161 162 } 163 164 // Recur if the visible list is still overflowing the nav 165 if (isOverflowingNavivation(visibleList, toggleButton, container)) { 166 updateNavigationMenu(container); 167 } 168 169 } 170 171 document.addEventListener('DOMContentLoaded', function () { 172 173 updateNavigationMenu(navContainer); 174 175 // Also, run our priority+ function on selective refresh in the customizer 176 var hasSelectiveRefresh = ( 177 'undefined' !== typeof wp && 178 wp.customize && 179 wp.customize.selectiveRefresh && 180 wp.customize.navMenusPreview.NavMenuInstancePartial 181 ); 182 183 if (hasSelectiveRefresh) { 184 // Re-run our priority+ function on Nav Menu partial refreshes 185 wp.customize.selectiveRefresh.bind('partial-content-rendered', function (placement) { 186 187 var isNewNavMenu = ( 188 placement && 189 placement.partial.id.includes('nav_menu_instance') && 190 'null' !== placement.container[0].parentNode && 191 placement.container[0].parentNode.classList.contains('main-navigation') 192 ); 193 194 if (isNewNavMenu) { 195 updateNavigationMenu(placement.container[0].parentNode); 196 } 197 }); 198 } 199 }); 200 201 window.addEventListener('load', function () { 202 updateNavigationMenu(navContainer); 203 subMenuPosition(); 204 }); 205 206 var timeout; 207 208 window.addEventListener('resize', function () { 209 function checkMenu() { 210 if (timeout) { 211 clearTimeout(timeout); 212 timeout = undefined; 213 } 214 215 timeout = setTimeout( 216 function () { 217 updateNavigationMenu(navContainer); 218 subMenuPosition(); 219 }, 220 100 221 ); 222 } 223 224 checkMenu(); 225 subMenuPosition(); 226 }); 227 228 updateNavigationMenu(navContainer); 229 subMenuPosition(); 230 } 231 232})(jQuery);
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.