diff --git a/data/releases.json b/data/releases.json index dbcec679..1b9f5933 100644 --- a/data/releases.json +++ b/data/releases.json @@ -1,53 +1,53 @@ -[ -"-----------------------------------------------------------------", -{ - "released":false, - "version":"0.3.1", - "date":"10 Aug 2013", - "changes":[ - "Orientation methods now return current orientation (GitHub Issue #64)" - ], - "files":[ - { "name":"chessboardjs-0.3.1.zip", "size":"44.6 KB" } - ] -}, -"-----------------------------------------------------------------", -{ - "version":"0.3.0", - "date":"10 Aug 2013", - "changes":[ - "Added appearSpeed animation config", - "Added onSnapbackEnd event", - "Added onMoveEnd event" - ], - "files":[ - { "name":"chessboardjs-0.3.0.zip", "size":"44.6 KB" } - ] -}, -"-----------------------------------------------------------------", -{ - "version":"0.2.0", - "date":"05 Aug 2013", - "changes":[ - "Added onMouseoverSquare and onMouseoutSquare events", - "Added onSnapEnd event", - "Added square code as CSS class on the squares", - "chess.js integration examples" - ], - "files":[ - { "name":"chessboardjs-0.2.0.zip", "size":"44.6 KB" } - ] -}, -"-----------------------------------------------------------------", -{ - "version":"0.1.0", - "date":"21 Jul 2013", - "changes":[ - "Initial release" - ], - "files":[ - { "name":"chessboard-0.1.0.zip", "size":"44.0 KB" } - ] -}, -"-----------------------------------------------------------------" +[ +"-----------------------------------------------------------------", +{ + "released":false, + "version":"0.3.1", + "date":"10 Aug 2013", + "changes":[ + "Orientation methods now return current orientation (GitHub Issue #64)" + ], + "files":[ + { "name":"chessboardjs-0.3.1.zip", "size":"44.6 KB" } + ] +}, +"-----------------------------------------------------------------", +{ + "version":"0.3.0", + "date":"10 Aug 2013", + "changes":[ + "Added appearSpeed animation config", + "Added onSnapbackEnd event", + "Added onMoveEnd event" + ], + "files":[ + { "name":"chessboardjs-0.3.0.zip", "size":"44.6 KB" } + ] +}, +"-----------------------------------------------------------------", +{ + "version":"0.2.0", + "date":"05 Aug 2013", + "changes":[ + "Added onMouseoverSquare and onMouseoutSquare events", + "Added onSnapEnd event", + "Added square code as CSS class on the squares", + "chess.js integration examples" + ], + "files":[ + { "name":"chessboardjs-0.2.0.zip", "size":"44.6 KB" } + ] +}, +"-----------------------------------------------------------------", +{ + "version":"0.1.0", + "date":"21 Jul 2013", + "changes":[ + "Initial release" + ], + "files":[ + { "name":"chessboard-0.1.0.zip", "size":"44.0 KB" } + ] +}, +"-----------------------------------------------------------------" ] \ No newline at end of file diff --git a/examples/1000-empty-board.example b/examples/1000-empty-board.example index b065604c..19c7f32c 100644 --- a/examples/1000-empty-board.example +++ b/examples/1000-empty-board.example @@ -2,13 +2,13 @@ 1000 ===== Name -Empty Board - +Empty Board + ===== Description Chessboard.js initializes to an empty board with no second argument. - + ===== HTML
- + ===== JS var board = Chessboard('myBoard') diff --git a/examples/1001-start-position.example b/examples/1001-start-position.example index d95b132b..d1ac9cee 100644 --- a/examples/1001-start-position.example +++ b/examples/1001-start-position.example @@ -1,15 +1,15 @@ ===== id 1001 -===== Name -Start Position - +===== Name +Start Position + ===== Description Pass 'start' as the second argument to initialize the board to the start position. - + ===== HTML
- + ===== JS var board = Chessboard('myBoard', 'start') diff --git a/examples/1002-fen.example b/examples/1002-fen.example index fa7718a2..a3776e05 100644 --- a/examples/1002-fen.example +++ b/examples/1002-fen.example @@ -1,16 +1,16 @@ ===== id 1002 -===== Name -FEN String - +===== Name +FEN String + ===== Description Pass a FEN String as the second argument to initialize the board to a specific position. - + ===== HTML
- + ===== JS var ruyLopez = 'r1bqkbnr/pppp1ppp/2n5/1B2p3/4P3/5N2/PPPP1PPP/RNBQK2R' var board = Chessboard('myBoard', ruyLopez) diff --git a/examples/1003-position-object.example b/examples/1003-position-object.example index 6bfa237e..f5926f03 100644 --- a/examples/1003-position-object.example +++ b/examples/1003-position-object.example @@ -1,16 +1,16 @@ ===== id 1003 -===== Name -Position Object - -===== Description -Pass a Position Object as the second argument to initialize the board to a specific position. - -===== HTML -
- -===== JS +===== Name +Position Object + +===== Description +Pass a Position Object as the second argument to initialize the board to a specific position. + +===== HTML +
+ +===== JS var position = { d6: 'bK', d4: 'wP', diff --git a/examples/1004-multiple-boards.example b/examples/1004-multiple-boards.example index 54c45e6d..88e7ddd3 100644 --- a/examples/1004-multiple-boards.example +++ b/examples/1004-multiple-boards.example @@ -1,25 +1,25 @@ ===== id 1004 -===== Name -Multiple Boards - -===== Description -You can have multiple boards on the same page. - +===== Name +Multiple Boards + +===== Description +You can have multiple boards on the same page. + ===== CSS .small-board { display: inline-block; margin-right: 5px; width: 200px; } - + ===== HTML
- -===== JS + +===== JS var board1 = Chessboard('board1', { position: 'start', showNotation: false diff --git a/examples/2000-config-position.example b/examples/2000-config-position.example index ed5ba568..81e0d661 100644 --- a/examples/2000-config-position.example +++ b/examples/2000-config-position.example @@ -1,17 +1,17 @@ ===== id 2000 -===== Name -Start Position - -===== Description -Set the position property to 'start' to initialize the board to the start position. - -===== HTML -
- -===== JS -var config = { - position: 'start' +===== Name +Start Position + +===== Description +Set the position property to 'start' to initialize the board to the start position. + +===== HTML +
+ +===== JS +var config = { + position: 'start' } -var board = Chessboard('myBoard', config) +var board = Chessboard('myBoard', config) diff --git a/examples/2001-config-orientation.example b/examples/2001-config-orientation.example index 1ce4048b..e8ec9cdc 100644 --- a/examples/2001-config-orientation.example +++ b/examples/2001-config-orientation.example @@ -1,18 +1,18 @@ ===== id 2001 -===== Name -Orientation - -===== Description -Use the orientation property to set board orientation. - -===== HTML -
- -===== JS -var config = { - orientation: 'black', - position: 'start' +===== Name +Orientation + +===== Description +Use the orientation property to set board orientation. + +===== HTML +
+ +===== JS +var config = { + orientation: 'black', + position: 'start' } -var board = Chessboard('myBoard', config) +var board = Chessboard('myBoard', config) diff --git a/examples/2002-config-notation.example b/examples/2002-config-notation.example index a4585bed..c188ce44 100644 --- a/examples/2002-config-notation.example +++ b/examples/2002-config-notation.example @@ -1,18 +1,18 @@ ===== id 2002 -===== Name -Notation - -===== Description -Use the showNotation property to turn board notation on or off. - -===== HTML -
- -===== JS -var config = { - showNotation: false, - position: 'start' +===== Name +Notation + +===== Description +Use the showNotation property to turn board notation on or off. + +===== HTML +
+ +===== JS +var config = { + showNotation: false, + position: 'start' } -var board = Chessboard('myBoard', config) +var board = Chessboard('myBoard', config) diff --git a/examples/2003-draggable-snapback.example b/examples/2003-draggable-snapback.example index 194e8580..71ffedb9 100644 --- a/examples/2003-draggable-snapback.example +++ b/examples/2003-draggable-snapback.example @@ -1,19 +1,19 @@ ===== id 2003 -===== Name -Draggable Snapback - -===== Description -Set draggable to true to allow drag and drop of pieces. Pieces will return to their original square when dropped off the board (ie: the default for dropOffBoard is 'snapback'). - -===== HTML -
- -===== JS -var config = { - draggable: true, - dropOffBoard: 'snapback', // this is the default - position: 'start' +===== Name +Draggable Snapback + +===== Description +Set draggable to true to allow drag and drop of pieces. Pieces will return to their original square when dropped off the board (ie: the default for dropOffBoard is 'snapback'). + +===== HTML +
+ +===== JS +var config = { + draggable: true, + dropOffBoard: 'snapback', // this is the default + position: 'start' } -var board = Chessboard('myBoard', config) +var board = Chessboard('myBoard', config) diff --git a/examples/3000-get-position.example b/examples/3000-get-position.example index 6aadc63d..eecf76fe 100644 --- a/examples/3000-get-position.example +++ b/examples/3000-get-position.example @@ -1,17 +1,17 @@ ===== id 3000 -===== Name -Get Position - -===== Description -Use the position and fen methods to retrieve the current position of the board. - -===== HTML -
+===== Name +Get Position + +===== Description +Use the position and fen methods to retrieve the current position of the board. + +===== HTML +
- -===== JS + +===== JS var config = { draggable: true, position: 'start' diff --git a/examples/3001-set-position.example b/examples/3001-set-position.example index e999f107..3194466b 100644 --- a/examples/3001-set-position.example +++ b/examples/3001-set-position.example @@ -1,19 +1,19 @@ ===== id 3001 -===== Name -Set Position - -===== Description -Use the start and position methods to set the board position. - -===== HTML -
+===== Name +Set Position + +===== Description +Use the start and position methods to set the board position. + +===== HTML +
- -===== JS + +===== JS var board = Chessboard('myBoard') $('#setRuyLopezBtn').on('click', function () { diff --git a/examples/3002-set-position-instant.example b/examples/3002-set-position-instant.example index 08e5ad15..283e4d44 100644 --- a/examples/3002-set-position-instant.example +++ b/examples/3002-set-position-instant.example @@ -1,19 +1,19 @@ ===== id 3002 -===== Name -Set Position Instantly - -===== Description -Pass false as the second argument to the start and position methods to set the board position instantly. - -===== HTML -
+===== Name +Set Position Instantly + +===== Description +Pass false as the second argument to the start and position methods to set the board position instantly. + +===== HTML +
- -===== JS + +===== JS var board = Chessboard('myBoard') $('#setRuyLopezBtn').on('click', function () { diff --git a/examples/3003-clear.example b/examples/3003-clear.example index d1243b68..2effbb08 100644 --- a/examples/3003-clear.example +++ b/examples/3003-clear.example @@ -1,19 +1,19 @@ ===== id 3003 -===== Name -Clear Board - -===== Description -Use the clear method to remove all the pieces from the board. - -===== HTML -
+===== Name +Clear Board + +===== Description +Use the clear method to remove all the pieces from the board. + +===== HTML +
- -===== JS + +===== JS var board = Chessboard('myBoard', 'start') $('#clearBoardBtn').on('click', board.clear) diff --git a/examples/3004-move-pieces.example b/examples/3004-move-pieces.example index c380527d..89956e59 100644 --- a/examples/3004-move-pieces.example +++ b/examples/3004-move-pieces.example @@ -1,19 +1,19 @@ ===== id 3004 -===== Name -Move Pieces - -===== Description -Use the move method to make one or more moves on the board. - -===== HTML -
+===== Name +Move Pieces + +===== Description +Use the move method to make one or more moves on the board. + +===== HTML +
-===== JS +===== JS var board = Chessboard('myBoard', 'start') $('#move1Btn').on('click', function () { diff --git a/examples/3005-orientation.example b/examples/3005-orientation.example index b3221564..a64101f2 100644 --- a/examples/3005-orientation.example +++ b/examples/3005-orientation.example @@ -1,21 +1,21 @@ ===== id 3005 -===== Name -Orientation - -===== Description -Use the orientation method to retrieve and set the orientation. Use the flip method to flip orientation. - -===== HTML -
+===== Name +Orientation + +===== Description +Use the orientation method to retrieve and set the orientation. Use the flip method to flip orientation. + +===== HTML +

-===== JS +===== JS var ruyLopez = 'r1bqkbnr/pppp1ppp/2n5/1B2p3/4P3/5N2/PPPP1PPP/RNBQK2R' var board = Chessboard('myBoard', ruyLopez) diff --git a/examples/4000-onchange.example b/examples/4000-onchange.example index bc8c60da..ca06e63e 100644 --- a/examples/4000-onchange.example +++ b/examples/4000-onchange.example @@ -1,18 +1,18 @@ ===== id 4000 -===== Name -onChange - -===== Description +===== Name +onChange + +===== Description The onChange event fires when the board position changes. - -===== HTML + +===== HTML
-===== JS +===== JS function onChange (oldPos, newPos) { console.log('Position changed:') console.log('Old position: ' + Chessboard.objToFen(oldPos)) diff --git a/examples/5004-piece-highlight1.example b/examples/5004-piece-highlight1.example index 5195335f..2536f59f 100644 --- a/examples/5004-piece-highlight1.example +++ b/examples/5004-piece-highlight1.example @@ -1,23 +1,23 @@ ===== id 5004 -===== Name -Piece Highlighting 1 - -===== Description -Use CSS to show piece highlighting. - -===== HTML - -
- +
+ ===== JS // NOTE: this example uses the chess.js library: // https://github.com/jhlywa/chess.js diff --git a/lib/chessboard.css b/lib/chessboard.css index 27ffdccb..2add196e 100644 --- a/lib/chessboard.css +++ b/lib/chessboard.css @@ -1,54 +1,54 @@ /*! chessboard.js v@VERSION | (c) 2019 Chris Oakman | MIT License chessboardjs.com/license */ - + .clearfix-7da63 { - clear: both; -} - + clear: both; +} + .board-b72b1 { border: 2px solid #404040; box-sizing: content-box; -} - +} + .square-55d63 { - float: left; - position: relative; - - /* disable any native browser highlighting */ - -webkit-touch-callout: none; - -webkit-user-select: none; - -khtml-user-select: none; - -moz-user-select: none; - -ms-user-select: none; - user-select: none; -} - + float: left; + position: relative; + + /* disable any native browser highlighting */ + -webkit-touch-callout: none; + -webkit-user-select: none; + -khtml-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; +} + .white-1e1d7 { - background-color: #f0d9b5; - color: #b58863; -} - + background-color: #f0d9b5; + color: #b58863; +} + .black-3c85d { - background-color: #b58863; - color: #f0d9b5; -} + background-color: #b58863; + color: #f0d9b5; +} .highlight1-32417, .highlight2-9c5d2 { - box-shadow: inset 0 0 3px 3px yellow; -} + box-shadow: inset 0 0 3px 3px yellow; +} -.notation-322f9 { - cursor: default; - font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; - font-size: 14px; - position: absolute; +.notation-322f9 { + cursor: default; + font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; + font-size: 14px; + position: absolute; } -.alpha-d2270 { - bottom: 1px; - right: 3px; +.alpha-d2270 { + bottom: 1px; + right: 3px; } -.numeric-fc462 { - top: 2px; - left: 2px; +.numeric-fc462 { + top: 2px; + left: 2px; } diff --git a/lib/chessboard.js b/lib/chessboard.js index ed27db18..47ccf3f0 100644 --- a/lib/chessboard.js +++ b/lib/chessboard.js @@ -4,9 +4,9 @@ // Copyright (c) 2019, Chris Oakman // Released under the MIT license // https://github.com/oakmac/chessboardjs/blob/master/LICENSE.md - -// start anonymous scope -;(function () { + +// start anonymous scope +;(function () { 'use strict' var $ = window['jQuery'] @@ -179,20 +179,20 @@ rate >= 1 } - function validMove (move) { - // move should be a string + function validMove (move) { + // move should be a string if (!isString(move)) return false - - // move should be in the form of "e2-e4", "f6-d5" + + // move should be in the form of "e2-e4", "f6-d5" var squares = move.split('-') if (squares.length !== 2) return false - + return validSquare(squares[0]) && validSquare(squares[1]) - } - + } + function validSquare (square) { return isString(square) && square.search(/^[a-h][1-8]$/) !== -1 - } + } if (RUN_ASSERTS) { console.assert(validSquare('a1')) @@ -207,7 +207,7 @@ function validPieceCode (code) { return isString(code) && code.search(/^[bw][KQRNBP]$/) !== -1 - } + } if (RUN_ASSERTS) { console.assert(validPieceCode('bP')) @@ -224,28 +224,28 @@ function validFen (fen) { if (!isString(fen)) return false - - // cut off any move, castling, etc info from the end - // we're only interested in position information - fen = fen.replace(/ .+$/, '') + + // cut off any move, castling, etc info from the end + // we're only interested in position information + fen = fen.replace(/ .+$/, '') // expand the empty square numbers to just 1s fen = expandFenEmptySquares(fen) - // FEN should be 8 sections separated by slashes - var chunks = fen.split('/') + // FEN should be 8 sections separated by slashes + var chunks = fen.split('/') if (chunks.length !== 8) return false // check each section for (var i = 0; i < 8; i++) { if (chunks[i].length !== 8 || chunks[i].search(/[^kqrnbpKQRNBP1]/) !== -1) { - return false - } - } - - return true - } + return false + } + } + + return true + } if (RUN_ASSERTS) { console.assert(validFen(START_FEN)) @@ -263,17 +263,17 @@ function validPositionObject (pos) { if (!$.isPlainObject(pos)) return false - - for (var i in pos) { - if (!pos.hasOwnProperty(i)) continue - - if (!validSquare(i) || !validPieceCode(pos[i])) { - return false - } - } - - return true - } + + for (var i in pos) { + if (!pos.hasOwnProperty(i)) continue + + if (!validSquare(i) || !validPieceCode(pos[i])) { + return false + } + } + + return true + } if (RUN_ASSERTS) { console.assert(validPositionObject(START_POSITION)) @@ -326,76 +326,76 @@ return pieceCodeLetters[1].toLowerCase() } - // convert FEN string to position object - // returns false if the FEN string is invalid - function fenToObj (fen) { + // convert FEN string to position object + // returns false if the FEN string is invalid + function fenToObj (fen) { if (!validFen(fen)) return false - - // cut off any move, castling, etc info from the end - // we're only interested in position information - fen = fen.replace(/ .+$/, '') - - var rows = fen.split('/') - var position = {} - - var currentRow = 8 - for (var i = 0; i < 8; i++) { - var row = rows[i].split('') + + // cut off any move, castling, etc info from the end + // we're only interested in position information + fen = fen.replace(/ .+$/, '') + + var rows = fen.split('/') + var position = {} + + var currentRow = 8 + for (var i = 0; i < 8; i++) { + var row = rows[i].split('') var colIdx = 0 - - // loop through each character in the FEN section - for (var j = 0; j < row.length; j++) { - // number / empty squares - if (row[j].search(/[1-8]/) !== -1) { + + // loop through each character in the FEN section + for (var j = 0; j < row.length; j++) { + // number / empty squares + if (row[j].search(/[1-8]/) !== -1) { var numEmptySquares = parseInt(row[j], 10) colIdx = colIdx + numEmptySquares } else { - // piece + // piece var square = COLUMNS[colIdx] + currentRow - position[square] = fenToPieceCode(row[j]) + position[square] = fenToPieceCode(row[j]) colIdx = colIdx + 1 - } - } + } + } currentRow = currentRow - 1 - } - - return position + } + + return position } - // position object to FEN string - // returns false if the obj is not a valid position object - function objToFen (obj) { + // position object to FEN string + // returns false if the obj is not a valid position object + function objToFen (obj) { if (!validPositionObject(obj)) return false - - var fen = '' - - var currentRow = 8 - for (var i = 0; i < 8; i++) { - for (var j = 0; j < 8; j++) { - var square = COLUMNS[j] + currentRow - - // piece exists + + var fen = '' + + var currentRow = 8 + for (var i = 0; i < 8; i++) { + for (var j = 0; j < 8; j++) { + var square = COLUMNS[j] + currentRow + + // piece exists if (obj.hasOwnProperty(square)) { fen = fen + pieceCodeToFen(obj[square]) - } else { - // empty space + } else { + // empty space fen = fen + '1' - } - } - + } + } + if (i !== 7) { fen = fen + '/' } - + currentRow = currentRow - 1 - } - + } + // squeeze the empty numbers together fen = squeezeFenEmptySquares(fen) - return fen - } + return fen + } if (RUN_ASSERTS) { console.assert(objToFen(START_POSITION) === START_FEN) @@ -663,8 +663,8 @@ var $sparePiecesBottom = null // constructor return object - var widget = {} - + var widget = {} + // ------------------------------------------------------------------------- // Stateful // ------------------------------------------------------------------------- @@ -684,44 +684,44 @@ // ------------------------------------------------------------------------- // Validation / Errors // ------------------------------------------------------------------------- - - function error (code, msg, obj) { - // do nothing if showErrors is not set - if ( + + function error (code, msg, obj) { + // do nothing if showErrors is not set + if ( config.hasOwnProperty('showErrors') !== true || config.showErrors === false - ) { - return - } - + ) { + return + } + var errorText = 'Chessboard Error ' + code + ': ' + msg - - // print to console - if ( + + // print to console + if ( config.showErrors === 'console' && - typeof console === 'object' && - typeof console.log === 'function' - ) { - console.log(errorText) - if (arguments.length >= 2) { - console.log(obj) - } - return - } - - // alert errors + typeof console === 'object' && + typeof console.log === 'function' + ) { + console.log(errorText) + if (arguments.length >= 2) { + console.log(obj) + } + return + } + + // alert errors if (config.showErrors === 'alert') { - if (obj) { - errorText += '\n\n' + JSON.stringify(obj) - } - window.alert(errorText) - return - } - + if (obj) { + errorText += '\n\n' + JSON.stringify(obj) + } + window.alert(errorText) + return + } + // custom function if (isFunction(config.showErrors)) { config.showErrors(code, msg, obj) - } + } } function setInitialState () { @@ -748,50 +748,50 @@ // ------------------------------------------------------------------------- // DOM Misc // ------------------------------------------------------------------------- - + // calculates square size based on the width of the container // got a little CSS black magic here, so let me explain: // get the width of the container element (could be anything), reduce by 1 for // fudge factor, and then keep reducing until we find an exact mod 8 for // our square size - function calculateSquareSize () { + function calculateSquareSize () { var containerWidth = parseInt($container.width(), 10) - + // defensive, prevent infinite loop if (!containerWidth || containerWidth <= 0) { - return 0 - } - + return 0 + } + // pad one pixel - var boardWidth = containerWidth - 1 - + var boardWidth = containerWidth - 1 + while (boardWidth % 8 !== 0 && boardWidth > 0) { boardWidth = boardWidth - 1 - } - - return boardWidth / 8 - } - + } + + return boardWidth / 8 + } + // create random IDs for elements function createElIds () { // squares on the board for (var i = 0; i < COLUMNS.length; i++) { for (var j = 1; j <= 8; j++) { - var square = COLUMNS[i] + j + var square = COLUMNS[i] + j squareElsIds[square] = square + '-' + uuid() - } - } - + } + } + // spare pieces var pieces = 'KQRNBP'.split('') for (i = 0; i < pieces.length; i++) { - var whitePiece = 'w' + pieces[i] - var blackPiece = 'b' + pieces[i] + var whitePiece = 'w' + pieces[i] + var blackPiece = 'b' + pieces[i] sparePiecesElsIds[whitePiece] = whitePiece + '-' + uuid() sparePiecesElsIds[blackPiece] = blackPiece + '-' + uuid() - } - } - + } + } + // ------------------------------------------------------------------------- // Markup Building // ------------------------------------------------------------------------- @@ -853,158 +853,158 @@ return interpolateTemplate(html, CSS) } - - function buildPieceImgSrc (piece) { + + function buildPieceImgSrc (piece) { if (isFunction(config.pieceTheme)) { return config.pieceTheme(piece) - } - + } + if (isString(config.pieceTheme)) { return interpolateTemplate(config.pieceTheme, {piece: piece}) - } - + } + // NOTE: this should never happen error(8272, 'Unable to build image source for config.pieceTheme.') - return '' - } - + return '' + } + function buildPieceHTML (piece, hidden, id) { - var html = '' - + html += '" />' + return interpolateTemplate(html, CSS) - } - + } + function buildSparePiecesHTML (color) { - var pieces = ['wK', 'wQ', 'wR', 'wB', 'wN', 'wP'] - if (color === 'black') { - pieces = ['bK', 'bQ', 'bR', 'bB', 'bN', 'bP'] - } - - var html = '' - for (var i = 0; i < pieces.length; i++) { + var pieces = ['wK', 'wQ', 'wR', 'wB', 'wN', 'wP'] + if (color === 'black') { + pieces = ['bK', 'bQ', 'bR', 'bB', 'bN', 'bP'] + } + + var html = '' + for (var i = 0; i < pieces.length; i++) { html += buildPieceHTML(pieces[i], false, sparePiecesElsIds[pieces[i]]) - } - - return html - } - + } + + return html + } + // ------------------------------------------------------------------------- // Animations // ------------------------------------------------------------------------- - - function animateSquareToSquare (src, dest, piece, completeFn) { + + function animateSquareToSquare (src, dest, piece, completeFn) { // get information about the source and destination squares var $srcSquare = $('#' + squareElsIds[src]) var srcSquarePosition = $srcSquare.offset() var $destSquare = $('#' + squareElsIds[dest]) var destSquarePosition = $destSquare.offset() - + // create the animated piece and absolutely position it // over the source square - var animatedPieceId = uuid() + var animatedPieceId = uuid() $('body').append(buildPieceHTML(piece, true, animatedPieceId)) var $animatedPiece = $('#' + animatedPieceId) $animatedPiece.css({ - display: '', - position: 'absolute', - top: srcSquarePosition.top, - left: srcSquarePosition.left - }) - + display: '', + position: 'absolute', + top: srcSquarePosition.top, + left: srcSquarePosition.left + }) + // remove original piece from source square $srcSquare.find('.' + CSS.piece).remove() function onFinishAnimation1 () { // add the "real" piece to the destination square $destSquare.append(buildPieceHTML(piece)) - + // remove the animated piece $animatedPiece.remove() - + // run complete function if (isFunction(completeFn)) { - completeFn() - } - } - + completeFn() + } + } + // animate the piece to the destination square - var opts = { + var opts = { duration: config.moveSpeed, complete: onFinishAnimation1 - } + } $animatedPiece.animate(destSquarePosition, opts) - } - - function animateSparePieceToSquare (piece, dest, completeFn) { + } + + function animateSparePieceToSquare (piece, dest, completeFn) { var srcOffset = $('#' + sparePiecesElsIds[piece]).offset() var $destSquare = $('#' + squareElsIds[dest]) var destOffset = $destSquare.offset() - + // create the animate piece - var pieceId = uuid() + var pieceId = uuid() $('body').append(buildPieceHTML(piece, true, pieceId)) var $animatedPiece = $('#' + pieceId) $animatedPiece.css({ - display: '', - position: 'absolute', - left: srcOffset.left, - top: srcOffset.top - }) - + display: '', + position: 'absolute', + left: srcOffset.left, + top: srcOffset.top + }) + // on complete function onFinishAnimation2 () { // add the "real" piece to the destination square $destSquare.find('.' + CSS.piece).remove() $destSquare.append(buildPieceHTML(piece)) - + // remove the animated piece $animatedPiece.remove() - + // run complete function if (isFunction(completeFn)) { - completeFn() - } - } - + completeFn() + } + } + // animate the piece to the destination square - var opts = { + var opts = { duration: config.moveSpeed, complete: onFinishAnimation2 - } + } $animatedPiece.animate(destOffset, opts) } // execute an array of animations function doAnimations (animations, oldPos, newPos) { if (animations.length === 0) return - - var numFinished = 0 + + var numFinished = 0 function onFinishAnimation3 () { // exit if all the animations aren't finished numFinished = numFinished + 1 if (numFinished !== animations.length) return drawPositionInstant() - + // run their onMoveEnd function if (isFunction(config.onMoveEnd)) { config.onMoveEnd(deepCopy(oldPos), deepCopy(newPos)) - } - } - + } + } + for (var i = 0; i < animations.length; i++) { var animation = animations[i] @@ -1027,178 +1027,178 @@ // move a piece from squareA to squareB } else if (animation.type === 'move') { animateSquareToSquare(animation.source, animation.destination, animation.piece, onFinishAnimation3) - } - } + } + } } // calculate an array of animations that need to happen in order to get // from pos1 to pos2 - function calculateAnimations (pos1, pos2) { + function calculateAnimations (pos1, pos2) { // make copies of both - pos1 = deepCopy(pos1) - pos2 = deepCopy(pos2) - - var animations = [] - var squaresMovedTo = {} - + pos1 = deepCopy(pos1) + pos2 = deepCopy(pos2) + + var animations = [] + var squaresMovedTo = {} + // remove pieces that are the same in both positions - for (var i in pos2) { - if (!pos2.hasOwnProperty(i)) continue - - if (pos1.hasOwnProperty(i) && pos1[i] === pos2[i]) { - delete pos1[i] - delete pos2[i] - } - } - + for (var i in pos2) { + if (!pos2.hasOwnProperty(i)) continue + + if (pos1.hasOwnProperty(i) && pos1[i] === pos2[i]) { + delete pos1[i] + delete pos2[i] + } + } + // find all the "move" animations for (i in pos2) { - if (!pos2.hasOwnProperty(i)) continue - - var closestPiece = findClosestPiece(pos1, pos2[i], i) + if (!pos2.hasOwnProperty(i)) continue + + var closestPiece = findClosestPiece(pos1, pos2[i], i) if (closestPiece) { - animations.push({ - type: 'move', - source: closestPiece, - destination: i, - piece: pos2[i] - }) - - delete pos1[closestPiece] - delete pos2[i] - squaresMovedTo[i] = true - } + animations.push({ + type: 'move', + source: closestPiece, + destination: i, + piece: pos2[i] + }) + + delete pos1[closestPiece] + delete pos2[i] + squaresMovedTo[i] = true + } } // "add" animations for (i in pos2) { if (!pos2.hasOwnProperty(i)) continue - - animations.push({ - type: 'add', - square: i, - piece: pos2[i] - }) - - delete pos2[i] - } + + animations.push({ + type: 'add', + square: i, + piece: pos2[i] + }) + + delete pos2[i] + } // "clear" animations for (i in pos1) { if (!pos1.hasOwnProperty(i)) continue - + // do not clear a piece if it is on a square that is the result // of a "move", ie: a piece capture if (squaresMovedTo.hasOwnProperty(i)) continue - - animations.push({ - type: 'clear', - square: i, - piece: pos1[i] - }) - - delete pos1[i] - } - - return animations - } - + + animations.push({ + type: 'clear', + square: i, + piece: pos1[i] + }) + + delete pos1[i] + } + + return animations + } + // ------------------------------------------------------------------------- // Control Flow // ------------------------------------------------------------------------- - function drawPositionInstant () { + function drawPositionInstant () { // clear the board $board.find('.' + CSS.piece).remove() - + // add the pieces for (var i in currentPosition) { if (!currentPosition.hasOwnProperty(i)) continue - + $('#' + squareElsIds[i]).append(buildPieceHTML(currentPosition[i])) - } - } - - function drawBoard () { + } + } + + function drawBoard () { $board.html(buildBoardHTML(currentOrientation, squareSize, config.showNotation)) - drawPositionInstant() - + drawPositionInstant() + if (config.sparePieces) { if (currentOrientation === 'white') { $sparePiecesTop.html(buildSparePiecesHTML('black')) $sparePiecesBottom.html(buildSparePiecesHTML('white')) - } else { + } else { $sparePiecesTop.html(buildSparePiecesHTML('white')) $sparePiecesBottom.html(buildSparePiecesHTML('black')) - } - } - } + } + } + } - function setCurrentPosition (position) { + function setCurrentPosition (position) { var oldPos = deepCopy(currentPosition) - var newPos = deepCopy(position) - var oldFen = objToFen(oldPos) - var newFen = objToFen(newPos) - + var newPos = deepCopy(position) + var oldFen = objToFen(oldPos) + var newFen = objToFen(newPos) + // do nothing if no change in position - if (oldFen === newFen) return - + if (oldFen === newFen) return + // run their onChange function if (isFunction(config.onChange)) { config.onChange(oldPos, newPos) - } - + } + // update state currentPosition = position - } - - function isXYOnSquare (x, y) { + } + + function isXYOnSquare (x, y) { for (var i in squareElsOffsets) { if (!squareElsOffsets.hasOwnProperty(i)) continue - + var s = squareElsOffsets[i] if (x >= s.left && x < s.left + squareSize && - y >= s.top && + y >= s.top && y < s.top + squareSize) { - return i - } - } - - return 'offboard' - } - + return i + } + } + + return 'offboard' + } + // records the XY coords of every square into memory - function captureSquareOffsets () { + function captureSquareOffsets () { squareElsOffsets = {} - + for (var i in squareElsIds) { if (!squareElsIds.hasOwnProperty(i)) continue - + squareElsOffsets[i] = $('#' + squareElsIds[i]).offset() - } - } - - function removeSquareHighlights () { + } + } + + function removeSquareHighlights () { $board .find('.' + CSS.square) .removeClass(CSS.highlight1 + ' ' + CSS.highlight2) - } - - function snapbackDraggedPiece () { + } + + function snapbackDraggedPiece () { // there is no "snapback" for spare pieces if (draggedPieceSource === 'spare') { - trashDraggedPiece() - return - } - - removeSquareHighlights() - + trashDraggedPiece() + return + } + + removeSquareHighlights() + // animation complete - function complete () { - drawPositionInstant() + function complete () { + drawPositionInstant() $draggedPiece.css('display', 'none') - + // run their onSnapbackEnd function if (isFunction(config.onSnapbackEnd)) { config.onSnapbackEnd( @@ -1206,313 +1206,313 @@ draggedPieceSource, deepCopy(currentPosition), currentOrientation - ) - } - } - + ) + } + } + // get source square position var sourceSquarePosition = $('#' + squareElsIds[draggedPieceSource]).offset() - + // animate the piece to the target square - var opts = { + var opts = { duration: config.snapbackSpeed, - complete: complete - } + complete: complete + } $draggedPiece.animate(sourceSquarePosition, opts) - + // set state isDragging = false - } - - function trashDraggedPiece () { - removeSquareHighlights() - + } + + function trashDraggedPiece () { + removeSquareHighlights() + // remove the source piece var newPosition = deepCopy(currentPosition) delete newPosition[draggedPieceSource] - setCurrentPosition(newPosition) - + setCurrentPosition(newPosition) + // redraw the position - drawPositionInstant() - + drawPositionInstant() + // hide the dragged piece $draggedPiece.fadeOut(config.trashSpeed) - + // set state isDragging = false - } - - function dropDraggedPieceOnSquare (square) { - removeSquareHighlights() - + } + + function dropDraggedPieceOnSquare (square) { + removeSquareHighlights() + // update position var newPosition = deepCopy(currentPosition) delete newPosition[draggedPieceSource] newPosition[square] = draggedPiece - setCurrentPosition(newPosition) - + setCurrentPosition(newPosition) + // get target square information var targetSquarePosition = $('#' + squareElsIds[square]).offset() - + // animation complete function onAnimationComplete () { - drawPositionInstant() + drawPositionInstant() $draggedPiece.css('display', 'none') - + // execute their onSnapEnd function if (isFunction(config.onSnapEnd)) { config.onSnapEnd(draggedPieceSource, square, draggedPiece) - } - } - + } + } + // snap the piece to the target square - var opts = { + var opts = { duration: config.snapSpeed, complete: onAnimationComplete - } + } $draggedPiece.animate(targetSquarePosition, opts) - + // set state isDragging = false - } - - function beginDraggingPiece (source, piece, x, y) { + } + + function beginDraggingPiece (source, piece, x, y) { // run their custom onDragStart function // their custom onDragStart function can cancel drag start if (isFunction(config.onDragStart) && config.onDragStart(source, piece, deepCopy(currentPosition), currentOrientation) === false) { - return - } - + return + } + // set state isDragging = true draggedPiece = piece draggedPieceSource = source - + // if the piece came from spare pieces, location is offboard - if (source === 'spare') { + if (source === 'spare') { draggedPieceLocation = 'offboard' - } else { + } else { draggedPieceLocation = source - } - + } + // capture the x, y coords of all squares in memory - captureSquareOffsets() - + captureSquareOffsets() + // create the dragged piece $draggedPiece.attr('src', buildPieceImgSrc(piece)).css({ - display: '', - position: 'absolute', + display: '', + position: 'absolute', left: x - squareSize / 2, top: y - squareSize / 2 - }) - - if (source !== 'spare') { + }) + + if (source !== 'spare') { // highlight the source square and hide the piece $('#' + squareElsIds[source]) .addClass(CSS.highlight1) .find('.' + CSS.piece) .css('display', 'none') - } - } - - function updateDraggedPiece (x, y) { + } + } + + function updateDraggedPiece (x, y) { // put the dragged piece over the mouse cursor $draggedPiece.css({ left: x - squareSize / 2, top: y - squareSize / 2 - }) - + }) + // get location - var location = isXYOnSquare(x, y) - + var location = isXYOnSquare(x, y) + // do nothing if the location has not changed if (location === draggedPieceLocation) return - + // remove highlight from previous square if (validSquare(draggedPieceLocation)) { $('#' + squareElsIds[draggedPieceLocation]).removeClass(CSS.highlight2) - } - + } + // add highlight to new square if (validSquare(location)) { $('#' + squareElsIds[location]).addClass(CSS.highlight2) - } - + } + // run onDragMove if (isFunction(config.onDragMove)) { config.onDragMove( - location, + location, draggedPieceLocation, draggedPieceSource, draggedPiece, deepCopy(currentPosition), currentOrientation - ) - } - + ) + } + // update state draggedPieceLocation = location - } - - function stopDraggedPiece (location) { + } + + function stopDraggedPiece (location) { // determine what the action should be - var action = 'drop' + var action = 'drop' if (location === 'offboard' && config.dropOffBoard === 'snapback') { - action = 'snapback' - } + action = 'snapback' + } if (location === 'offboard' && config.dropOffBoard === 'trash') { - action = 'trash' - } - + action = 'trash' + } + // run their onDrop function, which can potentially change the drop action if (isFunction(config.onDrop)) { var newPosition = deepCopy(currentPosition) - + // source piece is a spare piece and position is off the board // if (draggedPieceSource === 'spare' && location === 'offboard') {...} // position has not changed; do nothing - + // source piece is a spare piece and position is on the board if (draggedPieceSource === 'spare' && validSquare(location)) { // add the piece to the board newPosition[location] = draggedPiece - } - + } + // source piece was on the board and position is off the board if (validSquare(draggedPieceSource) && location === 'offboard') { // remove the piece from the board delete newPosition[draggedPieceSource] - } - + } + // source piece was on the board and position is on the board if (validSquare(draggedPieceSource) && validSquare(location)) { // move the piece delete newPosition[draggedPieceSource] newPosition[location] = draggedPiece - } - + } + var oldPosition = deepCopy(currentPosition) - + var result = config.onDrop( draggedPieceSource, - location, + location, draggedPiece, - newPosition, - oldPosition, + newPosition, + oldPosition, currentOrientation - ) - if (result === 'snapback' || result === 'trash') { - action = result - } - } - + ) + if (result === 'snapback' || result === 'trash') { + action = result + } + } + // do it! - if (action === 'snapback') { - snapbackDraggedPiece() - } else if (action === 'trash') { - trashDraggedPiece() - } else if (action === 'drop') { - dropDraggedPieceOnSquare(location) - } - } - + if (action === 'snapback') { + snapbackDraggedPiece() + } else if (action === 'trash') { + trashDraggedPiece() + } else if (action === 'drop') { + dropDraggedPieceOnSquare(location) + } + } + // ------------------------------------------------------------------------- // Public Methods // ------------------------------------------------------------------------- - + // clear the board widget.clear = function (useAnimation) { - widget.position({}, useAnimation) + widget.position({}, useAnimation) } - + // remove the widget from the page widget.destroy = function () { // remove markup $container.html('') $draggedPiece.remove() - + // remove event handlers $container.unbind() } - + // shorthand method to get the current FEN - widget.fen = function () { - return widget.position('fen') - } - + widget.fen = function () { + return widget.position('fen') + } + // flip orientation widget.flip = function () { - return widget.orientation('flip') + return widget.orientation('flip') } // move pieces // TODO: this method should be variadic as well as accept an array of moves - widget.move = function () { + widget.move = function () { // no need to throw an error here; just do nothing // TODO: this should return the current position - if (arguments.length === 0) return - - var useAnimation = true - + if (arguments.length === 0) return + + var useAnimation = true + // collect the moves into an object - var moves = {} - for (var i = 0; i < arguments.length; i++) { + 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 - } - + if (arguments[i] === false) { + useAnimation = false + continue + } + // skip invalid arguments if (!validMove(arguments[i])) { - error(2826, 'Invalid move passed to the move method.', arguments[i]) - continue - } - - var tmp = arguments[i].split('-') - moves[tmp[0]] = tmp[1] - } - + error(2826, 'Invalid move passed to the move method.', arguments[i]) + continue + } + + var tmp = arguments[i].split('-') + moves[tmp[0]] = tmp[1] + } + // calculate position from moves var newPos = calculatePositionFromMoves(currentPosition, moves) - + // update the board - widget.position(newPos, useAnimation) - + widget.position(newPos, useAnimation) + // return the new position object - return newPos - } - - widget.orientation = function (arg) { + return newPos + } + + widget.orientation = function (arg) { // no arguments, return the current orientation - if (arguments.length === 0) { + if (arguments.length === 0) { return currentOrientation - } - + } + // set to white or black - if (arg === 'white' || arg === 'black') { + if (arg === 'white' || arg === 'black') { currentOrientation = arg - drawBoard() + drawBoard() return currentOrientation - } - + } + // flip orientation - if (arg === 'flip') { + if (arg === 'flip') { currentOrientation = currentOrientation === 'white' ? 'black' : 'white' - drawBoard() + drawBoard() return currentOrientation - } - - error(5482, 'Invalid value passed to the orientation method.', arg) + } + + error(5482, 'Invalid value passed to the orientation method.', arg) } widget.position = function (position, useAnimation) { // no arguments, return the current position - if (arguments.length === 0) { + if (arguments.length === 0) { return deepCopy(currentPosition) - } - + } + // get position as FEN if (isString(position) && position.toLowerCase() === 'fen') { return objToFen(currentPosition) @@ -1520,19 +1520,19 @@ // start position if (isString(position) && position.toLowerCase() === 'start') { - position = deepCopy(START_POSITION) - } - + position = deepCopy(START_POSITION) + } + // convert FEN to position object if (validFen(position)) { - position = fenToObj(position) - } - + position = fenToObj(position) + } + // validate position object if (!validPositionObject(position)) { - error(6482, 'Invalid value passed to the position method.', position) - return - } + error(6482, 'Invalid value passed to the position method.', position) + return + } // default for useAnimations is true if (useAnimation !== false) useAnimation = true @@ -1541,43 +1541,43 @@ // start the animations var animations = calculateAnimations(currentPosition, position) doAnimations(animations, currentPosition, position) - + // set the new position - setCurrentPosition(position) - } else { + setCurrentPosition(position) + } else { // instant update - setCurrentPosition(position) - drawPositionInstant() - } + setCurrentPosition(position) + drawPositionInstant() + } } widget.resize = function () { // calulate the new square size squareSize = calculateSquareSize() - + // set board width $board.css('width', squareSize * 8 + 'px') - + // set drag piece size $draggedPiece.css({ height: squareSize, width: squareSize - }) - + }) + // spare pieces if (config.sparePieces) { $container .find('.' + CSS.sparePieces) .css('paddingLeft', squareSize + boardBorderSize + 'px') - } - + } + // redraw the board - drawBoard() + drawBoard() } // set the starting position widget.start = function (useAnimation) { - widget.position('start', useAnimation) + widget.position('start', useAnimation) } // ------------------------------------------------------------------------- @@ -1586,8 +1586,8 @@ function stopDefault (evt) { evt.preventDefault() - } - + } + function mousedownSquare (evt) { // do nothing if we're not draggable if (!config.draggable) return @@ -1600,48 +1600,48 @@ beginDraggingPiece(square, currentPosition[square], evt.pageX, evt.pageY) } - function touchstartSquare (e) { + function touchstartSquare (e) { // do nothing if we're not draggable if (!config.draggable) return - + // do nothing if there is no piece on this square var square = $(this).attr('data-square') if (!validSquare(square)) return if (!currentPosition.hasOwnProperty(square)) return - - e = e.originalEvent - beginDraggingPiece( - square, + + e = e.originalEvent + beginDraggingPiece( + square, currentPosition[square], - e.changedTouches[0].pageX, - e.changedTouches[0].pageY - ) - } - + e.changedTouches[0].pageX, + e.changedTouches[0].pageY + ) + } + function mousedownSparePiece (evt) { // do nothing if sparePieces is not enabled if (!config.sparePieces) return - - var piece = $(this).attr('data-piece') - + + var piece = $(this).attr('data-piece') + beginDraggingPiece('spare', piece, evt.pageX, evt.pageY) - } - - function touchstartSparePiece (e) { + } + + function touchstartSparePiece (e) { // do nothing if sparePieces is not enabled if (!config.sparePieces) return - - var piece = $(this).attr('data-piece') - - e = e.originalEvent - beginDraggingPiece( - 'spare', - piece, - e.changedTouches[0].pageX, - e.changedTouches[0].pageY - ) - } - + + var piece = $(this).attr('data-piece') + + e = e.originalEvent + beginDraggingPiece( + 'spare', + piece, + e.changedTouches[0].pageX, + e.changedTouches[0].pageY + ) + } + function mousemoveWindow (evt) { if (isDragging) { updateDraggedPiece(evt.pageX, evt.pageY) @@ -1653,37 +1653,37 @@ function touchmoveWindow (evt) { // do nothing if we are not dragging a piece if (!isDragging) return - + // prevent screen from scrolling evt.preventDefault() - + updateDraggedPiece(evt.originalEvent.changedTouches[0].pageX, evt.originalEvent.changedTouches[0].pageY) - } + } var throttledTouchmoveWindow = throttle(touchmoveWindow, config.dragThrottleRate) function mouseupWindow (evt) { // do nothing if we are not dragging a piece if (!isDragging) return - + // get the location var location = isXYOnSquare(evt.pageX, evt.pageY) - - stopDraggedPiece(location) - } - + + stopDraggedPiece(location) + } + function touchendWindow (evt) { // do nothing if we are not dragging a piece if (!isDragging) return - + // get the location var location = isXYOnSquare(evt.originalEvent.changedTouches[0].pageX, evt.originalEvent.changedTouches[0].pageY) - - stopDraggedPiece(location) - } - + + stopDraggedPiece(location) + } + function mouseenterSquare (evt) { // do not fire this event if we are dragging a piece // NOTE: this should never happen, but it's a safeguard @@ -1691,23 +1691,23 @@ // exit if they did not provide a onMouseoverSquare function if (!isFunction(config.onMouseoverSquare)) return - + // get the square var square = $(evt.currentTarget).attr('data-square') - + // NOTE: this should never happen; defensive if (!validSquare(square)) return - + // get the piece on this square - var piece = false + var piece = false if (currentPosition.hasOwnProperty(square)) { piece = currentPosition[square] - } - + } + // execute their function config.onMouseoverSquare(square, piece, deepCopy(currentPosition), currentOrientation) - } - + } + function mouseleaveSquare (evt) { // do not fire this event if we are dragging a piece // NOTE: this should never happen, but it's a safeguard @@ -1715,35 +1715,35 @@ // exit if they did not provide an onMouseoutSquare function if (!isFunction(config.onMouseoutSquare)) return - + // get the square var square = $(evt.currentTarget).attr('data-square') - + // NOTE: this should never happen; defensive if (!validSquare(square)) return - + // get the piece on this square - var piece = false + var piece = false if (currentPosition.hasOwnProperty(square)) { piece = currentPosition[square] - } - + } + // execute their function config.onMouseoutSquare(square, piece, deepCopy(currentPosition), currentOrientation) - } - + } + // ------------------------------------------------------------------------- // Initialization // ------------------------------------------------------------------------- - function addEvents () { + function addEvents () { // prevent "image drag" $('body').on('mousedown mousemove', '.' + CSS.piece, stopDefault) // mouse drag pieces $board.on('mousedown', '.' + CSS.square, mousedownSquare) $container.on('mousedown', '.' + CSS.sparePieces + ' .' + CSS.piece, mousedownSparePiece) - + // mouse enter / leave square $board .on('mouseenter', '.' + CSS.square, mouseenterSquare) @@ -1754,7 +1754,7 @@ $window .on('mousemove', throttledMousemoveWindow) .on('mouseup', mouseupWindow) - + // touch drag pieces if (isTouchDevice()) { $board.on('touchstart', '.' + CSS.square, touchstartSquare) @@ -1762,24 +1762,24 @@ $window .on('touchmove', throttledTouchmoveWindow) .on('touchend', touchendWindow) - } - } - + } + } + function initDOM () { // create unique IDs for all the elements we will create - createElIds() - + createElIds() + // build board and save it in memory $container.html(buildContainerHTML(config.sparePieces)) $board = $container.find('.' + CSS.board) - + if (config.sparePieces) { $sparePiecesTop = $container.find('.' + CSS.sparePiecesTop) $sparePiecesBottom = $container.find('.' + CSS.sparePiecesBottom) - } - + } + // create the drag piece - var draggedPieceId = uuid() + var draggedPieceId = uuid() $('body').append(buildPieceHTML('wP', true, draggedPieceId)) $draggedPiece = $('#' + draggedPieceId) @@ -1788,10 +1788,10 @@ // get the border size boardBorderSize = parseInt($board.css('borderLeftWidth'), 10) - + // set the size and draw the board - widget.resize() - } + widget.resize() + } // ------------------------------------------------------------------------- // Initialization @@ -1811,10 +1811,10 @@ // support legacy ChessBoard name window['ChessBoard'] = window['Chessboard'] - // expose util functions + // expose util functions window['Chessboard']['fenToObj'] = fenToObj window['Chessboard']['objToFen'] = objToFen -})() // end anonymous wrapper +})() // end anonymous wrapper /* export Chessboard object if using node or any other CommonJS compatible * environment */