Browse Source

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

master
Dean Attali 5 years ago
parent
commit
9e017d9fc0
1 changed files with 28 additions and 1 deletions
  1. +28
    -1
      js/main.js

+ 28
- 1
js/main.js 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);

Loading…
Cancel
Save