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) {