From: Raphaƫl Jakse Date: Thu, 3 Sep 2020 21:04:59 +0000 (+0200) Subject: fix dblckick on tile in Chromium X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=d5f4d913dbc3cc15c10b7a67f44235f37e281458;p=trivabble.git fix dblckick on tile in Chromium --- 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) {