1(function($, v, undefined) { 2 "use strict"; 3 4 var menu_toggle = document.getElementById( 'vamtam-fallback-main-menu-toggle' ); 5 var original_toggle = document.querySelector( '#main-menu > .mega-menu-wrap > .mega-menu-toggle' ); 6 var main_menu = document.querySelector( '#main-menu' ); 7 8 // main menu custom toggle 9 10 if ( menu_toggle ) { 11 menu_toggle.addEventListener( 'click', function( e ) { 12 e.preventDefault(); 13 14 requestAnimationFrame( function() { 15 var is_open = ( original_toggle || menu_toggle ).classList.contains( 'mega-menu-open' ); 16 17 menu_toggle.classList.toggle( 'mega-menu-open', ! is_open ); 18 19 ( original_toggle || main_menu ).classList.toggle( 'mega-menu-open', ! is_open ); 20 21 var topBar = document.getElementById( 'mobile-top-bar-above' ); 22 if ( topBar ) { 23 topBar.style.display = is_open ? 'block' : 'none'; 24 } 25 } ); 26 } ); 27 } 28 29 30 // add left/right classes to submenus depending on resolution 31 32 var allSubMenus = $( '#main-menu .sub-menu' ); 33 34 if ( allSubMenus.length ) { 35 var invertPositionCallback = window.VAMTAM.debounce( function() { 36 requestAnimationFrame( function() { 37 var winWidth = window.innerWidth; 38 39 allSubMenus.show().removeClass( 'invert-position' ).each( function() { 40 if ( $( this ).offset().left + $( this ).width() > winWidth - 50 ) { 41 $( this ).addClass( 'invert-position' ); 42 } 43 } ); 44 45 allSubMenus.css( 'display', '' ); 46 } ); 47 }, 100 ); 48 49 invertPositionCallback(); 50 window.addEventListener( 'resize', invertPositionCallback, false ); 51 } 52 53 // open submenus on click, only on mobile, when Max Mega Menu plugin is disabled 54 if ( main_menu && main_menu.classList.contains('vamtam-basic-menu') ) { 55 var allSubMenusResponsive = $(main_menu).find('.sub-menu'); 56 var allMenusResponsive = $(main_menu).find('.menu-item > a'); 57 58 allMenusResponsive.on( 'click', function( event ) { 59 if (!main_menu.classList.contains('mega-menu-open')) { 60 return; 61 } 62 63 var menuItem = this.parentElement; 64 65 if ( this.classList.contains( 'menu-item-on' ) || ! menuItem.classList.contains( 'menu-item-has-children' ) ) { 66 return; 67 } 68 69 event.preventDefault(); 70 71 var submenu = $( menuItem ).find( '.sub-menu' ); 72 73 allSubMenusResponsive.attr( 'style', '' ); 74 submenu.attr( 'style', 'display: block !important;' ); 75 allMenusResponsive.not( this ).removeClass( 'menu-item-on' ); 76 this.classList.add( 'menu-item-on' ); 77 }); 78 } 79 80 // adds .current-menu-item classes 81 82 var hashes = [ 83 // ['top', $('<div></div>'), $('#top')] 84 ]; 85 86 $('#main-menu').find('.mega-menu, .menu').find('.maybe-current-menu-item, .current-menu-item').each(function() { 87 var link = $('> a', this); 88 89 if(link.prop('href').indexOf('#') > -1) { 90 var link_hash = link.prop('href').split('#')[1]; 91 92 if('#'+link_hash !== window.location.hash) { 93 $(this).removeClass('mega-current-menu-item current-menu-item'); 94 } 95 96 hashes.push([link_hash, $(this), $('#'+link_hash)]); 97 } 98 }); 99 100 if ( hashes.length ) { 101 var winHeight = 0; 102 var documentHeight = 0; 103 104 var prev_upmost_data = null; 105 106 v.addScrollHandler( { 107 init: function() {}, 108 add_current_menu_item: function( hash ) { 109 // there may be more than one links with the same hash, 110 // so we need to loop over all of the hashes 111 112 for ( var i = 0; i < hashes.length; i++ ) { 113 if ( hashes[i][0] === hash ) { 114 hashes[i][1][0].classList.add( 'current-menu-item' ); 115 } 116 } 117 }, 118 measure: function( cpos ) { 119 winHeight = window.innerHeight; 120 documentHeight = document.body.offsetHeight; 121 122 this.upmost = Infinity; 123 this.upmost_data = null; 124 125 for ( var i = 0; i < hashes.length; i++ ) { 126 var el = hashes[i][2]; 127 128 if ( el.length ) { 129 var top = el.offset().top + 10; 130 131 if ( 132 top > cpos && 133 top < this.upmost && 134 ( 135 top < cpos + winHeight / 2 || 136 ( top < cpos + winHeight && cpos + winHeight === documentHeight ) 137 ) 138 ) { 139 this.upmost_data = hashes[i]; 140 this.upmost = top; 141 } 142 } 143 } 144 }, 145 mutate: function( cpos ) { 146 for ( var i = 0; i < hashes.length; i++ ) { 147 if ( hashes[i][2].length ) { 148 hashes[i][1][0].classList.remove( 'current-menu-item' ); 149 hashes[i][1][0].childNodes[0].blur(); 150 } 151 } 152 153 if ( this.upmost_data ) { 154 this.add_current_menu_item( this.upmost_data[0] ); 155 156 // attempt to push a state to the history if the current hash is different from the previous one 157 if ( 'history' in window && ( prev_upmost_data !== null ? prev_upmost_data[0] : '' ) !== this.upmost_data[0] ) { 158 window.history.pushState( 159 this.upmost_data[0], 160 $( '> a', this.upmost_data[1] ).text(), 161 ( cpos !== 0 ? '#' + this.upmost_data[0] : location.href.replace( location.hash, '' ) ) 162 ); 163 164 prev_upmost_data = $.extend({}, this.upmost_data); 165 } 166 } else if ( this.upmost_data === null && prev_upmost_data !== null ) { 167 this.add_current_menu_item( prev_upmost_data[0] ); 168 } 169 } 170 } ); 171 } 172 173})( jQuery, window.VAMTAM );
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.