Commit | Line | Data |
---|---|---|
e71161fb BA |
1 | <template lang="pug"> |
2 | div | |
5b3dc10e BA |
3 | input#modalAdjust.modal(type="checkbox") |
4 | div#adjuster( | |
5 | role="dialog" | |
6 | data-checkbox="modalAdjust" | |
7 | ) | |
8 | .card.text-center | |
9 | label.modal-close(for="modalAdjust") | |
10 | label(for="boardSize") {{ st.tr["Board size"] }} | |
11 | input#boardSize.slider( | |
12 | type="range" | |
13 | min="0" | |
14 | max="100" | |
15 | value="50" | |
16 | @input="adjustBoard()" | |
17 | ) | |
feaf1bf7 BA |
18 | #aboveMoves |
19 | // NOTE: variants pages already have a "Rules" link on top | |
20 | span#rulesBtn( | |
21 | v-if="!$route.path.match('/variants/')" | |
57078452 BA |
22 | @click="clickRulesBtn()" |
23 | :class="btnRulesClass" | |
feaf1bf7 BA |
24 | ) |
25 | | {{ st.tr["Rules"] }} | |
1e02d16d | 26 | button( |
659a9bd2 | 27 | :class="btnTooltipClass()" |
feaf1bf7 BA |
28 | onClick="window.doClick('modalAdjust')" |
29 | :aria-label="st.tr['Resize board']" | |
30 | ) | |
31 | img.inline(src="/images/icons/resize.svg") | |
1e02d16d BA |
32 | button#analyzeBtn( |
33 | v-if="canAnalyze" | |
659a9bd2 | 34 | :class="btnTooltipClass()" |
b83a675a BA |
35 | @click="$emit('analyze')" |
36 | :aria-label="st.tr['Analyse']" | |
37 | ) | |
38 | img.inline(src="/images/icons/analyse.svg") | |
feaf1bf7 BA |
39 | #downloadDiv(v-if="canDownload") |
40 | a#download(href="#") | |
1e02d16d | 41 | button( |
659a9bd2 | 42 | :class="btnTooltipClass()" |
feaf1bf7 BA |
43 | @click="$emit('download')" |
44 | :aria-label="st.tr['Download'] + ' PGN'" | |
45 | ) | |
46 | img.inline(src="/images/icons/download.svg") | |
e71161fb | 47 | #scoreInfo(v-if="score!='*'") |
feaf1bf7 BA |
48 | span.score {{ score }} |
49 | span.score-msg {{ st.tr[message] }} | |
90df90bc | 50 | .moves-list |
e71161fb | 51 | .tr(v-for="moveIdx in evenNumbers") |
fef153df | 52 | .td {{ firstNum + moveIdx / 2 }} |
90df90bc | 53 | .td( |
e71161fb BA |
54 | :class="{'highlight-lm': cursor == moveIdx}" |
55 | @click="() => gotoMove(moveIdx)" | |
56 | ) | |
90df90bc | 57 | | {{ notation(moveIdx) }} |
e71161fb BA |
58 | .td( |
59 | v-if="moveIdx < moves.length-1" | |
90df90bc | 60 | :class="{'highlight-lm': cursor == moveIdx+1}" |
e71161fb BA |
61 | @click="() => gotoMove(moveIdx+1)" |
62 | ) | |
90df90bc | 63 | | {{ notation(moveIdx + 1) }} |
e71161fb BA |
64 | </template> |
65 | ||
cf2343ce | 66 | <script> |
fcd299a3 | 67 | import { store } from "@/store"; |
e71161fb | 68 | import { getFullNotation } from "@/utils/notation"; |
5b3dc10e | 69 | import { processModalClick } from "@/utils/modalClick"; |
cf2343ce | 70 | export default { |
6808d7a1 | 71 | name: "my-move-list", |
feaf1bf7 BA |
72 | props: [ |
73 | "moves", "show", "canAnalyze", "canDownload", | |
57078452 | 74 | "vname", "cursor", "score", "message", "firstNum"], |
311cba76 BA |
75 | data: function() { |
76 | return { | |
77 | st: store.state | |
78 | }; | |
79 | }, | |
5b3dc10e | 80 | mounted: function() { |
42a92848 BA |
81 | document.getElementById("adjuster") |
82 | .addEventListener("click", processModalClick); | |
5b3dc10e BA |
83 | // Take full width on small screens: |
84 | let boardSize = parseInt(localStorage.getItem("boardSize")); | |
85 | if (!boardSize) { | |
86 | boardSize = | |
87 | window.innerWidth >= 768 | |
88 | ? 0.75 * Math.min(window.innerWidth, window.innerHeight) | |
89 | : window.innerWidth; | |
90 | } | |
91 | const movesWidth = window.innerWidth >= 768 ? 280 : 0; | |
92 | document.getElementById("boardContainer").style.width = boardSize + "px"; | |
93 | let gameContainer = document.getElementById("gameContainer"); | |
94 | gameContainer.style.width = boardSize + movesWidth + "px"; | |
95 | document.getElementById("boardSize").value = | |
96 | (boardSize * 100) / (window.innerWidth - movesWidth); | |
107dc1bd BA |
97 | window.addEventListener("resize", this.adjustBoard); |
98 | }, | |
99 | beforeDestroy: function() { | |
100 | window.removeEventListener("resize", this.adjustBoard); | |
5b3dc10e | 101 | }, |
c6b8d37f BA |
102 | watch: { |
103 | cursor: function(newCursor) { | |
104 | if (window.innerWidth <= 767) return; //scrolling would hide chessboard | |
c6b8d37f BA |
105 | // $nextTick to wait for table > tr to be rendered |
106 | this.$nextTick(() => { | |
3c186115 | 107 | let curMove = document.querySelector(".td.highlight-lm"); |
2c5d7b20 | 108 | if (!curMove && this.moves.length > 0) { |
c51c301f | 109 | // Cursor is before game beginning, and some moves were made: |
2c5d7b20 BA |
110 | curMove = |
111 | document.querySelector(".moves-list > .tr:first-child > .td"); | |
112 | } | |
3c186115 BA |
113 | if (!!curMove) { |
114 | curMove.scrollIntoView({ | |
c6b8d37f BA |
115 | behavior: "auto", |
116 | block: "nearest" | |
117 | }); | |
118 | } | |
119 | }); | |
120 | } | |
121 | }, | |
e71161fb BA |
122 | computed: { |
123 | evenNumbers: function() { | |
124 | return [...Array(this.moves.length).keys()].filter(i => i%2==0); | |
57078452 BA |
125 | }, |
126 | btnRulesClass: function() { | |
127 | // "rr" for "rules read" | |
128 | return { highlightRules: !localStorage.getItem("rr_" + this.vname) }; | |
e71161fb BA |
129 | } |
130 | }, | |
430a2038 | 131 | methods: { |
90df90bc BA |
132 | notation: function(moveIdx) { |
133 | const move = this.moves[moveIdx]; | |
134 | if (this.score != "*") return getFullNotation(move); | |
135 | if ( | |
136 | ['none','highlight'].includes(this.show) || | |
e6bcc1d8 | 137 | ( |
e6bcc1d8 | 138 | this.show == "byrow" && |
90df90bc BA |
139 | moveIdx == this.moves.length-1 && |
140 | moveIdx % 2 == 0 | |
e6bcc1d8 | 141 | ) |
90df90bc BA |
142 | ) { |
143 | return "?"; | |
144 | } | |
145 | return getFullNotation(move); | |
08a5069c | 146 | }, |
1e02d16d BA |
147 | btnTooltipClass: function() { |
148 | return { tooltip: !("ontouchstart" in window) }; | |
149 | }, | |
57078452 BA |
150 | clickRulesBtn: function() { |
151 | const key = "rr_" + this.vname; | |
152 | if (!localStorage.getItem(key)) { | |
153 | localStorage.setItem(key, '1'); | |
154 | document.getElementById("rulesBtn").classList.remove("highlightRules"); | |
155 | } | |
156 | this.$emit("showrules"); | |
157 | }, | |
dac39588 | 158 | gotoMove: function(index) { |
107dc1bd BA |
159 | // Goto move except if click on current move: |
160 | if (this.cursor != index) this.$emit("goto-move", index); | |
5b3dc10e BA |
161 | }, |
162 | adjustBoard: function() { | |
163 | const boardContainer = document.getElementById("boardContainer"); | |
164 | if (!boardContainer) return; //no board on page | |
165 | const k = document.getElementById("boardSize").value; | |
166 | const movesWidth = window.innerWidth >= 768 ? 280 : 0; | |
167 | const minBoardWidth = 240; //TODO: these 240 and 280 are arbitrary... | |
168 | // Value of 0 is board min size; 100 is window.width [- movesWidth] | |
169 | const boardSize = | |
170 | minBoardWidth + | |
171 | (k * (window.innerWidth - (movesWidth + minBoardWidth))) / 100; | |
172 | localStorage.setItem("boardSize", boardSize); | |
173 | boardContainer.style.width = boardSize + "px"; | |
174 | document.getElementById("gameContainer").style.width = | |
175 | boardSize + movesWidth + "px"; | |
107dc1bd | 176 | this.$emit("redraw-board"); |
6808d7a1 BA |
177 | } |
178 | } | |
430a2038 BA |
179 | }; |
180 | </script> | |
181 | ||
182 | <style lang="sass" scoped> | |
183 | .moves-list | |
28b32b4f | 184 | user-select: none |
8477e53d BA |
185 | cursor: pointer |
186 | min-height: 1px | |
187 | max-height: 500px | |
188 | overflow: auto | |
189 | background-color: white | |
190 | width: 280px | |
191 | & > .tr | |
192 | clear: both | |
193 | border-bottom: 1px solid lightgrey | |
194 | & > .td | |
195 | float: left | |
f9c36b2d | 196 | padding: 2% 0 2% 2% |
8477e53d BA |
197 | &:first-child |
198 | color: grey | |
f9c36b2d | 199 | width: 13% |
8477e53d | 200 | &:not(first-child) |
f9c36b2d | 201 | width: 40.5% |
8477e53d BA |
202 | |
203 | @media screen and (max-width: 767px) | |
204 | .moves-list | |
205 | width: 100% | |
910d631b | 206 | |
8477e53d | 207 | .td.highlight-lm |
430a2038 | 208 | background-color: plum |
5b3dc10e | 209 | |
57078452 BA |
210 | .highlightRules |
211 | padding: 3px 5px | |
212 | background-color: yellow | |
213 | ||
5b3dc10e BA |
214 | #boardSizeBtnContainer |
215 | width: 100% | |
216 | text-align: center | |
217 | ||
5b3dc10e BA |
218 | [type="checkbox"]#modalAdjust+div .card |
219 | padding: 5px | |
feaf1bf7 BA |
220 | |
221 | img.inline | |
54ec15eb | 222 | height: 22px |
feaf1bf7 BA |
223 | @media screen and (max-width: 767px) |
224 | height: 18px | |
225 | ||
0cc44e58 BA |
226 | #scoreInfo |
227 | margin: 10px 0 | |
228 | @media screen and (max-width: 767px) | |
229 | margin: 5px 0 | |
230 | ||
feaf1bf7 BA |
231 | span.score |
232 | display: inline-block | |
233 | margin-left: 10px | |
234 | font-weight: bold | |
235 | ||
236 | span.score-msg | |
237 | display: inline-block | |
238 | margin-left: 10px | |
239 | font-style: italic | |
240 | ||
241 | #downloadDiv | |
242 | display: inline-block | |
243 | margin: 0 | |
244 | ||
245 | span#rulesBtn | |
246 | cursor: pointer | |
247 | display: inline-block | |
248 | margin: 0 10px | |
249 | font-weight: bold | |
250 | ||
251 | button | |
252 | margin: 0 | |
07052665 | 253 | &.active |
236485b5 | 254 | background-color: #48C9B0 |
5b4de147 | 255 | |
42a92848 | 256 | #aboveMoves button |
5b4de147 | 257 | padding-bottom: 5px |
430a2038 | 258 | </style> |