This commit is contained in:
InternalLoss 2018-10-01 13:20:23 +00:00 committed by GitHub
parent 2687ddde6c
commit 01f9ad1e3e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,111 +1 @@
/*
GreedyNav.js - https://github.com/lukejacksonn/GreedyNav
Licensed under the MIT license - http://opensource.org/licenses/MIT
Copyright (c) 2015 Luke Jackson
*/
$(document).ready(function(){
var $btn1 = $('nav.greedy-nav button.navsel');
var $btn2 = $('nav.greedy-nav button.langsel');
var $vlinks = $('nav.greedy-nav .visible-links');
var $hlinks1 = $('nav.greedy-nav .hidden-links.links-menu');
var $hlinks2 = $('nav.greedy-nav .hidden-links.lang-menu');
var numOfItems = 0;
var totalSpace = 0;
var closingTime = 1000;
var breakWidths = [];
// Get initial state
$vlinks.children().outerWidth(function(i, w) {
totalSpace += w;
numOfItems += 1;
breakWidths.push(totalSpace);
});
var availableSpace, numOfVisibleItems, requiredSpace, timer1, timer2;
function check() {
// Get instant state
availableSpace = $vlinks.width() - 10;
numOfVisibleItems = $vlinks.children().length;
requiredSpace = breakWidths[numOfVisibleItems - 1];
// There is not enough space
if (requiredSpace > availableSpace) {
$vlinks.children().last().prependTo($hlinks1);
numOfVisibleItems -= 1;
check();
// There is more than enough space
} else if (availableSpace > breakWidths[numOfVisibleItems]) {
$hlinks1.children().first().appendTo($vlinks);
numOfVisibleItems += 1;
check();
}
// Update the button accordingly
$btn1.attr("count", numOfItems - numOfVisibleItems);
if (numOfVisibleItems === numOfItems) {
$btn1.addClass('hidden');
} else {
$btn1.removeClass('hidden');
}
}
// Window listeners
$(window).resize(function() {
check();
});
$btn1.on('click', function() {
if($hlinks1.is(":visible")){
$hlinks1.addClass('hidden');
$(this).removeClass('close');
} else {
$hlinks1.removeClass('hidden');
$(this).addClass('close');
$hlinks2.addClass('hidden');
$btn2.removeClass('close');
clearTimeout(timer2);
}
});
$hlinks1.on('mouseleave', function() {
// Mouse has left, start the timer1
timer1 = setTimeout(function() {
$hlinks1.addClass('hidden');
$btn1.removeClass('close');
}, closingTime);
}).on('mouseenter', function() {
// Mouse is back, cancel the timer1
clearTimeout(timer1);
})
$btn2.on('click', function() {
if($hlinks2.is(":visible")){
$hlinks2.addClass('hidden');
$(this).removeClass('close');
} else {
$hlinks2.removeClass('hidden');
$(this).addClass('close');
$hlinks1.addClass('hidden');
$btn1.removeClass('close');
clearTimeout(timer1);
}
});
$hlinks2.on('mouseleave', function() {
// Mouse has left, start the timer2
timer2 = setTimeout(function() {
$hlinks2.addClass('hidden');
$btn2.removeClass('close');
}, closingTime);
}).on('mouseenter', function() {
// Mouse is back, cancel the timer2
clearTimeout(timer2);
})
check();
});
$(document).ready(function(){var e,n,s,d,i,o=$("nav.greedy-nav button.navsel"),a=$("nav.greedy-nav button.langsel"),l=$("nav.greedy-nav .visible-links"),t=$("nav.greedy-nav .hidden-links.links-menu"),c=$("nav.greedy-nav .hidden-links.lang-menu"),r=0,u=0,v=[];function h(){e=l.width()-10,n=l.children().length,s=v[n-1],e<s?(l.children().last().prependTo(t),n-=1,h()):e>v[n]&&(t.children().first().appendTo(l),n+=1,h()),o.attr("count",r-n),n===r?o.addClass("hidden"):o.removeClass("hidden")}l.children().outerWidth(function(e,n){u+=n,r+=1,v.push(u)}),$(window).resize(function(){h()}),o.on("click",function(){t.is(":visible")?(t.addClass("hidden"),$(this).removeClass("close")):(t.removeClass("hidden"),$(this).addClass("close"),c.addClass("hidden"),a.removeClass("close"),clearTimeout(i))}),t.on("mouseleave",function(){d=setTimeout(function(){t.addClass("hidden"),o.removeClass("close")},1e3)}).on("mouseenter",function(){clearTimeout(d)}),a.on("click",function(){c.is(":visible")?(c.addClass("hidden"),$(this).removeClass("close")):(c.removeClass("hidden"),$(this).addClass("close"),t.addClass("hidden"),o.removeClass("close"),clearTimeout(d))}),c.on("mouseleave",function(){i=setTimeout(function(){c.addClass("hidden"),a.removeClass("close")},1e3)}).on("mouseenter",function(){clearTimeout(i)}),h()});