From df44b9b35793762418005be06cb6a1f3a1aca2e6 Mon Sep 17 00:00:00 2001 From: Braulio Rivas Abad Date: Sat, 10 Aug 2024 16:02:20 -0500 Subject: [PATCH] fix hover, modal dissapears and won't stay as expected --- js/draw/box.js | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/js/draw/box.js b/js/draw/box.js index ae46d8d..01929b7 100644 --- a/js/draw/box.js +++ b/js/draw/box.js @@ -92,29 +92,34 @@ export function buildBox(object) { } export function addHoverModal(box, lines) { - let objectModal = null; + const objectModal = createObjectModal(lines, box.width); + const objectModalWidth = parseInt(objectModal.width); + const boxWidth = parseInt(box.width); + + let showModal = false; + + const clean = () => { + showModal = false; + removeObjectModal(objectModal); + }; box.on("pointerover", () => { - objectModal = createObjectModal(lines, box.width); - const objectModalWidth = parseInt(objectModal.width); - const boxWidth = parseInt(box.width); - const x = parseInt(box.position.x); - const xPosition = (boxWidth - objectModalWidth) / 2 + x; - const y = box.position.y; - - const timeout = setTimeout(() => { + if (showModal) { + return; + } + showModal = true; + setTimeout(() => { + if (!showModal) { + return; + } + const x = parseInt(box.position.x); + const xPosition = (boxWidth - objectModalWidth) / 2 + x; + const y = box.position.y; renderObjectModal(objectModal, xPosition, y); }, 500); - - const clean = () => { - clearTimeout(timeout); - removeObjectModal(objectModal); - objectModal = null; - }; - - box.on("pointerdown", clean); - box.on("pointerout", clean); }); + box.on("pointerdown", clean); + box.on("pointerout", clean); } export function addTitleToBox(title, box) {