/*!
- * chessboard.js v0.3.0
+ * chessboard.js v0.3.0+asn
*
* Copyright 2013 Chris Oakman
+ * Portions copyright 2022 Steinar H. Gunderson
* Released under the MIT license
* http://chessboardjs.com/license
*
containerEl = containerElOrId;
}
- // JSON must exist
- if (! window.JSON ||
- typeof JSON.stringify !== 'function' ||
- typeof JSON.parse !== 'function') {
- window.alert('ChessBoard Error 1004: JSON does not exist. ' +
- 'Please include a JSON polyfill.\n\nExiting...');
- return false;
- }
-
- // check for a compatible version of jQuery
- if (! (typeof window.$ && $.fn && $.fn.jquery &&
- compareSemVer($.fn.jquery, MINIMUM_JQUERY_VERSION) === true)) {
- window.alert('ChessBoard Error 1005: Unable to find a valid version ' +
- 'of jQuery. Please include jQuery ' + MINIMUM_JQUERY_VERSION + ' or ' +
- 'higher on the page.\n\nExiting...');
- return false;
- }
-
return true;
}
// animate the piece to the destination square
animatedPieceEl.addEventListener('transitionend', complete, {once: true});
requestAnimationFrame(() => {
- animatedPieceEl.style.transitionProperty = 'top left';
+ animatedPieceEl.style.transitionProperty = 'top, left';
animatedPieceEl.style.transitionDuration = cfg.moveSpeed + 'ms';
animatedPieceEl.style.top = destSquarePosition.top + 'px';
animatedPieceEl.style.left = destSquarePosition.left + 'px';
duration: cfg.moveSpeed,
complete: complete
};
- $(animatedPieceEl).animate(destOffset, opts);
+ //$(animatedPieceEl).animate(destOffset, opts);
}
function fadeIn(piece, onFinish) {
}
}
- for (var i = 0; i < a.length; i++) {
- // clear a piece
- if (a[i].type === 'clear') {
- document.getElementById(SQUARE_ELS_IDS[a[i].square]).querySelectorAll('.' + CSS.piece).forEach(
- (piece) => fadeOut(piece, onFinish)
- );
- }
+ requestAnimationFrame(() => { // Firefox workaround.
+ for (var i = 0; i < a.length; i++) {
+ // clear a piece
+ if (a[i].type === 'clear') {
+ document.getElementById(SQUARE_ELS_IDS[a[i].square]).querySelectorAll('.' + CSS.piece).forEach(
+ (piece) => fadeOut(piece, onFinish)
+ );
+ }
- // add a piece (no spare pieces)
- if (a[i].type === 'add' && cfg.sparePieces !== true) {
- let square = document.getElementById(SQUARE_ELS_IDS[a[i].square]);
- square.append(buildPiece(a[i].piece, true));
- let piece = square.querySelector('.' + CSS.piece);
- fadeIn(piece, onFinish);
- }
+ // add a piece (no spare pieces)
+ if (a[i].type === 'add' && cfg.sparePieces !== true) {
+ let square = document.getElementById(SQUARE_ELS_IDS[a[i].square]);
+ square.append(buildPiece(a[i].piece, true));
+ let piece = square.querySelector('.' + CSS.piece);
+ fadeIn(piece, onFinish);
+ }
- // add a piece from a spare piece
- if (a[i].type === 'add' && cfg.sparePieces === true) {
- animateSparePieceToSquare(a[i].piece, a[i].square, onFinish);
- }
+ // add a piece from a spare piece
+ if (a[i].type === 'add' && cfg.sparePieces === true) {
+ animateSparePieceToSquare(a[i].piece, a[i].square, onFinish);
+ }
- // move a piece
- if (a[i].type === 'move') {
- animateSquareToSquare(a[i].source, a[i].destination, a[i].piece,
- onFinish);
+ // move a piece
+ if (a[i].type === 'move') {
+ animateSquareToSquare(a[i].source, a[i].destination, a[i].piece,
+ onFinish);
+ }
}
- }
+ });
}
// returns the distance between two squares
// animate the piece to the target square
draggedPieceEl.addEventListener('transitionend', complete, {once: true});
requestAnimationFrame(() => {
- draggedPieceEl.style.transitionProperty = 'top left';
+ draggedPieceEl.style.transitionProperty = 'top, left';
draggedPieceEl.style.transitionDuration = cfg.snapbackSpeed + 'ms';
draggedPieceEl.style.top = sourceSquarePosition.top + 'px';
draggedPieceEl.style.left = sourceSquarePosition.left + 'px';
// hide the dragged piece
// FIXME: support this for non-jquery
- $(draggedPieceEl).fadeOut(cfg.trashSpeed);
+ //$(draggedPieceEl).fadeOut(cfg.trashSpeed);
// set state
DRAGGING_A_PIECE = false;
// snap the piece to the target square
draggedPieceEl.addEventListener('transitionend', complete, {once: true});
requestAnimationFrame(() => {
- draggedPieceEl.style.transitionProperty = 'top left';
+ draggedPieceEl.style.transitionProperty = 'top, left';
draggedPieceEl.style.transitionDuration = cfg.snapSpeed + 'ms';
draggedPieceEl.style.top = targetSquarePosition.top + 'px';
draggedPieceEl.style.left = targetSquarePosition.left + 'px';