nested menus: ensure title width is wide enough to accommodate children; fixes #54

This commit is contained in:
Dean Attali 2016-05-01 01:42:06 -07:00
parent df981db1d1
commit 9e017d9fc0

View File

@ -35,6 +35,33 @@ var main = {
});
});
// Ensure nested navbar menus are not longer than the menu header
var menus = $(".navlinks-container");
if (menus.length > 0) {
var navbar = $("#main-navbar ul");
var fakeMenuHtml = "<li class='fake-menu' style='display:none;'><a></a></li>";
navbar.append(fakeMenuHtml);
var fakeMenu = $(".fake-menu");
$.each(menus, function(i) {
var parent = $(menus[i]).find(".navlinks-parent");
var children = $(menus[i]).find(".navlinks-children a");
var words = [];
$.each(children, function(idx, el) { words = words.concat($(el).text().trim().split(/\s+/)); });
var maxwidth = 0;
$.each(words, function(id, word) {
fakeMenu.html("<a>" + word + "</a>");
var width = fakeMenu.width();
if (width > maxwidth) {
maxwidth = width;
}
});
$(menus[i]).css('min-width', maxwidth + 'px')
});
fakeMenu.remove();
}
// show the big header image
main.initImgs();
},
@ -108,4 +135,4 @@ var main = {
// 2fc73a3a967e97599c9763d05e564189
document.addEventListener('DOMContentLoaded', main.init);
document.addEventListener('DOMContentLoaded', main.init);