- name: 'my-move-list',
- props: ["moves","cursor"], //TODO: other props for e.g. players names + connected indicator
- // --> we could also add turn indicator here
- data: function() {
- return {
- something: "", //TODO?
- };
- },
- // TODO: extend rendering for more than 2 colors: would be a parameter
- // in that case some moves for some colors could be just skipped (if a player lost)
- render(h) {
- if (this.moves.length == 0)
- return;
- const nbColors = 2;
- // TODO: name colors "white", "black", "red", "yellow" ?
- if (this.moves[0].color == "b")
- this.moves.unshift({color: "w", notation: "..."});
- let tableContent = [];
- let moveCounter = 0;
- let tableRow = undefined;
- let moveCells = undefined;
- let curCellContent = "";
- for (let i=0; i<this.moves.length; i++)
- {
- if (this.moves[i].color == "w")
- {
- if (i == 0 || i>0 && this.moves[i-1].color=="b")
- {
- if (!!tableRow)
- {
- tableRow.children = moveCells;
- tableContent.push(tableRow);
- }
- moveCells = [
- h(
- "td",
- { domProps: { innerHTML: (++moveCounter) + "." } }
- )
- ];
- tableRow = h(
- "tr",
- { }
- );
- curCellContent = "";
- }
- }
- curCellContent += this.moves[i].notation;
- if (i < this.moves.length-1 && this.moves[i+1].color == this.moves[i].color)
- curCellContent += ",";
- else //color change
- {
- moveCells.push(
- h(
- "td",
- {
- domProps: { innerHTML: curCellContent },
- on: { click: () => this.gotoMove(i) },
- "class": { "highlight-lm": this.cursor == i },
- }
- )
- );
- curCellContent = "";
- }
- }
- // Complete last row, which might not be full:
- if (moveCells.length-1 < nbColors)
- {
- const delta = nbColors - (moveCells.length-1);
- for (let i=0; i<delta; i++)
- {
- moveCells.push(
- h(
- "td",
- { domProps: { innerHTML: "" } }
- )
- );
- }
- }
- tableRow.children = moveCells;
- tableContent.push(tableRow);
- const movesTable = h(
- "table",
- { },
- tableContent
- );
- return movesTable;
- },
- methods: {
- gotoMove: function(index) {
- this.$emit("goto-move", index);
- },
- },
+ name: "my-move-list",
+ props: ["moves", "show", "cursor", "score", "message", "firstNum"],
+ data: function() {
+ return {
+ st: store.state
+ };
+ },
+ mounted: function() {
+ document.getElementById("adjuster").addEventListener(
+ "click",
+ processModalClick);
+ // Take full width on small screens:
+ let boardSize = parseInt(localStorage.getItem("boardSize"));
+ if (!boardSize) {
+ boardSize =
+ window.innerWidth >= 768
+ ? 0.75 * Math.min(window.innerWidth, window.innerHeight)
+ : window.innerWidth;
+ }
+ const movesWidth = window.innerWidth >= 768 ? 280 : 0;
+ document.getElementById("boardContainer").style.width = boardSize + "px";
+ let gameContainer = document.getElementById("gameContainer");
+ gameContainer.style.width = boardSize + movesWidth + "px";
+ document.getElementById("boardSize").value =
+ (boardSize * 100) / (window.innerWidth - movesWidth);
+ // timeout to avoid calling too many time the adjust method
+ let timeoutLaunched = false;
+ window.addEventListener("resize", () => {
+ if (!timeoutLaunched) {
+ timeoutLaunched = true;
+ setTimeout(() => {
+ this.adjustBoard();
+ timeoutLaunched = false;
+ }, 500);
+ }
+ });
+ },
+ watch: {
+ cursor: function(newCursor) {
+ if (window.innerWidth <= 767) return; //scrolling would hide chessboard
+ // $nextTick to wait for table > tr to be rendered
+ this.$nextTick(() => {
+ let curMove = document.querySelector(".td.highlight-lm");
+ if (curMove) {
+ curMove.scrollIntoView({
+ behavior: "auto",
+ block: "nearest"
+ });
+ }
+ });
+ }
+ },
+ computed: {
+ evenNumbers: function() {
+ return [...Array(this.moves.length).keys()].filter(i => i%2==0);
+ }
+ },
+ methods: {
+ notation: function(move) {
+ return getFullNotation(move);
+ },
+ gotoMove: function(index) {
+ this.$emit("goto-move", index);
+ },
+ adjustBoard: function() {
+ const boardContainer = document.getElementById("boardContainer");
+ if (!boardContainer) return; //no board on page
+ const k = document.getElementById("boardSize").value;
+ const movesWidth = window.innerWidth >= 768 ? 280 : 0;
+ const minBoardWidth = 240; //TODO: these 240 and 280 are arbitrary...
+ // Value of 0 is board min size; 100 is window.width [- movesWidth]
+ const boardSize =
+ minBoardWidth +
+ (k * (window.innerWidth - (movesWidth + minBoardWidth))) / 100;
+ localStorage.setItem("boardSize", boardSize);
+ boardContainer.style.width = boardSize + "px";
+ document.getElementById("gameContainer").style.width =
+ boardSize + movesWidth + "px";
+ }
+ }