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
- 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)
- 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)

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
Copyright (c) 2015 Luke Jackson
*/
$(document).ready(function() {
$(function() {
var $btn = $("nav.greedy-nav .greedy-nav__toggle");
var $vlinks = $("nav.greedy-nav .visible-links");
var $hlinks = $("nav.greedy-nav .hidden-links");
var numOfItems = 0;
var totalSpace = 0;
var closingTime = 1000;
var breakWidths = [];
// Get initial state
@ -20,38 +22,31 @@ $(document).ready(function() {
breakWidths.push(totalSpace);
});
var availableSpace, numOfVisibleItems, requiredSpace;
var availableSpace, numOfVisibleItems, requiredSpace, timer;
function check() {
// Get instant state
availableSpace = $vlinks.width() - $btn.width();
availableSpace = $vlinks.width() - 10;
numOfVisibleItems = $vlinks.children().length;
requiredSpace = breakWidths[numOfVisibleItems - 1];
// There is not enough space
// There is not enought space
if (requiredSpace > availableSpace) {
$vlinks
.children()
.last()
.prependTo($hlinks);
$vlinks.children().last().prependTo($hlinks);
numOfVisibleItems -= 1;
check();
// There is more than enough space
} else if (availableSpace > breakWidths[numOfVisibleItems]) {
$hlinks
.children()
.first()
.appendTo($vlinks);
$hlinks.children().first().appendTo($vlinks);
numOfVisibleItems += 1;
check();
}
// Update the button accordingly
$btn.attr("count", numOfItems - numOfVisibleItems);
if (numOfVisibleItems === numOfItems) {
$btn.addClass("hidden");
} else {
$btn.removeClass("hidden");
}
$btn.addClass('hidden');
} else $btn.removeClass('hidden');
}
// Window listeners
@ -59,10 +54,21 @@ $(document).ready(function() {
check();
});
$btn.on("click", function() {
$hlinks.toggleClass("hidden");
$(this).toggleClass("close");
$btn.on('click', function() {
$hlinks.toggleClass('hidden');
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();
});
});

View file

@ -5,7 +5,7 @@ permalink: /docs/history/
excerpt: "Change log of enhancements and bug fixes made to the theme."
sidebar:
nav: docs
last_modified_at: 2020-06-02T22:31:55-04:00
last_modified_at: 2020-06-06T10:30:36-04:00
toc: false
---
@ -13,6 +13,7 @@ toc: false
### 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)
- 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)