Fix mousedown event (only in game)
authorBenjamin Auder <benjamin.auder@somewhere>
Tue, 4 Dec 2018 15:54:03 +0000 (16:54 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Tue, 4 Dec 2018 15:54:03 +0000 (16:54 +0100)
public/javascripts/components/game.js

index 84976b0..2a9a701 100644 (file)
@@ -736,6 +736,19 @@ Vue.component('my-game', {
                },
                mousedown: function(e) {
                        e = e || window.event;
                },
                mousedown: function(e) {
                        e = e || window.event;
+                       let ingame = false;
+                       let elem = e.target;
+                       while (!ingame && elem !== null)
+                       {
+                               if (elem.classList.contains("game"))
+                               {
+                                       ingame = true;
+                                       break;
+                               }
+                               elem = elem.parentElement;
+                       }
+                       if (!ingame) //let default behavior (click on button...)
+                               return;
                        e.preventDefault(); //disable native drag & drop
                        if (!this.selectedPiece && e.target.classList.contains("piece"))
                        {
                        e.preventDefault(); //disable native drag & drop
                        if (!this.selectedPiece && e.target.classList.contains("piece"))
                        {