-//------------------------------------------------------------------------------
-// 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() {
- var containerWidth = parseInt(getComputedStyle(containerEl).width, 10);
-
- // defensive, prevent infinite loop
- if (! containerWidth || containerWidth <= 0) {
- return 0;
- }
-
- // pad one pixel
- var boardWidth = containerWidth - 1;
-
- while (boardWidth % 8 !== 0 && boardWidth > 0) {
- boardWidth--;
- }
-
- 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;
- SQUARE_ELS_IDS[square] = square + '-' + createId();
- }
- }
-
- // spare pieces
- var pieces = 'KQRBNP'.split('');
- for (var i = 0; i < pieces.length; i++) {
- var whitePiece = 'w' + pieces[i];
- var blackPiece = 'b' + pieces[i];
- SPARE_PIECE_ELS_IDS[whitePiece] = whitePiece + '-' + createId();
- SPARE_PIECE_ELS_IDS[blackPiece] = blackPiece + '-' + createId();
- }
-}
-