Commit | Line | Data |
---|---|---|
cf2343ce | 1 | <script> |
fcd299a3 | 2 | import { store } from "@/store"; |
cf2343ce | 3 | export default { |
6808d7a1 BA |
4 | name: "my-move-list", |
5 | props: ["moves", "cursor", "score", "message", "firstNum"], | |
dac39588 | 6 | render(h) { |
5fde3a01 | 7 | let rootElements = []; |
6808d7a1 BA |
8 | if (!!this.score && this.score != "*") { |
9 | const scoreDiv = h( | |
10 | "div", | |
144c9003 | 11 | { |
5fde3a01 BA |
12 | id: "scoreInfo", |
13 | style: { | |
6808d7a1 BA |
14 | display: this.score != "*" ? "block" : "none" |
15 | } | |
5fde3a01 | 16 | }, |
6808d7a1 | 17 | [h("p", this.score), h("p", store.state.tr[this.message])] |
5fde3a01 BA |
18 | ); |
19 | rootElements.push(scoreDiv); | |
20 | } | |
8477e53d BA |
21 | if (this.moves.length > 0) { |
22 | let tableContent = []; | |
23 | let moveCounter = 0; | |
24 | let tableRow = undefined; | |
25 | let moveCells = undefined; | |
26 | let curCellContent = ""; | |
27 | let firstIndex = 0; | |
28 | for (let i = 0; i < this.moves.length; i++) { | |
29 | if (this.moves[i].color == "w") { | |
30 | if (i == 0 || (i > 0 && this.moves[i - 1].color == "b")) { | |
31 | if (tableRow) { | |
32 | tableRow.children = moveCells; | |
33 | tableContent.push(tableRow); | |
34 | } | |
35 | moveCells = [ | |
36 | h( | |
37 | "div", | |
38 | { | |
39 | "class": {td: true}, | |
40 | domProps: { innerHTML: ++moveCounter + "." } | |
41 | } | |
42 | ) | |
43 | ]; | |
44 | tableRow = h("div", {"class": {tr: true}}); | |
45 | curCellContent = ""; | |
46 | firstIndex = i; | |
6808d7a1 | 47 | } |
8477e53d BA |
48 | } |
49 | // Next condition is fine because even if the first move is black, | |
50 | // there will be the "..." which count as white move. | |
51 | else if (this.moves[i].color == "b" && this.moves[i - 1].color == "w") | |
52 | firstIndex = i; | |
53 | curCellContent += this.moves[i].notation; | |
54 | if ( | |
55 | i < this.moves.length - 1 && | |
56 | this.moves[i + 1].color == this.moves[i].color | |
57 | ) | |
58 | curCellContent += ","; | |
59 | else { | |
60 | // Color change | |
61 | moveCells.push( | |
62 | h( | |
63 | "div", | |
64 | { | |
65 | "class": { | |
66 | td: true, | |
67 | "highlight-lm": this.cursor >= firstIndex && this.cursor <= i | |
68 | }, | |
69 | domProps: { innerHTML: curCellContent }, | |
70 | on: { click: () => this.gotoMove(i) } | |
71 | } | |
72 | ) | |
73 | ); | |
74 | curCellContent = ""; | |
75 | } | |
76 | } | |
77 | // Complete last row, which might not be full: | |
78 | if (moveCells.length - 1 == 1) { | |
79 | moveCells.push(h("div", {"class": {td: true}})); | |
80 | } | |
81 | tableRow.children = moveCells; | |
82 | tableContent.push(tableRow); | |
83 | rootElements.push( | |
84 | h( | |
85 | "div", | |
86 | { | |
87 | class: { | |
88 | "moves-list": true | |
89 | } | |
90 | }, | |
91 | tableContent | |
92 | ) | |
93 | ); | |
94 | } | |
6808d7a1 | 95 | return h("div", {}, rootElements); |
dac39588 | 96 | }, |
c6b8d37f BA |
97 | watch: { |
98 | cursor: function(newCursor) { | |
99 | if (window.innerWidth <= 767) return; //scrolling would hide chessboard | |
c6b8d37f BA |
100 | // $nextTick to wait for table > tr to be rendered |
101 | this.$nextTick(() => { | |
8477e53d BA |
102 | let curMove = document.querySelector(".td.highlight-lm"); |
103 | if (curMove) { | |
104 | curMove.scrollIntoView({ | |
c6b8d37f BA |
105 | behavior: "auto", |
106 | block: "nearest" | |
107 | }); | |
108 | } | |
109 | }); | |
110 | } | |
111 | }, | |
430a2038 | 112 | methods: { |
dac39588 BA |
113 | gotoMove: function(index) { |
114 | this.$emit("goto-move", index); | |
6808d7a1 BA |
115 | } |
116 | } | |
430a2038 BA |
117 | }; |
118 | </script> | |
119 | ||
120 | <style lang="sass" scoped> | |
121 | .moves-list | |
8477e53d BA |
122 | cursor: pointer |
123 | min-height: 1px | |
124 | max-height: 500px | |
125 | overflow: auto | |
126 | background-color: white | |
127 | width: 280px | |
128 | & > .tr | |
129 | clear: both | |
130 | border-bottom: 1px solid lightgrey | |
131 | & > .td | |
132 | float: left | |
133 | padding: 2% 0 2% 1% | |
134 | &:first-child | |
135 | color: grey | |
136 | width: 15% | |
137 | &:not(first-child) | |
138 | width: 41% | |
139 | ||
140 | @media screen and (max-width: 767px) | |
141 | .moves-list | |
142 | width: 100% | |
910d631b | 143 | |
8477e53d | 144 | .td.highlight-lm |
430a2038 BA |
145 | background-color: plum |
146 | </style> |