From d5f4d913dbc3cc15c10b7a67f44235f37e281458 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Jakse?= Date: Thu, 3 Sep 2020 23:04:59 +0200 Subject: [PATCH] fix dblckick on tile in Chromium --- public/trivabble.js | 48 +++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/public/trivabble.js b/public/trivabble.js index 273bab8..e21f105 100644 --- a/public/trivabble.js +++ b/public/trivabble.js @@ -275,7 +275,27 @@ return null; } + function cleanupDragTile() { + mouseUp(document, dragTileEnd, true); + mouseMove(document, dragTileMove, true); + + tileInitMouseCoords = null; + tileInitCoords = null; + tileInitDest = null; + tileDest = null; + movingTile = null; + boardBCR = null; + bagBCR = null; + rackBCR = null; + moveCMD = null; + } + function dragTileEnd() { + if (movingTile.parentNode === tileInitDest) { + cleanupDragTile(); + return; + } + movingTile.style.left = ""; movingTile.style.top = ""; movingTile.style.width = ""; @@ -293,9 +313,6 @@ delete currentTilePlayed[moveCMD.indexFrom]; } - mouseUp(document, dragTileEnd, true); - mouseMove(document, dragTileMove, true); - if (tileDest === bag) { moveCMD.to = "bag"; moveCMD.indexTo = -1; @@ -349,18 +366,18 @@ } } - tileInitMouseCoords = null; - tileInitCoords = null; - tileInitDest = null; - tileDest = null; - movingTile = null; - boardBCR = null; - bagBCR = null; - rackBCR = null; - moveCMD = null; + cleanupDragTile(); } function dragTileMove(e) { + if (movingTile.parentNode !== document.body) { + movingTile.style.left = tileInitCoords.left + window.scrollX + "px"; + movingTile.style.top = tileInitCoords.top + window.scrollY + "px"; + movingTile.style.width = tileInitCoords.width + "px"; + movingTile.style.height = tileInitCoords.height + "px"; + document.body.appendChild(movingTile); + } + let newLeft = (tileInitCoords.left + (e.clientX - tileInitMouseCoords.clientX)); let newTop = (tileInitCoords.top + (e.clientY - tileInitMouseCoords.clientY)); @@ -542,13 +559,6 @@ mouseMove(document, dragTileMove); mouseUp(document, dragTileEnd); - - movingTile.style.left = tileInitCoords.left + window.scrollX + "px"; - movingTile.style.top = tileInitCoords.top + window.scrollY + "px"; - movingTile.style.width = tileInitCoords.width + "px"; - movingTile.style.height = tileInitCoords.height + "px"; - - document.body.appendChild(movingTile); } function setLetter(tile, letter, highlight) { -- 2.30.2