From 62f03862d678cb10272b4dae2bd3ab1b6c0974a0 Mon Sep 17 00:00:00 2001 From: themancalledjakob Date: Tue, 10 Oct 2023 13:28:40 +0200 Subject: [PATCH] better click handling --- bin/web/js/audio.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/bin/web/js/audio.js b/bin/web/js/audio.js index 11546bc..94c7687 100644 --- a/bin/web/js/audio.js +++ b/bin/web/js/audio.js @@ -361,12 +361,24 @@ const Audio = function(tp, record) { mappingOptions.max_in = (bb.height - min_y) * y_factor; } }); - fft_Dom.addEventListener('mouseup', (e) => { + const unset = (e) => { setFrequency = false; + }; + const unsetFromOutside = (e) => { + document.removeEventListener('mouseup', unsetFromOutside); + unset(e); + }; + fft_Dom.addEventListener('mouseup', unset); + fft_Dom.addEventListener('mouseleave', (e) => { + if (setFrequency) { + document.addEventListener('mouseup', unsetFromOutside); + } + }); + fft_Dom.addEventListener('mouseenter', (e) => { + if (setFrequency) { + document.removeEventListener('mouseup', unsetFromOutside); + } }); - //fft_Dom.addEventListener('mouseout', (e) => { - //setFrequency = false; - //}); container.after(audioOptions);