Skip to content

Commit

Permalink
GitHub Issue #27 - update move() method with animations
Browse files Browse the repository at this point in the history
  • Loading branch information
oakmac committed Jul 31, 2013
1 parent 0497003 commit acb1074
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion js/chessboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,12 @@ var dropDraggedPieceOnSquare = function(square) {
var complete = function() {
drawPositionInstant();
draggedPieceEl.css('display', 'none');

// execute their onSnapEnd function
if (cfg.hasOwnProperty('onSnapEnd') === true &&
typeof cfg.onSnapEnd === 'function') {
cfg.onSnapEnd(DRAGGED_PIECE_SOURCE, square, DRAGGED_PIECE);
}
};

// snap the piece to the target square
Expand Down Expand Up @@ -1324,9 +1330,17 @@ widget.move = function() {
// no need to throw an error here; just do nothing
if (arguments.length === 0) return;

var useAnimation = true;

// collect the moves into an object
var moves = {};
for (var i = 0; i < arguments.length; i++) {
// any "false" to this function means no animations
if (arguments[i] === false) {
useAnimation = false;
continue;
}

// skip invalid arguments
if (validMove(arguments[i]) !== true) {
error(2826, 'Invalid move passed to the move method.', arguments[i]);
Expand All @@ -1341,7 +1355,7 @@ widget.move = function() {
var newPos = calculatePositionFromMoves(CURRENT_POSITION, moves);

// update the board
widget.position(newPos);
widget.position(newPos, useAnimation);

// return the new position object
return newPos;
Expand Down

0 comments on commit acb1074

Please sign in to comment.