Documentation
Config Properties
Property / Type | Required | Default | Description | Example |
---|---|---|---|---|
Boolean | no |
| If | |
| no |
| If If This property has no effect when | |
| no | n/a | If provided, sets the initial position of the board. | |
Function | no | n/a | Fires when the board position changes. The first argument to the function is the old position, the second argument is the new position. Warning: do not call any position-changing methods in your Position-changing methods are: | |
Function | no | n/a | Fires when a piece is picked up. The first argument to the function is the source of the piece, the second argument is the piece, the third argument is the current position on the board, and the fourth argument is the current orientation. The drag action is prevented if the function returns | |
Function | no | n/a | Fires when a dragged piece changes location. The first argument to the function is the new location of the piece, the second argument is the old location of the piece, the third argument is the source of the dragged piece, the fourth argument is the piece, the fifth argument is the current position on the board, and the sixth argument is the current orientation. | |
Function | no | n/a | Fires when a piece is dropped. The first argument to the function is the source of the dragged piece, the second argument is the target of the dragged piece, the third argument is the piece, the fourth argument is the new position once the piece drops, the fifth argument is the old position before the piece was picked up, and the sixth argument is the current orientation. If If | |
Function | no | n/a | Fires when the mouse leaves a square. The first argument to the function is the square that was left, the second argument is the piece on that square (or Note that | |
Function | no | n/a | Fires when the mouse enters a square. The first argument to the function is the square that was entered, the second argument is the piece on that square (or Note that | |
Function | no | n/a | Fires at the end of animations when the board position changes. The first argument to the function is the old position, the second argument is the new position. | |
Function | no | n/a | Fires when the "snapback" animation is complete when pieces are dropped off the board. The first argument to the function is the dragged piece, the second argument is the square the piece returned to, the third argument is the current position, and the fourth argument is the current orientation. | |
Function | no | n/a | Fires when the piece "snap" animation is complete. The first argument to the function is the source of the dragged piece, the second argument is the target of the dragged piece, and the third argument is the piece. | |
| no |
| If provided, sets the initial orientation of the board. | |
Boolean | no |
| Turn board notation on or off. | |
Boolean | no |
| If If | |
| no | n/a |
Every error in Chessboard has a unique code to help diagnose problems and search for solutions. If If If If | |
String or | no |
| A template string used to determine the source of piece images. If The function should return an | |
Number or | no |
| Animation speed for when pieces appear on a square. Note that the "appear" animation only occurs when | |
Number or | no |
| Animation speed for when pieces move between squares or from spare pieces to the board. | |
Number or | no |
| Animation speed for when pieces that were dropped outside the board return to their original square. | |
Number or | no |
| Animation speed for when pieces "snap" to a square when dropped. | |
Number or | no |
| Animation speed for when pieces are removed. |
Methods
Method | Arguments | Description | Example |
---|---|---|---|
| Removes all the pieces on the board. If Alias of | ||
none | Remove the widget from the DOM. | ||
none | Returns the current position as a FEN string. Alias of | ||
none | Flips the board orientation. Alias of | ||
| Executes one or more moves on the board. Returns an updated Position Object of the board including the move(s). | ||
| Returns the current position as a Position Object. If the first argument is | ||
Position Object, FEN string, or
| Animates to a new position. If | ||
none | Returns the current orientation of the board. | ||
| If If | ||
none | Recalculates board and square sizes based on the parent element and redraws the board accordingly. | ||
| Sets the board to the start position. If Alias of |
Position Object
You can use a JavaScript object to represent a board position.
The object property names must be algebraic squares (ie: e4, b2, c6, etc) and the values must be a valid piece codes (ie: wP, bK, wQ, etc).
See an example of using an object to represent a position here.
Xiangqiboard.js exposes the Xiangqiboard.objToFen
method to help convert between Position Objects
and FEN Strings.
FEN String
You can use Forsyth-Edwards Notation (FEN) to represent a board position.
Note that FEN notation captures more information than xiangqiboard.js requires, like who's move it is and whether or not castling is allowed. This information will be ignored; only the position information is used.
See an example of using a FEN String to represent a position here and here.
Xiangqiboard.js exposes the Xiangqiboard.fenToObj
method to help convert a
FEN String to a Position Object.
Errors
Xiangqiboard.js has an error system designed to inform you when you use the API incorrectly.
Every alert has a unique code associated with it and you can control how the errors are presented with the showErrors config option.
Error ID | Error Text | More Information |
---|---|---|
The first argument to | The first argument to the | |
The first argument to | The first argument to the | |
Unable to find a valid version of jQuery. Please include jQuery 1.8.3 or higher on the page. | Chessboard requires jQuery version 1.8.3 or higher. | |
Invalid move passed to the move method. | Moves must be a string in the form of | |
Invalid value passed to the position method. | Position must be either | |
Invalid value passed to config.position | Position must either be | |
Unable to build image source for cfg.pieceTheme. | This is an internal Chessboard error that you should never see. If you see this error please open a GitHub issue. |