function moreButton($nav) { var lisInRow = 0; var langNavChildren = $("nav.mainMenu ul.languageNav>li", $nav); var hasLangNav = $(langNavChildren).length; var menuItemsNav = $('nav.mainMenu>ul.menuItemsNav', $nav); var menuItemsNavChildren = $('nav.mainMenu>ul.menuItemsNav>li:not(".moreButton, .moreButtonMeasure")', $nav); var menuItemsNavChildrenWidth = 0; var langNavWidth = 0; var moreButtonMeasureContainerWidth = 0; var navMenuWidth = parseInt($('nav.mainMenu', $nav).outerWidth(), 10); var navMenuWidthAfterCalc; var topRowWidth = 0; var lisInRowArr = []; var moreVerbiage='More'; menuItemsNavChildren.each(function(index) { menuItemsNavChildrenWidth += parseInt($(this).outerWidth(true), 10) + 1; // + 1 pixel to counteract some browsers' subpixel calculation }); if ( hasLangNav > 0 ) { langNavChildren.each(function(index) { langNavWidth += parseInt($(this).outerWidth(true), 10); }); } if ((menuItemsNavChildrenWidth + langNavWidth) > $('nav.mainMenu', $nav).outerWidth()) { menuItemsNavChildren.each(function() { lisInRow++; }); menuItemsNav .append($('
  • ') .append('
    '+moreVerbiage+'
    ') ); moreButtonMeasureContainerWidth = $(".moreButtonContent").outerWidth(true); menuItemsNavChildren.slice(0,lisInRow).each(function(i) { topRowWidth += parseInt($(this).outerWidth(true), 10); lisInRowArr.push(topRowWidth); }); navMenuWidthAfterCalc = navMenuWidth - langNavWidth - moreButtonMeasureContainerWidth; for (var i = lisInRowArr.length; i > 0 ; i--) { if ( lisInRowArr[i] < navMenuWidthAfterCalc ) { break; } if ( lisInRowArr[i] > navMenuWidthAfterCalc ) { lisInRow--; } } menuItemsNav.find('.moreButton') .append($('