Skip to main content
'));usingOverflowMenu = true;dbpTooltipMenu = new cbpTooltipMenu(document.getElementById('cbp-tm-menu'));}}//make sure the LIs fit into the navfunction checkNavForOverflow() {iteration_counter++;//console.log("starting checkNavForOverflow #" + iteration_counter);var $nav = $(nav).find("ul").first();var $logo = $(".logo").first();var $rightnav = $(".cbp-tm-nav-right").first();//console.log($logo);var logo_width = $logo.outerWidth(true);var rightnav_width = $rightnav.outerWidth(true);//console.log("logo_width: " + logo_width);var $overflowMenu = $("#mobile-menu-icon-responsive>ul.dropdown").first();//console.log($overflowMenu);var overflow_menu_width = $("#mobile-menu-icon-responsive").outerWidth(true);//console.log("overflow_menu_width: " + overflow_menu_width);var nav_width = $nav.width();//console.log("nav_width: " + nav_width);var available_space = nav_width - logo_width - rightnav_width;//console.log("available_space: " + available_space);var total_length = 0;var $allMenuItems = $nav.children();$allMenuItems.each(function() {var $this = $(this), this_current_width = $this.outerWidth(true);//console.log("this_current_width: " + this_current_width);$this.data("default-width", this_current_width);total_length += this_current_width;});//console.log("total_length: " + total_length);var $overflowMenuItems = $overflowMenu.children('li:not(.skip-responsive, #mobile-menu-icon-responsive)');var number_of_overflow_items = $overflowMenuItems.length;//console.log("number_of_overflow_items: " + number_of_overflow_items);var first_overflow_item_width = $overflowMenuItems.first().data("default-width");//console.log("first_overflow_item_width: " + first_overflow_item_width);//need a dropdownif (total_length > available_space) {//add an element to dropdown//console.log("should add item");putItemInOverflowMenu();} else if (number_of_overflow_items > 1 && total_length + first_overflow_item_width <= available_space) {//remove an element from dropdown//console.log("should remove item");takeItemOutOfOverflowMenu();} else if (number_of_overflow_items === 1 && total_length + first_overflow_item_width - overflow_menu_width <= available_space) {//move last out and remove dropdown//console.log("should remove item and remove menu");emptyAndRemoveOverflowMenu();} else {//console.log("should take no action");}//console.log("ending checkNavForOverflow #" + iteration_counter);iteration_counter--;}//move LIs to the extra dropdown from main navfunction putItemInOverflowMenu() {var $nav = $(nav).find("ul").first();var $menuItems = $nav.children('li:not(.skip-responsive, #mobile-menu-icon-responsive)');if ($menuItems.length) {if (!usingOverflowMenu) {addOverflowMenu();}var $menuItem = $menuItems.last().detach();if ($menuItem.hasClass('cbp-tm-submenu')) {$menuItem.addClass('cbp-tm-submenu-removed');$menuItem.removeClass('cbp-tm-submenu');}$nav.find("#mobile-menu-icon-responsive>ul.dropdown").first().prepend($menuItem);checkNavForOverflow();$("#mobile-menu-icon-responsive .cbp-tm-submenu li").on('keydown', function(event) {if(event.keyCode == 27) {$('li.cbp-tm-show-below').removeClass('cbp-tm-show');$('li.cbp-tm-show-below').attr('aria-expanded', 'false');$('li.cbp-tm-show-below').removeClass('cbp-tm-show-below');$(this.parentElement.parentElement).focus();}});}}//move LIs to the extra dropdown from main navfunction takeItemOutOfOverflowMenu() {var $overflowMenu = $("#mobile-menu-icon-responsive>ul.dropdown");var $overflowMenuItems = $overflowMenu.children('li:not(.skip-responsive, #mobile-menu-icon-responsive)');if ($overflowMenuItems.length) {var $menuItem = $overflowMenuItems.first().detach();if ($menuItem.hasClass('cbp-tm-submenu-removed')) {$menuItem.removeClass('cbp-tm-submenu-removed');$menuItem.addClass('cbp-tm-submenu');}var $nav = $(nav).find("ul").first();var $menuItems = $nav.children('li:not(.skip-responsive, #mobile-menu-icon-responsive)');$menuItems.last().after($menuItem);checkNavForOverflow();}}//move all LIs from extra dropdown back to the navfunction emptyAndRemoveOverflowMenu() {var $overflowMenu = $("#mobile-menu-icon-responsive>ul.dropdown");var $overflowMenuItems = $overflowMenu.children('li:not(.skip-responsive, #mobile-menu-icon-responsive)');$overflowMenuItems.each(function() {//console.log"returning element...");var $menuItem = $(this).detach();if ($menuItem.hasClass('cbp-tm-submenu-removed')) {$menuItem.removeClass('cbp-tm-submenu-removed');$menuItem.addClass('cbp-tm-submenu');}var $nav = $(nav).find("ul").first();var $menuItems = $nav.children('li:not(.skip-responsive, #mobile-menu-icon-responsive)');$menuItems.last().after($menuItem);});$("#mobile-menu-icon-responsive").remove();usingOverflowMenu = false;}//check if to use mobile nav or notfunction detectMobileWidth() {if (window.matchMedia('(min-width: ' + breakPoint + 'px)').matches) {checkNavForOverflow();} else {emptyAndRemoveOverflowMenu();}}};$('.nav').each(function() {new ResponsiveNav($(this), 768);dbpTooltipMenu = new cbpTooltipMenu(document.getElementById('cbp-tm-menu'));});$('#mobile-menu-icon-responsive').on('touch', function(event) {$(this).toggleClass('cbp-tm-show');$(this).toggleClass('cbp-tm-show-below');});if ( $(window).width() <= 766 ) {$("ul.cbp-tm-submenu.dropdown li:nth-child(n+2) a").each(function (i, v) {$(v).contents().wrap('');});}});
Previous Previous
Next Next
Previous Previous
Next Next
Related Articles