Update GreedyNav.js

This commit is contained in:
Michael Rose 2020-06-06 10:30:54 -04:00
parent 3ab6ba0b1f
commit 7ec8e90c76
4 changed files with 32 additions and 24 deletions

View file

@ -2,6 +2,7 @@
### Enhancements ### Enhancements
- Update GreedyNav.js
- Replace `<section id="custom-comments"></section>` in `comments.html` include and add `custom_scripts.html` include for loading custom comment provider JavaScript in the footer. [#2549](https://github.com/mmistakes/minimal-mistakes/issues/2549) - Replace `<section id="custom-comments"></section>` in `comments.html` include and add `custom_scripts.html` include for loading custom comment provider JavaScript in the footer. [#2549](https://github.com/mmistakes/minimal-mistakes/issues/2549)
- Move page date Liquid to include. [#2544](https://github.com/mmistakes/minimal-mistakes/pull/2544) - Move page date Liquid to include. [#2544](https://github.com/mmistakes/minimal-mistakes/pull/2544)
- Strip trailing whitespace in seo_description. [#2542](https://github.com/mmistakes/minimal-mistakes/pull/2542) - Strip trailing whitespace in seo_description. [#2542](https://github.com/mmistakes/minimal-mistakes/pull/2542)

File diff suppressed because one or more lines are too long

View file

@ -1,16 +1,18 @@
/* /*
GreedyNav.js - https://github.com/lukejacksonn/GreedyNav GreedyNav.js - http://lukejacksonn.com/actuate
Licensed under the MIT license - http://opensource.org/licenses/MIT Licensed under the MIT license - http://opensource.org/licenses/MIT
Copyright (c) 2015 Luke Jackson Copyright (c) 2015 Luke Jackson
*/ */
$(document).ready(function() { $(function() {
var $btn = $("nav.greedy-nav .greedy-nav__toggle"); var $btn = $("nav.greedy-nav .greedy-nav__toggle");
var $vlinks = $("nav.greedy-nav .visible-links"); var $vlinks = $("nav.greedy-nav .visible-links");
var $hlinks = $("nav.greedy-nav .hidden-links"); var $hlinks = $("nav.greedy-nav .hidden-links");
var numOfItems = 0; var numOfItems = 0;
var totalSpace = 0; var totalSpace = 0;
var closingTime = 1000;
var breakWidths = []; var breakWidths = [];
// Get initial state // Get initial state
@ -20,38 +22,31 @@ $(document).ready(function() {
breakWidths.push(totalSpace); breakWidths.push(totalSpace);
}); });
var availableSpace, numOfVisibleItems, requiredSpace; var availableSpace, numOfVisibleItems, requiredSpace, timer;
function check() { function check() {
// Get instant state // Get instant state
availableSpace = $vlinks.width() - $btn.width(); availableSpace = $vlinks.width() - 10;
numOfVisibleItems = $vlinks.children().length; numOfVisibleItems = $vlinks.children().length;
requiredSpace = breakWidths[numOfVisibleItems - 1]; requiredSpace = breakWidths[numOfVisibleItems - 1];
// There is not enough space // There is not enought space
if (requiredSpace > availableSpace) { if (requiredSpace > availableSpace) {
$vlinks $vlinks.children().last().prependTo($hlinks);
.children()
.last()
.prependTo($hlinks);
numOfVisibleItems -= 1; numOfVisibleItems -= 1;
check(); check();
// There is more than enough space // There is more than enough space
} else if (availableSpace > breakWidths[numOfVisibleItems]) { } else if (availableSpace > breakWidths[numOfVisibleItems]) {
$hlinks $hlinks.children().first().appendTo($vlinks);
.children()
.first()
.appendTo($vlinks);
numOfVisibleItems += 1; numOfVisibleItems += 1;
check(); check();
} }
// Update the button accordingly // Update the button accordingly
$btn.attr("count", numOfItems - numOfVisibleItems); $btn.attr("count", numOfItems - numOfVisibleItems);
if (numOfVisibleItems === numOfItems) { if (numOfVisibleItems === numOfItems) {
$btn.addClass("hidden"); $btn.addClass('hidden');
} else { } else $btn.removeClass('hidden');
$btn.removeClass("hidden");
}
} }
// Window listeners // Window listeners
@ -59,10 +54,21 @@ $(document).ready(function() {
check(); check();
}); });
$btn.on("click", function() { $btn.on('click', function() {
$hlinks.toggleClass("hidden"); $hlinks.toggleClass('hidden');
$(this).toggleClass("close"); clearTimeout(timer);
}); });
$hlinks.on('mouseleave', function() {
// Mouse has left, start the timer
timer = setTimeout(function() {
$hlinks.addClass('hidden');
}, closingTime);
}).on('mouseenter', function() {
// Mouse is back, cancel the timer
clearTimeout(timer);
})
check(); check();
});
});

View file

@ -5,7 +5,7 @@ permalink: /docs/history/
excerpt: "Change log of enhancements and bug fixes made to the theme." excerpt: "Change log of enhancements and bug fixes made to the theme."
sidebar: sidebar:
nav: docs nav: docs
last_modified_at: 2020-06-02T22:31:55-04:00 last_modified_at: 2020-06-06T10:30:36-04:00
toc: false toc: false
--- ---
@ -13,6 +13,7 @@ toc: false
### Enhancements ### Enhancements
- Update GreedyNav.js
- Replace `<section id="custom-comments"></section>` in `comments.html` include and add `custom_scripts.html` include for loading custom comment provider JavaScript in the footer. [#2549](https://github.com/mmistakes/minimal-mistakes/issues/2549) - Replace `<section id="custom-comments"></section>` in `comments.html` include and add `custom_scripts.html` include for loading custom comment provider JavaScript in the footer. [#2549](https://github.com/mmistakes/minimal-mistakes/issues/2549)
- Move page date Liquid to include. [#2544](https://github.com/mmistakes/minimal-mistakes/pull/2544) - Move page date Liquid to include. [#2544](https://github.com/mmistakes/minimal-mistakes/pull/2544)
- Strip trailing whitespace in `seo_description`. [#2542](https://github.com/mmistakes/minimal-mistakes/pull/2542) - Strip trailing whitespace in `seo_description`. [#2542](https://github.com/mmistakes/minimal-mistakes/pull/2542)