Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b4e2acb
build single-file examples for website; upgrade jQuery
oakmac Jun 4, 2019
b8ed9d6
fix single-page examples
oakmac Jun 4, 2019
fbcc854
remove php files
oakmac Jun 4, 2019
a7833be
saving state - create build script
oakmac Jun 4, 2019
8dc893c
bump copyright year; add version to files in build script
oakmac Jun 4, 2019
7e285f0
simplify download page
oakmac Jun 5, 2019
a884810
website tweaks
oakmac Jun 5, 2019
eb6fefa
update CHANGELOG for v1.0.0
oakmac Jun 11, 2019
5dcc24d
some cleanup - minor
oakmac Jun 11, 2019
bfa31a0
1.0.0
oakmac Jun 11, 2019
fe99037
link to v1.0.0 CDN on the website
oakmac Jun 11, 2019
5a55072
add license page to website
oakmac Jun 11, 2019
f0d59e7
link to v1.0.0 on the website
oakmac Jun 11, 2019
6f03c2f
add img/ folder to release zip file
oakmac Jun 11, 2019
676a7af
add npm and CDN download links
oakmac Jun 11, 2019
be88c23
Update README.md
cybear Jul 2, 2019
ee584a5
Merge pull request #172 from cybear/patch-1
oakmac Jul 2, 2019
9c3138f
Bump lodash from 4.17.4 to 4.17.14
dependabot[bot] Jul 12, 2019
ed252a3
Merge pull request #173 from oakmac/dependabot/npm_and_yarn/lodash-4.…
oakmac Jul 13, 2019
c2d951f
add common js compatible export
iksarfo Nov 1, 2019
f2b0c89
Merge pull request #181 from ofraski/master
oakmac Nov 1, 2019
0af0d78
Bump lodash from 4.17.14 to 4.17.19 (#192)
dependabot[bot] Aug 1, 2020
86e9716
Bump jquery from 3.4.1 to 3.5.0 (#186)
dependabot[bot] Aug 1, 2020
f093aaf
GitHub Issue #169 - specify jQuery version in README
oakmac Jan 26, 2021
e054420
cleanup README
oakmac Jan 27, 2021
53dcdec
update website
oakmac Jan 27, 2021
62b590f
update favicon for the website
oakmac Mar 29, 2021
13dcae1
use SVG image for King on homepage
oakmac Mar 30, 2021
bfb9315
README updates: project status, add npm + license badges
oakmac Dec 9, 2022
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# git diff files
*.diff

dist/
node_modules/

website/*.html
website/css/chessboard.css
website/js/chessboard.js
website/examples/
7 changes: 7 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
data/
examples/
scripts/
templates/
website/
.editorconfig
changes.diff
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

All notable changes to this project will be documented in this file.

## [Unreleased]
## [1.0.0] - 2019-06-11
- Orientation methods now return current orientation. [Issue #64]
- Drop support for IE8
- Do not check for `window.JSON` (Error #1004)
Expand Down
4 changes: 2 additions & 2 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2013 Chris Oakman
Copyright 2019 Chris Oakman

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand All @@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
68 changes: 32 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
# chessboard.js
# chessboard.js [![npm](https://img.shields.io/npm/v/@chrisoakman/chessboardjs.svg)](https://www.npmjs.com/package/@chrisoakman/chessboardjs) [![MIT License](https://img.shields.io/npm/l/@chrisoakman/chessboardjs)](https://github.com/oakmac/chessboardjs/blob/master/LICENSE.md)

chessboard.js is a JavaScript chessboard component. It depends on [jQuery].
> **NOTE:** chessboard.js can be found on npm as `@chrisoakman/chessboardjs`

chessboard.js is a JavaScript chessboard component. It depends on [jQuery] v3.4.1 (or higher).

Please see [chessboardjs.com] for documentation and examples.

## What is chessboard.js?
## Project Status (Dec 2022)

chessboard.js is a JavaScript chessboard component with a flexible "just a
board" API that
I am currently focusing my efforts on [chessboard2].

[chessboard2]:https://github.com/oakmac/chessboard2

## What is chessboard.js?

chessboard.js is a standalone JavaScript Chess Board. It is designed to be "just
a board" and expose a powerful API so that it can be used in different ways.
Expand All @@ -27,47 +32,38 @@ ease.
## What can chessboard.js **not** do?

The scope of chessboard.js is limited to "just a board." This is intentional and
makes chessboard.js flexible for handling a multitude of chess-related problems.

This is a common source of confusion for new users. [remove?]

Specifically, chessboard.js does not understand anything about how the game of
chess is played: how a knight moves, who's turn is it, is White in check?, etc.
makes chessboard.js flexible for building a variety of chess-related
applications.

Fortunately, the powerful [chess.js] library deals with exactly this sort of
problem domain and plays nicely with chessboard.js's flexible API. Some examples
of chessboard.js combined with chess.js: 5000, 5001, 5002
To be specific, chessboard.js does not understand anything about how the game of
chess is played: how a knight moves, whose turn is it, is White in check?, etc.

Please see the powerful [chess.js] library for an API to deal with these sorts
of questions.
Fortunately, the [chess.js] library deals with exactly this sort of problem and
plays nicely with chessboard.js's flexible API. Some examples of chessboard.js
combined with chess.js: [Example 5000], [Example 5001], [Example 5002]

## Docs and Examples

This logic is distinct from the logic of the board. Please see the powerful
[chess.js] library for this aspect of your application.



Here is a list of things that chessboard.js is **not**:

- A chess engine
- A legal move validator
- A PGN parser
- Docs - <https://chessboardjs.com/docs>
- Examples - <https://chessboardjs.com/examples>

chessboard.js is designed to work well with any of those things, but the idea
behind chessboard.js is that the logic that controls the board should be
independent of those other problems.
## Developer Tools

## Docs and Examples
```sh
# create a build in the build/ directory
npm run build

- Docs - <http://chessboardjs.com/docs>
- Examples - <http://chessboardjs.com/examples>
# re-build the website
npm run website
```

## License

chessboard.js is released under the terms of the [MIT License].
[MIT License](LICENSE.md)

[jQuery]:https://jquery.com/
[chessboardjs.com]:http://chessboardjs.com
[chessboardjs.com]:https://chessboardjs.com
[chess.js]:https://github.com/jhlywa/chess.js
[Example 5000]:http://chessboardjs.com/examples#5000
[MIT License]:LICENSE.md
[Example 5000]:https://chessboardjs.com/examples#5000
[Example 5001]:https://chessboardjs.com/examples#5001
[Example 5002]:https://chessboardjs.com/examples#5002
9 changes: 8 additions & 1 deletion examples/1004-multiple-boards.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ Multiple Boards
===== Description
You can have multiple boards on the same page.

===== HTML
===== CSS
.small-board {
display: inline-block;
margin-right: 5px;
width: 200px;
}

===== HTML
<div id="board1" class="small-board"></div>
<div id="board2" class="small-board"></div>
<div id="board3" class="small-board"></div>
Expand Down
10 changes: 1 addition & 9 deletions src/chessboard.css → lib/chessboard.css
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
/*!
* chessboard.js $version$
*
* Copyright 2013 Chris Oakman
* Released under the MIT license
* https://github.com/oakmac/chessboardjs/blob/master/LICENSE
*
* Date: $date$
*/
/*! chessboard.js v@VERSION | (c) 2019 Chris Oakman | MIT License chessboardjs.com/license */

.clearfix-7da63 {
clear: both;
Expand Down
118 changes: 62 additions & 56 deletions src/chessboard.js → lib/chessboard.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// chessboard.js v@VERSION
// https://github.com/oakmac/chessboardjs/
//
// Copyright (c) 2017, Chris Oakman
// Copyright (c) 2019, Chris Oakman
// Released under the MIT license
// https://github.com/oakmac/chessboardjs/blob/master/LICENSE.md

Expand Down Expand Up @@ -405,22 +405,22 @@

function squeezeFenEmptySquares (fen) {
return fen.replace(/11111111/g, '8')
.replace(/1111111/g, '7')
.replace(/111111/g, '6')
.replace(/11111/g, '5')
.replace(/1111/g, '4')
.replace(/111/g, '3')
.replace(/11/g, '2')
.replace(/1111111/g, '7')
.replace(/111111/g, '6')
.replace(/11111/g, '5')
.replace(/1111/g, '4')
.replace(/111/g, '3')
.replace(/11/g, '2')
}

function expandFenEmptySquares (fen) {
return fen.replace(/8/g, '11111111')
.replace(/7/g, '1111111')
.replace(/6/g, '111111')
.replace(/5/g, '11111')
.replace(/4/g, '1111')
.replace(/3/g, '111')
.replace(/2/g, '11')
.replace(/7/g, '1111111')
.replace(/6/g, '111111')
.replace(/5/g, '11111')
.replace(/4/g, '1111')
.replace(/3/g, '111')
.replace(/2/g, '11')
}

// returns the distance between two squares
Expand Down Expand Up @@ -686,30 +686,30 @@
// -------------------------------------------------------------------------

function error (code, msg, obj) {
// do nothing if showErrors is not set
// do nothing if showErrors is not set
if (
config.hasOwnProperty('showErrors') !== true ||
config.hasOwnProperty('showErrors') !== true ||
config.showErrors === false
) {
) {
return
}

var errorText = 'Chessboard Error ' + code + ': ' + msg

// print to console
// print to console
if (
config.showErrors === 'console' &&
config.showErrors === 'console' &&
typeof console === 'object' &&
typeof console.log === 'function'
) {
) {
console.log(errorText)
if (arguments.length >= 2) {
console.log(obj)
}
return
}

// alert errors
// alert errors
if (config.showErrors === 'alert') {
if (obj) {
errorText += '\n\n' + JSON.stringify(obj)
Expand Down Expand Up @@ -737,10 +737,10 @@
currentPosition = deepCopy(config.position)
} else {
error(
7263,
'Invalid value passed to config.position.',
config.position
)
7263,
'Invalid value passed to config.position.',
config.position
)
}
}
}
Expand Down Expand Up @@ -1202,11 +1202,11 @@
// run their onSnapbackEnd function
if (isFunction(config.onSnapbackEnd)) {
config.onSnapbackEnd(
draggedPiece,
draggedPieceSource,
deepCopy(currentPosition),
currentOrientation
)
draggedPiece,
draggedPieceSource,
deepCopy(currentPosition),
currentOrientation
)
}
}

