Skip to content

Commit b9e4c76

Browse files
Fix site-nav problem in jquery.greedy-navigation.js
1 parent 71780d5 commit b9e4c76

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

assets/js/main.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/js/plugins/jquery.greedy-navigation.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,27 @@ function updateNav() {
1919
// The visible list is overflowing the nav
2020
if($vlinks.width() > availableSpace) {
2121

22-
// Record the width of the list
23-
breaks.push($vlinks.width());
22+
while ($vlinks.width() > availableSpace && $vlinks.children('*:not(.masthead__menu-item--lg)').length > 0) {
2423

25-
// Move item to the hidden list
26-
$vlinks.children('*:not(.masthead__menu-item--lg)').last().prependTo($hlinks);
24+
// Record the width of the list
25+
breaks.push($vlinks.width());
2726

28-
// Show the dropdown btn
29-
if($btn.hasClass('hidden')) {
30-
$btn.removeClass('hidden');
27+
// Move item to the hidden list
28+
$vlinks.children('*:not(.masthead__menu-item--lg)').last().prependTo($hlinks);
29+
30+
availableSpace = $btn.hasClass('hidden') ? $nav.width() : $nav.width() - $btn.width() - 30;
31+
32+
// Show the dropdown btn
33+
if($btn.hasClass('hidden')) {
34+
$btn.removeClass('hidden');
35+
}
3136
}
3237

33-
// The visible list is not overflowing
38+
// The visible list is not overflowing
3439
} else {
3540

3641
// There is space for another item in the nav
37-
if(availableSpace > breaks[breaks.length-1]) {
38-
42+
while(breaks.length > 0 && availableSpace > breaks[breaks.length-1]) {
3943
// Move the item to the visible list
4044
$hlinks.children().first().appendTo($vlinks);
4145
breaks.pop();
@@ -44,23 +48,22 @@ function updateNav() {
4448
// Hide the dropdown btn if hidden list is empty
4549
if(breaks.length < 1) {
4650
$btn.addClass('hidden');
51+
$btn.removeClass('close');
4752
$hlinks.addClass('hidden');
4853
}
4954
}
5055

5156
// Keep counter updated
5257
$btn.attr("count", breaks.length);
5358

54-
// Recur if the visible list is still overflowing the nav
55-
if($vlinks.width() > availableSpace) {
56-
updateNav();
57-
}
58-
5959
}
6060

6161
// Window listeners
6262

63-
$(window).resize(function() {
63+
$(window).on('resize', function() {
64+
updateNav();
65+
});
66+
screen.orientation.addEventListener("change", function(){
6467
updateNav();
6568
});
6669

0 commit comments

Comments
 (0)