nested menus: ensure title width is wide enough to accommodate children; fixes #54
This commit is contained in:
parent
df981db1d1
commit
9e017d9fc0
27
js/main.js
27
js/main.js
@ -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();
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user