3 input#modalAdjust.modal(type="checkbox")
6 data-checkbox="modalAdjust"
9 label.modal-close(for="modalAdjust")
10 label(for="boardSize") {{ st.tr["Board size"] }}
11 input#boardSize.slider(
16 @input="adjustBoard()"
19 // NOTE: variants pages already have a "Rules" link on top
21 v-if="!$route.path.match('/variants/')"
22 @click="$emit('showrules')"
24 | {{ st.tr["Rules"] }}
26 :class="btnTooltipClass()"
27 onClick="window.doClick('modalAdjust')"
28 :aria-label="st.tr['Resize board']"
30 img.inline(src="/images/icons/resize.svg")
33 :class="btnTooltipClass()"
34 @click="$emit('analyze')"
35 :aria-label="st.tr['Analyse']"
37 img.inline(src="/images/icons/analyse.svg")
38 #downloadDiv(v-if="canDownload")
41 :class="btnTooltipClass()"
42 @click="$emit('download')"
43 :aria-label="st.tr['Download'] + ' PGN'"
45 img.inline(src="/images/icons/download.svg")
46 #scoreInfo(v-if="score!='*'")
47 span.score {{ score }}
48 span.score-msg {{ st.tr[message] }}
49 .moves-list(v-if="!['none','highlight'].includes(show)")
50 .tr(v-for="moveIdx in evenNumbers")
51 .td {{ firstNum + moveIdx / 2 }}
52 .td(v-if="moveIdx < moves.length-1 || show == 'all'"
53 :class="{'highlight-lm': cursor == moveIdx}"
54 @click="() => gotoMove(moveIdx)"
56 | {{ notation(moves[moveIdx]) }}
58 v-if="moveIdx < moves.length-1"
59 :class="{'highlight-lm': highlightBlackmove(moveIdx+1)}"
60 @click="() => gotoMove(moveIdx+1)"
62 | {{ notation(moves[moveIdx + 1]) }}
66 import { store } from "@/store";
67 import { getFullNotation } from "@/utils/notation";
68 import { processModalClick } from "@/utils/modalClick";
72 "moves", "show", "canAnalyze", "canDownload",
73 "cursor", "score", "message", "firstNum"],
80 document.getElementById("adjuster")
81 .addEventListener("click", processModalClick);
82 // Take full width on small screens:
83 let boardSize = parseInt(localStorage.getItem("boardSize"));
86 window.innerWidth >= 768
87 ? 0.75 * Math.min(window.innerWidth, window.innerHeight)
90 const movesWidth = window.innerWidth >= 768 ? 280 : 0;
91 document.getElementById("boardContainer").style.width = boardSize + "px";
92 let gameContainer = document.getElementById("gameContainer");
93 gameContainer.style.width = boardSize + movesWidth + "px";
94 document.getElementById("boardSize").value =
95 (boardSize * 100) / (window.innerWidth - movesWidth);
96 // timeout to avoid calling too many time the adjust method
97 let timeoutLaunched = false;
98 window.addEventListener("resize", () => {
99 if (!timeoutLaunched) {
100 timeoutLaunched = true;
102 setTimeout(() => { timeoutLaunched = false; }, 500);
107 cursor: function(newCursor) {
108 if (window.innerWidth <= 767) return; //scrolling would hide chessboard
109 // $nextTick to wait for table > tr to be rendered
110 this.$nextTick(() => {
111 let curMove = document.querySelector(".td.highlight-lm");
112 if (!curMove && this.moves.length > 0) {
113 // Cursor is before game beginning, and some moves were made:
115 document.querySelector(".moves-list > .tr:first-child > .td");
118 curMove.scrollIntoView({
127 evenNumbers: function() {
128 return [...Array(this.moves.length).keys()].filter(i => i%2==0);
132 notation: function(move) {
133 return getFullNotation(move);
135 highlightBlackmove: function(moveIdx) {
137 this.cursor == moveIdx ||
139 // If display by rows, hightlight last black move while the white
140 // move is being played:
141 this.show == "byrow" &&
142 this.cursor == moveIdx + 1 &&
143 // ...except if cursor is behind in the game:
144 this.cursor == this.moves.length - 1
148 btnTooltipClass: function() {
149 return { tooltip: !("ontouchstart" in window) };
151 gotoMove: function(index) {
152 this.$emit("goto-move", index);
154 adjustBoard: function() {
155 const boardContainer = document.getElementById("boardContainer");
156 if (!boardContainer) return; //no board on page
157 let arrows = document.getElementById("arrowCanvas");
158 // TODO: arrows on board don't scale
159 if (!!arrows) this.$emit("reset-arrows");
160 const k = document.getElementById("boardSize").value;
161 const movesWidth = window.innerWidth >= 768 ? 280 : 0;
162 const minBoardWidth = 240; //TODO: these 240 and 280 are arbitrary...
163 // Value of 0 is board min size; 100 is window.width [- movesWidth]
166 (k * (window.innerWidth - (movesWidth + minBoardWidth))) / 100;
167 localStorage.setItem("boardSize", boardSize);
168 boardContainer.style.width = boardSize + "px";
169 document.getElementById("gameContainer").style.width =
170 boardSize + movesWidth + "px";
176 <style lang="sass" scoped>
183 background-color: white
187 border-bottom: 1px solid lightgrey
197 @media screen and (max-width: 767px)
202 background-color: plum
204 #boardSizeBtnContainer
208 [type="checkbox"]#modalAdjust+div .card
213 @media screen and (max-width: 767px)
218 @media screen and (max-width: 767px)
222 display: inline-block
227 display: inline-block
232 display: inline-block
237 display: inline-block
244 background-color: #50E99A