Expand Down Expand Up @@ -1342,13 +1342,13 @@
// run onDragMove
if (isFunction(config.onDragMove)) {
config.onDragMove(
location,
draggedPieceLocation,
draggedPieceSource,
draggedPiece,
deepCopy(currentPosition),
currentOrientation
)
location,
draggedPieceLocation,
draggedPieceSource,
draggedPiece,
deepCopy(currentPosition),
currentOrientation
)
}

// update state
Expand Down Expand Up @@ -1395,13 +1395,13 @@
var oldPosition = deepCopy(currentPosition)

var result = config.onDrop(
draggedPieceSource,
location,
draggedPiece,
newPosition,
oldPosition,
currentOrientation
)
draggedPieceSource,
location,
draggedPiece,
newPosition,
oldPosition,
currentOrientation
)
if (result === 'snapback' || result === 'trash') {
action = result
}
Expand Down Expand Up @@ -1589,7 +1589,7 @@
}

function mousedownSquare (evt) {
// do nothing if we're not draggable
// do nothing if we're not draggable
if (!config.draggable) return

// do nothing if there is no piece on this square
Expand All @@ -1611,11 +1611,11 @@

e = e.originalEvent
beginDraggingPiece(
square,
currentPosition[square],
e.changedTouches[0].pageX,
e.changedTouches[0].pageY
)
square,
currentPosition[square],
e.changedTouches[0].pageX,
e.changedTouches[0].pageY
)
}

