chessdog is a chess program that runs directly inside your browser. It can easily be embedded into other websites via a simple JavaScript API.
Here is a complete example. Insert this into any HTML page and a chess board will appear:
<div id="board"></div>
<script type="text/javascript" src="http://chessdog.christophdietze.com/chessdog.js"></script>
<script type="text/javascript">
var board = new chessdog.Board(document.getElementById("board"));
</script>
Let's dissect what this does:
-
Create a element where the board should be inserted, e.g.,
<div id="board"></div>
-
Include the chessdog script
<script type="text/javascript" src="http://chessdog.christophdietze.com/chessdog.js"></script>
-
Now, we can use the chessdog JavaScript API to create a chess board at the element. An iframe of a fixed size will be created as the child of the specified element.
<script type="text/javascript"> var board = new chessdog.Board(document.getElementById("board")); </script>
-
Additionally, the API provides the following functions:
board.reset() board.getFen() board.setFen(String fenString) board.getPgn() board.setPgn(String pgnString) board.onReady(function func) board.allowUserMoves(boolean allowed)
In order to build from source you will need sbt v0.11.
git clone [email protected]:thunderklaus/chessdog.git
cd chessdog
sbt package-war
After the build finished successfully, you can open a demo page at ./target/webapp/demo/JackEmbedDemo.html
.
The final war file will be in the target directory ./target/scala_xxx/
.