- if (!this.start) {
- // NOTE: classList[0] is enough: 'piece' is the first assigned class
- const withPiece = e.target.classList[0] == "piece";
- // Emit the click event which could be used by some variants
- this.$emit(
- "click-square",
- getSquareFromId(withPiece ? e.target.parentNode.id : e.target.id)
- );
- // Start square must contain a piece.
- if (!withPiece) return;
- let parent = e.target.parentNode; //surrounding square
- // Show possible moves if current player allowed to play
- const startSquare = getSquareFromId(parent.id);
- this.possibleMoves = [];
- const color = this.analyze ? this.vr.turn : this.userColor;
- if (this.vr.canIplay(color, startSquare))
- this.possibleMoves = this.vr.getPossibleMovesFrom(startSquare);
- // For potential drag'n drop, remember start coordinates
- // (to center the piece on mouse cursor)
- let rect = parent.getBoundingClientRect();
- this.start = {
+ if (e.which != 3)
+ // Cancel current drawing and circles, if any
+ this.cancelResetArrows();
+ if (e.which == 1 || this.mobileBrowser) {
+ // Mouse left button
+ if (!this.start) {
+ // NOTE: classList[0] is enough: 'piece' is the first assigned class
+ const withPiece = (e.target.classList[0] == "piece");
+ // Emit the click event which could be used by some variants
+ this.$emit(
+ "click-square",
+ getSquareFromId(withPiece ? e.target.parentNode.id : e.target.id)
+ );
+ // Start square must contain a piece.
+ if (!withPiece) return;
+ let parent = e.target.parentNode; //surrounding square
+ // Show possible moves if current player allowed to play
+ const startSquare = getSquareFromId(parent.id);
+ this.possibleMoves = [];
+ const color = this.analyze ? this.vr.turn : this.userColor;
+ if (this.vr.canIplay(color, startSquare))
+ this.possibleMoves = this.vr.getPossibleMovesFrom(startSquare);
+ // For potential drag'n drop, remember start coordinates
+ // (to center the piece on mouse cursor)
+ const rect = parent.getBoundingClientRect();
+ this.start = {
+ x: rect.x + rect.width / 2,
+ y: rect.y + rect.width / 2,
+ id: parent.id
+ };
+ // Add the moving piece to the board, just after current image
+ this.selectedPiece = e.target.cloneNode();
+ Object.assign(
+ this.selectedPiece.style,
+ {
+ position: "absolute",
+ top: 0,
+ display: "inline-block",
+ zIndex: 3000
+ }
+ );
+ parent.insertBefore(this.selectedPiece, e.target.nextSibling);
+ } else {
+ this.processMoveAttempt(e);
+ }
+ } else {
+ // e.which == 3 : mouse right button
+ let elem = e.target;
+ // Next loop because of potential marks
+ while (elem.tagName == "IMG") elem = elem.parentNode;
+ // To center the arrow in square:
+ const rect = elem.getBoundingClientRect();
+ this.startArrow = {