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 window.addEventListener("resize", this.adjustBoard);
98 beforeDestroy: function() {
99 window.removeEventListener("resize", this.adjustBoard);
102 cursor: function(newCursor) {
103 if (window.innerWidth <= 767) return; //scrolling would hide chessboard
104 // $nextTick to wait for table > tr to be rendered
105 this.$nextTick(() => {
106 let curMove = document.querySelector(".td.highlight-lm");
107 if (!curMove && this.moves.length > 0) {
108 // Cursor is before game beginning, and some moves were made:
110 document.querySelector(".moves-list > .tr:first-child > .td");
113 curMove.scrollIntoView({
122 evenNumbers: function() {
123 return [...Array(this.moves.length).keys()].filter(i => i%2==0);
127 notation: function(move) {
128 return getFullNotation(move);
130 highlightBlackmove: function(moveIdx) {
132 this.cursor == moveIdx ||
134 // If display by rows, hightlight last black move while the white
135 // move is being played:
136 this.show == "byrow" &&
137 this.cursor == moveIdx + 1 &&
138 // ...except if cursor is behind in the game:
139 this.cursor == this.moves.length - 1
143 btnTooltipClass: function() {
144 return { tooltip: !("ontouchstart" in window) };
146 gotoMove: function(index) {
147 // Goto move except if click on current move:
148 if (this.cursor != index) this.$emit("goto-move", index);
150 adjustBoard: function() {
151 const boardContainer = document.getElementById("boardContainer");
152 if (!boardContainer) return; //no board on page
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";
164 this.$emit("redraw-board");
170 <style lang="sass" scoped>
177 background-color: white
181 border-bottom: 1px solid lightgrey
191 @media screen and (max-width: 767px)
196 background-color: plum
198 #boardSizeBtnContainer
202 [type="checkbox"]#modalAdjust+div .card
207 @media screen and (max-width: 767px)
212 @media screen and (max-width: 767px)
216 display: inline-block
221 display: inline-block
226 display: inline-block
231 display: inline-block
238 background-color: #48C9B0