2 import { store } from "@/store";
5 props: ["moves", "show", "cursor", "score", "message", "firstNum"],
6 // TODO: if show == "byrows", show only full rows.
9 if (!!this.score && this.score != "*") {
15 display: this.score != "*" ? "block" : "none"
18 [h("p", this.score), h("p", store.state.tr[this.message])]
20 rootElements.push(scoreDiv);
22 if (this.moves.length > 0) {
23 let tableContent = [];
25 let tableRow = undefined;
26 let moveCells = undefined;
27 let curCellContent = "";
29 for (let i = 0; i < this.moves.length; i++) {
30 if (this.moves[i].color == "w") {
31 if (i == 0 || (i > 0 && this.moves[i - 1].color == "b")) {
33 tableRow.children = moveCells;
34 tableContent.push(tableRow);
41 domProps: { innerHTML: ++moveCounter + "." }
45 tableRow = h("div", {"class": {tr: true}});
50 // Next condition is fine because even if the first move is black,
51 // there will be the "..." which count as white move.
52 else if (this.moves[i].color == "b" && this.moves[i - 1].color == "w")
54 curCellContent += this.moves[i].notation;
56 i < this.moves.length - 1 &&
57 this.moves[i + 1].color == this.moves[i].color
59 curCellContent += ",";
68 "highlight-lm": this.cursor >= firstIndex && this.cursor <= i
70 domProps: { innerHTML: curCellContent },
71 on: { click: () => this.gotoMove(i) }
78 // Complete last row, which might not be full:
79 if (moveCells.length - 1 == 1) {
80 moveCells.push(h("div", {"class": {td: true}}));
82 tableRow.children = moveCells;
83 tableContent.push(tableRow);
96 return h("div", {}, rootElements);
99 cursor: function(newCursor) {
100 if (window.innerWidth <= 767) return; //scrolling would hide chessboard
101 // $nextTick to wait for table > tr to be rendered
102 this.$nextTick(() => {
103 let curMove = document.querySelector(".td.highlight-lm");
105 curMove.scrollIntoView({
114 gotoMove: function(index) {
115 this.$emit("goto-move", index);
121 <style lang="sass" scoped>
127 background-color: white
131 border-bottom: 1px solid lightgrey
141 @media screen and (max-width: 767px)
146 background-color: plum