~xdavidwu/xdavidwu.link

a6ee16f25f997aeb9c3aa169b06d62217e468132 — xdavidwu 3 years ago a037875
greedy nav: remove timeout

bad ux imo
2 files changed, 2 insertions(+), 15 deletions(-)

M assets/js/_greedy-navigation.js
M assets/js/main.min.js
M assets/js/_greedy-navigation.js => assets/js/_greedy-navigation.js +1 -14
@@ 11,7 11,6 @@ const $hlinks = document.querySelector("nav.greedy-nav .hidden-links");

var numOfItems = 0;
var totalSpace = 0;
var closingTime = 1000;
var breakWidths = [];

// Get initial state


@@ 21,7 20,7 @@ for (i of $vlinks.children) {
  breakWidths.push(totalSpace);
}

var availableSpace, numOfVisibleItems, requiredSpace, timer;
var availableSpace, numOfVisibleItems, requiredSpace;

function check() {



@@ 55,18 54,6 @@ window.addEventListener('resize', () => {

$btn.addEventListener('click', () => {
  $hlinks.classList.toggle('hidden');
  clearTimeout(timer);
});

$hlinks.addEventListener('mouseleave', () => {
  // Mouse has left, start the timer
  timer = setTimeout(function() {
    $hlinks.classList.add('hidden');
  }, closingTime);
});
$hlinks.addEventListener('mouseenter', () => {
  // Mouse is back, cancel the timer
  clearTimeout(timer);
});

check();

M assets/js/main.min.js => assets/js/main.min.js +1 -1
@@ 1,1 1,1 @@
!function(e){var t={};function n(i){if(t[i])return t[i].exports;var o=t[i]={i:i,l:!1,exports:{}};return e[i].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(i,o,function(t){return e[t]}.bind(null,o));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){n(1),document.addEventListener("DOMContentLoaded",()=>{document.addEventListener("keyup",e=>{27===e.keyCode&&document.getElementsByClassName("initial-content")[0].classList.contains("is--hidden")&&(document.getElementsByClassName("search-content")[0].classList.toggle("is--visible"),document.getElementsByClassName("initial-content")[0].classList.toggle("is--hidden"))}),document.getElementsByClassName("search__toggle")[0].addEventListener("click",()=>{document.getElementsByClassName("search-content")[0].classList.toggle("is--visible"),document.getElementsByClassName("initial-content")[0].classList.toggle("is--hidden"),setTimeout((function(){document.querySelector(".search-content input").focus()}),400)})})},function(e,t){const n=document.querySelector("nav.greedy-nav .greedy-nav__toggle"),o=document.querySelector("nav.greedy-nav .visible-links"),s=document.querySelector("nav.greedy-nav .hidden-links");var r,d,l,c=0,a=0,u=[];for(i of o.children)a+=i.offsetWidth,c+=1,u.push(a);function f(){r=o.offsetWidth,d=o.children.length,u[d-1]>r?(s.prepend(o.lastChild),d-=1,f()):r>u[d]&&(o.append(s.firstChild),d+=1,f()),n.setAttribute("count",c-d),d===c?n.classList.add("hidden"):n.classList.remove("hidden")}window.addEventListener("resize",()=>{f()}),n.addEventListener("click",()=>{s.classList.toggle("hidden"),clearTimeout(l)}),s.addEventListener("mouseleave",()=>{l=setTimeout((function(){s.classList.add("hidden")}),1e3)}),s.addEventListener("mouseenter",()=>{clearTimeout(l)}),f()}]);
\ No newline at end of file
!function(e){var t={};function n(i){if(t[i])return t[i].exports;var o=t[i]={i:i,l:!1,exports:{}};return e[i].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(i,o,function(t){return e[t]}.bind(null,o));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){n(1),document.addEventListener("DOMContentLoaded",()=>{document.addEventListener("keyup",e=>{27===e.keyCode&&document.getElementsByClassName("initial-content")[0].classList.contains("is--hidden")&&(document.getElementsByClassName("search-content")[0].classList.toggle("is--visible"),document.getElementsByClassName("initial-content")[0].classList.toggle("is--hidden"))}),document.getElementsByClassName("search__toggle")[0].addEventListener("click",()=>{document.getElementsByClassName("search-content")[0].classList.toggle("is--visible"),document.getElementsByClassName("initial-content")[0].classList.toggle("is--hidden"),setTimeout((function(){document.querySelector(".search-content input").focus()}),400)})})},function(e,t){const n=document.querySelector("nav.greedy-nav .greedy-nav__toggle"),o=document.querySelector("nav.greedy-nav .visible-links"),s=document.querySelector("nav.greedy-nav .hidden-links");var r,l,d=0,c=0,a=[];for(i of o.children)c+=i.offsetWidth,d+=1,a.push(c);function u(){r=o.offsetWidth,l=o.children.length,a[l-1]>r?(s.prepend(o.lastChild),l-=1,u()):r>a[l]&&(o.append(s.firstChild),l+=1,u()),n.setAttribute("count",d-l),l===d?n.classList.add("hidden"):n.classList.remove("hidden")}window.addEventListener("resize",()=>{u()}),n.addEventListener("click",()=>{s.classList.toggle("hidden")}),u()}]);
\ No newline at end of file