fix tile unwanted movement, and offset
authorRaphaël Jakse <raphael.jakse@univ-grenoble-alpes.fr>
Thu, 2 Apr 2020 17:09:47 +0000 (19:09 +0200)
committerRaphaël Jakse <raphael.jakse@univ-grenoble-alpes.fr>
Thu, 2 Apr 2020 17:09:47 +0000 (19:09 +0200)
trivabble.js

index bf5d873041abc7028a4e0fc45c05f9e28999c772..2a8d669b0a95435e99e19167327a4e05cb77a2d7 100644 (file)
         var newLeft = (tileInitCoords.left + (e.clientX - tileInitMouseCoords.clientX));
         var newTop  = (tileInitCoords.top  + (e.clientY - tileInitMouseCoords.clientY));
 
-        movingTile.style.left = newLeft  + "px";
-        movingTile.style.top  = newTop + "px";
+        movingTile.style.left = (newLeft + window.scrollX) + "px";
+        movingTile.style.top  = (newTop  + window.scrollY) + "px";
 
         var newDest = null;
 
     }
 
     function dragTileBegin(e) {
+        e.preventDefault();
         loadAudio();
         if (blockMove) {
             return;
         mouseMove(document, dragTileMove);
         mouseUp(document,   dragTileEnd);
 
-        movingTile.style.left   = tileInitCoords.left   + "px";
-        movingTile.style.top    = tileInitCoords.top    + "px";
+        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";
 
         }
     }
 
+    function preventDefault(e) {
+        e.preventDefault();
+        return false;
+    }
+
     function makeLetter(letter, highlight) {
         var tile = document.createElement("span");
         tile.className = "tile";
         tile.appendChild(document.createElement("span"));
         tile.lastChild.className = "tile-score";
         mouseDown(tile, dragTileBegin);
+
+        tile.addEventListener("contextmenu", preventDefault);
+        tile.addEventListener("touchmove", preventDefault);
+
         setLetter(tile, letter, highlight);
         return tile;
     }