fix dblckick on tile in Chromium
authorRaphaël Jakse <raphael.trivabble@jakse.fr>
Thu, 3 Sep 2020 21:04:59 +0000 (23:04 +0200)
committerRaphaël Jakse <raphael.trivabble@jakse.fr>
Thu, 3 Sep 2020 21:04:59 +0000 (23:04 +0200)
public/trivabble.js

index 273bab823cd9df3d954238c1124ff3a5cd8a9c52..e21f1055849cdc635e0be8c7d1293867ed3a6dba 100644 (file)
         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  = "";
             delete currentTilePlayed[moveCMD.indexFrom];
         }
 
-        mouseUp(document,   dragTileEnd,  true);
-        mouseMove(document, dragTileMove, true);
-
         if (tileDest === bag) {
             moveCMD.to = "bag";
             moveCMD.indexTo = -1;
             }
         }
 
-        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));
 
 
         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) {