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 onClick="window.doClick('modalAdjust')"
27 :aria-label="st.tr['Resize board']"
29 img.inline(src="/images/icons/resize.svg")
30 #downloadDiv(v-if="canDownload")
33 @click="$emit('download')"
34 :aria-label="st.tr['Download'] + ' PGN'"
36 img.inline(src="/images/icons/download.svg")
39 @click="$emit('analyze')"
40 :aria-label="st.tr['Analyse']"
42 img.inline(src="/images/icons/analyse.svg")
43 #scoreInfo(v-if="score!='*'")
44 span.score {{ score }}
45 span.score-msg {{ st.tr[message] }}
46 .moves-list(v-if="!['none','highlight'].includes(show)")
47 .tr(v-for="moveIdx in evenNumbers")
48 .td {{ firstNum + moveIdx / 2 + 1 }}
49 .td(v-if="moveIdx < moves.length-1 || show == 'all'"
50 :class="{'highlight-lm': cursor == moveIdx}"
51 @click="() => gotoMove(moveIdx)"
53 | {{ notation(moves[moveIdx]) }}
55 v-if="moveIdx < moves.length-1"
56 :class="{'highlight-lm': cursor == moveIdx+1}"
57 @click="() => gotoMove(moveIdx+1)"
59 | {{ notation(moves[moveIdx+1]) }}
63 import { store } from "@/store";
64 import { getFullNotation } from "@/utils/notation";
65 import { processModalClick } from "@/utils/modalClick";
69 "moves", "show", "canAnalyze", "canDownload",
70 "cursor", "score", "message", "firstNum"],
77 document.getElementById("adjuster").addEventListener(
80 // Take full width on small screens:
81 let boardSize = parseInt(localStorage.getItem("boardSize"));
84 window.innerWidth >= 768
85 ? 0.75 * Math.min(window.innerWidth, window.innerHeight)
88 const movesWidth = window.innerWidth >= 768 ? 280 : 0;
89 document.getElementById("boardContainer").style.width = boardSize + "px";
90 let gameContainer = document.getElementById("gameContainer");
91 gameContainer.style.width = boardSize + movesWidth + "px";
92 document.getElementById("boardSize").value =
93 (boardSize * 100) / (window.innerWidth - movesWidth);
94 // timeout to avoid calling too many time the adjust method
95 let timeoutLaunched = false;
96 window.addEventListener("resize", () => {
97 if (!timeoutLaunched) {
98 timeoutLaunched = true;
101 timeoutLaunched = false;
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:
114 curMove = document.querySelector(".moves-list > .tr:first-child > .td");
116 curMove.scrollIntoView({
125 evenNumbers: function() {
126 return [...Array(this.moves.length).keys()].filter(i => i%2==0);
130 notation: function(move) {
131 return getFullNotation(move);
133 gotoMove: function(index) {
134 this.$emit("goto-move", index);
136 adjustBoard: function() {
137 const boardContainer = document.getElementById("boardContainer");
138 if (!boardContainer) return; //no board on page
139 const k = document.getElementById("boardSize").value;
140 const movesWidth = window.innerWidth >= 768 ? 280 : 0;
141 const minBoardWidth = 240; //TODO: these 240 and 280 are arbitrary...
142 // Value of 0 is board min size; 100 is window.width [- movesWidth]
145 (k * (window.innerWidth - (movesWidth + minBoardWidth))) / 100;
146 localStorage.setItem("boardSize", boardSize);
147 boardContainer.style.width = boardSize + "px";
148 document.getElementById("gameContainer").style.width =
149 boardSize + movesWidth + "px";
155 <style lang="sass" scoped>
161 background-color: white
165 border-bottom: 1px solid lightgrey
175 @media screen and (max-width: 767px)
180 background-color: plum
182 #boardSizeBtnContainer
186 [type="checkbox"]#modalAdjust+div .card
191 @media screen and (max-width: 767px)
196 @media screen and (max-width: 767px)
200 display: inline-block
205 display: inline-block
210 display: inline-block
215 display: inline-block