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")
32 @click="$emit('analyze')"
33 :aria-label="st.tr['Analyse']"
35 img.inline(src="/images/icons/analyse.svg")
36 #downloadDiv(v-if="canDownload")
39 @click="$emit('download')"
40 :aria-label="st.tr['Download'] + ' PGN'"
42 img.inline(src="/images/icons/download.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': highlightBlackmove(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")
78 .addEventListener("click", processModalClick);
79 if ("ontouchstart" in window) {
80 // Disable tooltips on smartphones:
81 document.querySelectorAll("#aboveMoves .tooltip").forEach(elt => {
82 elt.classList.remove("tooltip");
85 // Take full width on small screens:
86 let boardSize = parseInt(localStorage.getItem("boardSize"));
89 window.innerWidth >= 768
90 ? 0.75 * Math.min(window.innerWidth, window.innerHeight)
93 const movesWidth = window.innerWidth >= 768 ? 280 : 0;
94 document.getElementById("boardContainer").style.width = boardSize + "px";
95 let gameContainer = document.getElementById("gameContainer");
96 gameContainer.style.width = boardSize + movesWidth + "px";
97 document.getElementById("boardSize").value =
98 (boardSize * 100) / (window.innerWidth - movesWidth);
99 // timeout to avoid calling too many time the adjust method
100 let timeoutLaunched = false;
101 window.addEventListener("resize", () => {
102 if (!timeoutLaunched) {
103 timeoutLaunched = true;
105 setTimeout(() => { timeoutLaunched = false; }, 500);
110 cursor: function(newCursor) {
111 if (window.innerWidth <= 767) return; //scrolling would hide chessboard
112 // $nextTick to wait for table > tr to be rendered
113 this.$nextTick(() => {
114 let curMove = document.querySelector(".td.highlight-lm");
115 if (!curMove && this.moves.length > 0) {
116 // Cursor is before game beginning, and some moves were made:
118 document.querySelector(".moves-list > .tr:first-child > .td");
121 curMove.scrollIntoView({
130 evenNumbers: function() {
131 return [...Array(this.moves.length).keys()].filter(i => i%2==0);
135 notation: function(move) {
136 return getFullNotation(move);
138 highlightBlackmove: function(moveIdx) {
140 this.cursor == moveIdx ||
141 (this.show == "byrow" && this.cursor == moveIdx + 1)
144 gotoMove: function(index) {
145 this.$emit("goto-move", index);
147 adjustBoard: function() {
148 const boardContainer = document.getElementById("boardContainer");
149 if (!boardContainer) return; //no board on page
150 let arrows = document.getElementById("arrowCanvas");
151 // TODO: arrows on board don't scale
152 if (!!arrows) this.$emit("reset-arrows");
153 const k = document.getElementById("boardSize").value;
154 const movesWidth = window.innerWidth >= 768 ? 280 : 0;
155 const minBoardWidth = 240; //TODO: these 240 and 280 are arbitrary...
156 // Value of 0 is board min size; 100 is window.width [- movesWidth]
159 (k * (window.innerWidth - (movesWidth + minBoardWidth))) / 100;
160 localStorage.setItem("boardSize", boardSize);
161 boardContainer.style.width = boardSize + "px";
162 document.getElementById("gameContainer").style.width =
163 boardSize + movesWidth + "px";
169 <style lang="sass" scoped>
176 background-color: white
180 border-bottom: 1px solid lightgrey
190 @media screen and (max-width: 767px)
195 background-color: plum
197 #boardSizeBtnContainer
201 [type="checkbox"]#modalAdjust+div .card
206 @media screen and (max-width: 767px)
211 @media screen and (max-width: 767px)
215 display: inline-block
220 display: inline-block
225 display: inline-block
230 display: inline-block