diff --git a/src/position.js b/src/position.js index b102199..77b57fe 100644 --- a/src/position.js +++ b/src/position.js @@ -910,9 +910,3 @@ Chess.Position.prototype.unmakeMove = function() { return move; }; - -Chess.Position.prototype.getString = function () { - return this.madeMoves.map(function(move) { - return move.getString().trim(); - }).join(" "); -}; diff --git a/src/ui.js b/src/ui.js index 7d0c872..9c41e78 100644 --- a/src/ui.js +++ b/src/ui.js @@ -145,16 +145,6 @@ Chess.UI.prototype.updatePieces = function() { } }; -Chess.UI.prototype.makeMove = function(move) { - this.chessPosition.makeMove(move); - var state = "#" + this.chessPosition.getString().trim(); - if (this.chessPosition.getTurnColor() === Chess.PieceColor.BLACK) { - window.history.pushState(null, move.getString(), state); - } else { - window.history.replaceState(null, move.getString(), state); - } -}; - /** * Adds chessboard cell hover, and chess piece dragging and dropping capabilities to the chessboard */ @@ -223,7 +213,7 @@ Chess.UI.prototype.updateMoves = function() { if (makeMoves.length > 0) { // TODO: it's possible that there is more than one move (promotions). Either ask the user here or have a droplist somewhere ("promote to") - ui.makeMove(makeMoves[0]); + ui.chessPosition.makeMove(makeMoves[0]); ui.updateChessPosition(); } else { // Dropped to an invalid square @@ -256,7 +246,7 @@ Chess.UI.prototype.updateMoves = function() { } else if (id === "auto") { ui.doComputerMove(); } else { - ui.makeMove(moves[parseInt(id, 10)]); + ui.chessPosition.makeMove(moves[parseInt(id, 10)]); ui.updateChessPosition(); } }); @@ -276,7 +266,7 @@ Chess.UI.prototype.doComputerMove = function() { throw new Error("Move not found"); } - ui.makeMove(move); + ui.chessPosition.makeMove(move); var from = $("#" + Chess.getAlgebraicFromIndex(move.getFrom())); var to = $("#" + Chess.getAlgebraicFromIndex(move.getTo())); var dx = (to.offset().left - from.offset().left); @@ -313,23 +303,11 @@ Chess.UI.prototype.updateChessPosition = function() { } }; -Chess.UI.prototype.loadState = function() { - var moves = window.location.href.split('#'); - if (moves.length > 1) { - this.chessPosition = Chess.Parser.parseMoves(moves[1]); - } else { - this.chessPosition = new Chess.Position; - } - this.updateChessPosition(); -}; - /** * Creates a new chessboard and sets up the game at the standard chess initial position. */ function makeChessGame() { Chess.UI.makeBoard(); var ui = new Chess.UI; - ui.loadState(); ui.updateChessPosition(); - window.onpopstate = ui.loadState.bind(ui); }