function mousedownSparePiece (evt) {
Expand All @@ -1635,11 +1635,11 @@

e = e.originalEvent
beginDraggingPiece(
'spare',
piece,
e.changedTouches[0].pageX,
e.changedTouches[0].pageY
)
'spare',
piece,
e.changedTouches[0].pageX,
e.changedTouches[0].pageY
)
}

function mousemoveWindow (evt) {
Expand All @@ -1658,7 +1658,7 @@
evt.preventDefault()

updateDraggedPiece(evt.originalEvent.changedTouches[0].pageX,
evt.originalEvent.changedTouches[0].pageY)
evt.originalEvent.changedTouches[0].pageY)
}

var throttledTouchmoveWindow = throttle(touchmoveWindow, config.dragThrottleRate)
Expand All @@ -1679,7 +1679,7 @@

// get the location
var location = isXYOnSquare(evt.originalEvent.changedTouches[0].pageX,
evt.originalEvent.changedTouches[0].pageY)
evt.originalEvent.changedTouches[0].pageY)

stopDraggedPiece(location)
}
Expand Down Expand Up @@ -1815,3 +1815,9 @@
window['Chessboard']['fenToObj'] = fenToObj
window['Chessboard']['objToFen'] = objToFen
})() // end anonymous wrapper

/* export Chessboard object if using node or any other CommonJS compatible
* environment */
if (typeof exports !== 'undefined') {
exports.Chessboard = window.Chessboard
}
Loading