Skip to content
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