Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow clicking source and destination to move piece, in addition to dragging and dropping. #138

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion www/js/chessboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ var ANIMATION_HAPPENING = false,
DRAGGED_PIECE,
DRAGGED_PIECE_LOCATION,
DRAGGED_PIECE_SOURCE,
CLICK_MOVE = false,
DRAGGING_A_PIECE = false,
SPARE_PIECE_ELS_IDS = {},
SQUARE_ELS_IDS = {},
Expand Down Expand Up @@ -1119,6 +1120,17 @@ function trashDraggedPiece() {
}

function dropDraggedPieceOnSquare(square) {

// if destination is same as source, piece stays picked up and is dropped at the next clicked square.
if (CLICK_MOVE == false) {
if (square === DRAGGED_PIECE_SOURCE) {
CLICK_MOVE = true;
return;
}
}

CLICK_MOVE = false;

removeSquareHighlights();

// update position
Expand Down Expand Up @@ -1275,6 +1287,17 @@ function stopDraggedPiece(location) {
if (result === 'snapback' || result === 'trash') {
action = result;
}
} else {
// source piece is a spare piece and position is off the board
if (DRAGGED_PIECE_SOURCE === 'spare' && location === 'offboard') {
if (CLICK_MOVE == false) {
// pick up spare piece and put it down on next clicked square
CLICK_MOVE = true;
return;
} else {
CLICK_MOVE = false;
}
}
}

// do it!
Expand Down Expand Up @@ -1704,4 +1727,4 @@ return widget;
window.ChessBoard.fenToObj = fenToObj;
window.ChessBoard.objToFen = objToFen;

})(); // end anonymous wrapper
})(); // end anonymous wrapper