/* * Implements the hamburger menu behaviour * * * @since 4.8 moved from avia.js to own file as some user request to customize this feature */ (function($) { "use strict"; $(function() { $.avia_utilities = $.avia_utilities || {}; if( 'undefined' == typeof $.avia_utilities.isMobile ) { if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) && 'ontouchstart' in document.documentElement ) { $.avia_utilities.isMobile = true; } else { $.avia_utilities.isMobile = false; } } //activates the hamburger mobile menu avia_hamburger_menu(); $(window).trigger( 'resize' ); }); $.avia_utilities = $.avia_utilities || {}; function avia_hamburger_menu() { var header = $('#header'), header_main = $('#main .av-logo-container'), //check if we got a top menu that is above the header menu = $('#avia-menu'), burger_wrap = $('.av-burger-menu-main a'), htmlEL = $('html').eq(0), overlay = $('
'), overlay_scroll = $('
').appendTo(overlay), inner_overlay = $('
').appendTo(overlay_scroll), bgColor = $('
').appendTo(overlay), animating = false, first_level = {}, logo_container = $('.av-logo-container .inner-container'), menu_in_logo_container = logo_container.find('.main_menu'), cloneFirst = htmlEL.is('.html_av-submenu-display-click.html_av-submenu-clone, .html_av-submenu-display-hover.html_av-submenu-clone'), menu_generated = false, cloned_menu_cnt = 0; if( ! htmlEL.hasClass( 'html_av-submenu-hidden' ) ) { htmlEL.addClass( 'html_av-submenu-visible' ); } /** * Check for alternate mobile menu */ var alternate = $('#avia_alternate_menu'); if( alternate.length > 0 ) { menu = alternate; } var set_list_container_height = function() { //necessary for ios since the height is usually not 100% but 100% - menu bar which can be requested by window.innerHeight if($.avia_utilities.isMobile) { overlay_scroll.outerHeight(window.innerHeight); } }, create_list = function( items , append_to ) { if( ! items ) { return; } var list, link, current, subitems, megacolumns, sub_current, sub_current_list, new_li, new_ul; items.each(function() { current = $(this); subitems = current.find(' > .sub-menu > li'); //find sublists of a regular defined menu if( subitems.length == 0 ) { subitems = current.find(' > .children > li'); //find sublists of a fallback menu } megacolumns = current.find( '.avia_mega_div > .sub-menu > li.menu-item' ); // href = '#': we have a custom link that should not link to something - is also in use by megamenu for titles var cur_menu = current.find('>a'); var clone_events = true; if( cur_menu.length ) { if( cur_menu.get(0).hash == '#' || 'undefined' == typeof cur_menu.attr('href') || cur_menu.attr('href') == '#' ) { // eventhandler conflict 'click' by megamenu (returns false) - ignore all handlers if( subitems.length > 0 || megacolumns.length > 0 ) { clone_events = false; } } } link = cur_menu.clone(clone_events).attr('style',''); // megamenus can have '' as url in top menu - allow click event in burger if( 'undefined' == typeof cur_menu.attr('href') ) { link.attr( 'href', '#' ); } new_li = $('
  • ').append( link ); new_li.attr( 'role', 'menuitem' ); // Copy user set classes for menu items - these must not start with menu-item, page-item, page_item (used by default classes) var cls = []; if( 'undefined' != typeof current.attr('class') ) { cls = current.attr('class').split(/\s+/); $.each( cls, function( index, value ){ if( ( value.indexOf('menu-item') != 0 ) && ( value.indexOf('page-item') < 0 ) && ( value.indexOf('page_item') != 0 ) && ( value.indexOf('dropdown_ul') < 0 ) ) { // 'current-menu-item' is also copied !! new_li.addClass( value ); } return true; }); } if( 'undefined' != typeof current.attr('id') && '' != current.attr('id') ) { new_li.addClass(current.attr('id')); } else { // fallback menu has no id -> try to find page id in class $.each( cls, function( index, value ){ if( value.indexOf('page-item-') >= 0 ) { new_li.addClass(value); return false; } }); } append_to.append(new_li); if(subitems.length) { new_ul = $('