-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.html
158 lines (151 loc) · 7.4 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="keywords" content="Chess, Chessboard, Javascript, Play Chess, Javascript Chess, three.js, chessboard.js, chessboard3.js">
<title>chessboard3.js</title>
<link rel="shortcut icon" href="img/favicon.ico" type="image/x-icon" />
<link type="text/css" rel="stylesheet" href="css/site.css">
<link type="text/css" rel="stylesheet" href="css/chessboard.css">
<link type="text/css" rel="stylesheet" href="css/prettyprint.css">
<script type="text/javascript" src="js/jquery-2.1.3.min.js"></script>
<script type="text/javascript" src="js/chessboard.js"></script>
<script type="text/javascript" src="js/three.min.js"></script>
<script type="text/javascript" src="js/OrbitControls.js"></script>
<script type="text/javascript" src="js/chessboard3.js"></script>
<script type="text/javascript" src="js/prettify.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</head>
<body onload="prettyPrint()">
<header id="header">
<h1>chessboard3.js</h1>
<nav>
<ul>
<li><a href="index.html"><input type="button" class="blueButton" value="Home"></a></li>
<li><a href="docs.html"><input type="button" class="blueButton" value="Documentation"></a></li>
<li><a href="play.html"><input type="button" class="blueButton" value="Play"></a></li>
<li><a href="releases/0.1.3/chessboard3js-0.1.3.zip"><input type="button" class="blueButton" value="Download"></a></li>
</ul>
</nav>
</header>
<div class="banner">
<p>Embed a chessboard on your web site in 3D with chessboard3.js, a JavaScript library based on three.js and WebGL.</p>
<p>It mirrors the API of <a href="http://chessboardjs.com">chessboard.js</a>, a 2D board library by <a href="https://github.com/oakmac/chessboardjs">Chris Oakman</a>, so that switching between the two is easy.</p>
</div>
<div class="row">
<div class="leftcol">
<h2>Simplest possible usage:</h2>
<h4>HTML</h4>
<pre class="prettyprint"><div id="board1" style="width: 600px; height: 450px"></div></pre>
<h4>JavaScript</h4>
<pre class="prettyprint">var board1 = new ChessBoard3('board1', 'start');</pre>
<p>
These two lines create a board with default settings, for illustrating the position supplied to the second argument to the constructor- either as a FEN string or 'start' for the starting position.
</p>
</div>
<div class="rightcol">
<div id="board1" style="width: 600px; height: 450px">
<h2 class="vertical-align">LOADING...</h2>
</div>
<p>(By default, pieces are not draggable.)</p>
</div>
</div>
<div class="row">
<div class="leftcol">
<h2>Customization</h2>
<h4>HTML</h4>
<pre class="prettyprint"><div id="board2" style="width: 600px; height: 450px"></div>
<input type="button" id="startBtn" value="Start" />
<input type="button" id="clearBtn" value="Clear" />
<input type="button" id="flipBtn" value="Flip" />
<div id="FEN"></div></pre>
<h4>JavaScript</h4>
<pre class="prettyprint">
var board2 = new ChessBoard3('board2', {
draggable: true,
dropOffBoard: 'trash',
sparePieces: true
onChange: function(oldPos, newPos) {
$("#FEN").text(ChessBoard3.objToFen(newPos));
}
});
$('#startBtn').on('click', board2.start);
$('#clearBtn').on('click', board2.clear);
$('#flipBtn').on('click', board2.flip);</pre>
The second argument can also be a configuration object. Here we let the user set up the board, and see the current position as a FEN string.
</div>
<div class="rightcol">
<div id="board2" style="width: 600px; height: 450px">
<h2 class="vertical-align">LOADING...</h2>
</div>
<input type="button" id="startBtn" value="Start"/>
<input type="button" id="clearBtn" value="Clear"/>
<input type="button" id="flipBtn" value="Flip"/>
<p id="FEN">8/8/8/8/8/8/8/8</p>
<p>Here you can drag pieces onto the board and see the corresponding FEN.</p>
</div>
</div>
<div class="row">
<div class="leftcol">
<h2>Integrating chessboard3.js and chessboard.js</h2>
<h4>HTML</h4>
<pre class="prettyprint"><div id="outer">
<div id="inner"></div>
</div>
<input type="button" id="2D" value="2D"/>
<input type="button" id="3D" value="3D"/>
</pre>
<h4>JavaScript</h4>
<pre class="prettyprint">var sampleConfig =
position: 'start',
draggable : true,
dropOffBoard: 'snapback'
};
var board;
function setUpBoard(dimensions) {
var currentPosition = 'start';
if (board !== undefined) {
currentPosition = board.position();
board.destroy();
}
if (dimensions >= 3) {
$('#inner').css('width', '600px');
$('#inner').css('height', '450px');
$('#outer').css('padding', '');
board = new ChessBoard3('inner', sampleConfig);
} else {
$('#inner').css('width', '450px');
$('#outer').css('height', '450px');
$('#outer').css('padding', '0px 75px 0px 75px');
board = new ChessBoard('inner', sampleConfig);
}
board.position(currentPosition, false);
}
$('#2D').on('click', function() {setUpBoard(2);});
$('#3D').on('click', function() {setUpBoard(3);});
setUpBoard(2); // start with a 2D board
</pre>
</div>
<div class="rightcol">
<div id="outer" style="margin-bottom: 20px">
<div id="inner"></div>
</div>
<input type="button" id="2D" value="2D"/>
<input type="button" id="3D" value="3D"/>
<p style="text-align: left">
You can easily switch between 2D and 3D boards, since chessboard.js and chessboard3.js expose the
same API. You can use chessboard.js as a fallback library, especially if WebGL is not supported
in the browser.
One major difference is in the aspect ratio. While chessboard.js sets the widget height to be equal
to the width in order to make a square widget, chessboard3.js sets its height to 75% of the width
for a 4:3 aspect ratio. This example code fiddles a bit with CSS widths and padding so that the 2D
board doesn't gobble up extra page height when it appears.
</p>
</div>
</div>
<footer id="footer">
<p>Copyright 2016 Jason Tiscione; chessboard3.js is released under the MIT license. The repository for this project is on <a href="https://github.com/jtiscione/chessboard3js">GitHub.</a></p>
<p>Please send questions, comments, criticisms to <i>tiscione@gmail.com.</i></p>
</footer>
</body>
</html>