1/** 2 * navigation.js 3 * 4 * Handles toggling the navigation menu for small screens. 5 */ 6( function () { 7 var container, button, menu, links, i, len; 8 9 container = document.getElementById( 'site-navigation' ); 10 if ( ! container ) { 11 return; 12 } 13 14 button = container.getElementsByClassName( 'menu-toggle' )[0]; 15 if ( 'undefined' === typeof button ) { 16 return; 17 } 18 19 menu = container.getElementsByTagName( 'ul' )[0]; 20 21 // Hide menu toggle button if menu is empty and return early. 22 if ( 'undefined' === typeof menu ) { 23 button.style.display = 'none'; 24 return; 25 } 26 27 if ( - 1 === menu.className.indexOf( 'nav-menu' ) ) { 28 menu.className += ' nav-menu'; 29 } 30 31 button.onclick = function () { 32 if ( - 1 !== container.className.indexOf( 'main-small-navigation' ) ) { 33 container.className = container.className.replace( 'main-small-navigation', 'main-navigation' ); 34 } else { 35 container.className = container.className.replace( 'main-navigation', 'main-small-navigation' ); 36 } 37 }; 38 39 // Get all the link elements within the menu. 40 links = menu.getElementsByTagName( 'a' ); 41 42 // Each time a menu link is focused or blurred, toggle focus. 43 for ( i = 0, len = links.length; i < len; i++ ) { 44 links[i].addEventListener( 'focus', toggleFocus, true ); 45 links[i].addEventListener( 'blur', toggleFocus, true ); 46 } 47 48 /** 49 * Sets or removes .focus class on an element. 50 */ 51 function toggleFocus() { 52 var self = this; 53 54 // Move up through the ancestors of the current link until we hit .nav-menu. 55 while ( -1 === self.className.indexOf( 'nav-menu' ) ) { 56 // On li elements toggle the class .focus. 57 if ( 'li' === self.tagName.toLowerCase() ) { 58 if ( -1 !== self.className.indexOf( 'focus' ) ) { 59 self.className = self.className.replace( ' focus', '' ); 60 } else { 61 self.className += ' focus'; 62 } 63 } 64 65 self = self.parentElement; 66 } 67 } 68} )(); 69 70// Show Submenu on click on touch enabled deviced 71( function () { 72 var container; 73 container = document.getElementById( 'site-navigation' ); 74 75 /** 76 * Toggles `focus` class to allow submenu access on tablets. 77 */ 78 ( function ( container ) { 79 var touchStartFn, i, 80 parentLink = container.querySelectorAll( '.menu-item-has-children > a, .page_item_has_children > a' ); 81 82 if ( ( 'ontouchstart' in window ) && ( window.matchMedia( "( min-width: 768px ) " ).matches ) ) { 83 touchStartFn = function ( e ) { 84 var menuItem = this.parentNode, i; 85 86 if ( ! menuItem.classList.contains( 'focus' ) ) { 87 e.preventDefault(); 88 for ( i = 0; i < menuItem.parentNode.children.length; ++ i ) { 89 if ( menuItem === menuItem.parentNode.children[i] ) { 90 continue; 91 } 92 menuItem.parentNode.children[i].classList.remove( 'focus' ); 93 } 94 menuItem.classList.add( 'focus' ); 95 } else { 96 menuItem.classList.remove( 'focus' ); 97 } 98 }; 99 100 for ( i = 0; i < parentLink.length; ++ i ) { 101 parentLink[i].addEventListener( 'touchstart', touchStartFn, false ); 102 } 103 } 104 }( container ) ); 105} )(); 106 107/** 108 * Fix: Menu out of view port 109 */ 110( function () { 111 112 var subMenu; 113 114 jQuery( '.main-navigation ul li.menu-item-has-children a, .main-navigation ul li.page_item_has_children a' ).on( { 115 116 'mouseover touchstart' : function () { 117 118 function isElementInViewport( subMenu ) { 119 120 if ( 'function' === typeof jQuery && subMenu instanceof jQuery ) { 121 subMenu = subMenu[0]; 122 } 123 124 // In case browser doesn't support getBoundingClientRect function. 125 if ( 'function' === typeof subMenu.getBoundingClientRect ) { 126 127 var rect = subMenu.getBoundingClientRect(); 128 129 if ( rect.right + 2 > ( window.innerWidth || document.documentElement.clientWidth ) ) { 130 return 'spacious-menu--left'; // menu goes out of viewport from right. 131 } else if ( rect.left < 0 ) { 132 return 'spacious-menu--right'; // menu goes out of viewport from left. 133 } else { 134 return false; 135 } 136 } 137 } 138 139 subMenu = jQuery( this ).next( '.sub-menu, .children' ); 140 141 // If menu item has submenu 142 if ( subMenu.length > 0 ) { 143 144 var viewportClass = isElementInViewport( subMenu ); 145 146 if ( false !== viewportClass ) { 147 subMenu.addClass( viewportClass ); 148 } 149 } 150 151 } 152 153 } ); 154 155} )(); 156 157/** 158 * Keep menu items on one line. 159 */ 160( 161 function () { 162 163 jQuery( document ).ready( function () { 164 // Get required elements. 165 var mainWrapper = document.querySelector( '#header-text-nav-container .inner-wrap' ), 166 branding = document.getElementById( 'header-left-section' ), 167 headerAction = document.querySelector( '.header-action' ), 168 navigation = document.getElementById( 'site-navigation' ), 169 mainWidth = mainWrapper ? mainWrapper.offsetWidth : 0, 170 brandWidth = branding ? branding.offsetWidth : 0, 171 navWidth = navigation ? navigation.offsetWidth : 0, 172 headerActionWidth = headerAction ? headerAction.offsetWidth: 0, 173 isExtra = ( brandWidth + navWidth + headerActionWidth ) > mainWidth, 174 more = navigation ? navigation.getElementsByClassName( 'tg-menu-extras-wrap' )[0] : '', 175 headerDisplayTypeFour = document.getElementsByClassName( 'spacious-header-display-four' )[0]; 176 177 // Check for header style 4. 178 if ( headerDisplayTypeFour ) { 179 isExtra = ( navWidth + headerActionWidth ) >= mainWidth; 180 } 181 182 // Return if no excess menu items. 183 if ( ! navigation.classList.contains( 'tg-extra-menus' ) ) { 184 return; 185 } 186 187 function Dimension( el ) { 188 var elWidth; 189 if ( document.all ) {// IE. 190 elWidth = el.currentStyle.width + parseInt( el.currentStyle.marginLeft, 10 ) + parseInt( el.currentStyle.marginRight, 10 ) + parseInt( el.currentStyle.paddingLeft, 10 ) + parseInt( el.currentStyle.paddingRight, 10 ); 191 } else { 192 elWidth = parseInt( document.defaultView.getComputedStyle( el, '' ).getPropertyValue( 'width' ) ) + parseInt( document.defaultView.getComputedStyle( el, '' ).getPropertyValue( 'margin-left' ) ) + parseInt( document.defaultView.getComputedStyle( el, '' ).getPropertyValue( 'margin-right' ) ); 193 } 194 195 return elWidth; 196 } 197 198 // If menu excesses. 199 if ( ! isExtra ) { 200 more.parentNode.removeChild( more ); 201 } else { 202 var widthToBe, buttons, buttonWidth, moreWidth; 203 204 widthToBe = mainWidth - headerActionWidth; 205 206 if ( ! headerDisplayTypeFour ) { 207 widthToBe = widthToBe - brandWidth; 208 } 209 210 buttons = navigation.getElementsByClassName( 'tg-header-button-wrap' )[0]; 211 buttonWidth = buttons ? Dimension( buttons ) : 0; 212 moreWidth = more ? Dimension( more ) : 0; 213 newNavWidth = widthToBe - ( buttonWidth + moreWidth ); 214 215 navigation.style.visibility = 'none'; 216 navigation.style.width = newNavWidth + 'px'; 217 218 // Returns first children of a node. 219 function getChildNodes( node ) { 220 var children = []; 221 222 for ( var child in node.childNodes ) { 223 if ( typeof node !== 'undefined' ) { 224 if ( 1 === node.childNodes[child].nodeType ) {
225 children.push( node.childNodes[child] ); 226 } 227 } 228 } 229 230 return children; 231 } 232 233 var navUl = navigation.getElementsByClassName( 'nav-menu' )[0], 234 navLi = getChildNodes( navUl ); // Get lis. 235 236 function offset( el ) { 237 var rect = el.getBoundingClientRect(), 238 scrollLeft = window.pageXOffset || document.documentElement.scrollLeft, 239 scrollTop = window.pageYOffset || document.documentElement.scrollTop; 240 241 return { top : rect.top + scrollTop, left : rect.left + scrollLeft } 242 } 243 244 var extraLi = []; 245 246 for ( var liCount = 0; liCount < navLi.length; liCount ++ ) { 247 var initialPos, li, posTop; 248 249 li = navLi[liCount]; 250 posTop = offset( li ).top; 251 252 if ( 0 === liCount ) { 253 initialPos = posTop; 254 } 255 256 if ( posTop > initialPos ) { 257 if ( ! li.classList.contains( 'header-action' ) && ! li.classList.contains( 'tg-menu-extras-wrap' ) && ! li.classList.contains( 'tg-header-button-wrap' ) ) { 258 extraLi.push( li ); 259 } 260 } 261 } 262 263 var newNavWidth = newNavWidth + ( buttonWidth + moreWidth ), 264 extraWrap = document.getElementById( 'tg-menu-extras' ); 265 266 if ( ! headerDisplayTypeFour ) { 267 newNavWidth = newNavWidth - 30; 268 } 269 270 navigation.style.width = newNavWidth + 'px'; 271 272 if ( null !== extraWrap ) { 273 extraLi.forEach( function ( item, index, arr ) { 274 extraWrap.appendChild( item ); 275 } ); 276 } 277 278 } 279 } ); 280 281 }() 282);
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.