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="clickRulesBtn()"
23 :class="btnRulesClass"
25 | {{ st.tr["Rules"] }}
27 :class="btnTooltipClass()"
28 onClick="window.doClick('modalAdjust')"
29 :aria-label="st.tr['Resize board']"
31 img.inline(src="/images/icons/resize.svg")
34 :class="btnTooltipClass()"
35 @click="$emit('analyze')"
36 :aria-label="st.tr['Analyse']"
38 img.inline(src="/images/icons/analyse.svg")
39 #downloadDiv(v-if="canDownload")
42 :class="btnTooltipClass()"
43 @click="$emit('download')"
44 :aria-label="st.tr['Download'] + ' PGN'"
46 img.inline(src="/images/icons/download.svg")
47 #scoreInfo(v-if="score!='*'")
48 span.score {{ score }}
49 span.score-msg {{ st.tr[message] }}
51 .tr(v-for="moveIdx in evenNumbers")
52 .td {{ firstNum + moveIdx / 2 }}
54 :class="{'highlight-lm': cursor == moveIdx}"
55 @click="() => gotoMove(moveIdx)"
57 | {{ notation(moveIdx) }}
59 v-if="moveIdx < moves.length-1"
60 :class="{'highlight-lm': cursor == moveIdx+1}"
61 @click="() => gotoMove(moveIdx+1)"
63 | {{ notation(moveIdx + 1) }}
67 import { store } from "@/store";
68 import { getFullNotation } from "@/utils/notation";
69 import { processModalClick } from "@/utils/modalClick";
73 "moves", "show", "canAnalyze", "canDownload",
74 "vname", "cursor", "score", "message", "firstNum"],
81 document.getElementById("adjuster")
82 .addEventListener("click", processModalClick);
83 // Take full width on small screens:
84 let boardSize = parseInt(localStorage.getItem("boardSize"));
87 window.innerWidth >= 768
88 ? 0.75 * Math.min(window.innerWidth, window.innerHeight)
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);
97 window.addEventListener("resize", this.adjustBoard);
99 beforeDestroy: function() {
100 window.removeEventListener("resize", this.adjustBoard);
103 cursor: function(newCursor) {
104 if (window.innerWidth <= 767) return; //scrolling would hide chessboard
105 // $nextTick to wait for table > tr to be rendered
106 this.$nextTick(() => {
107 let curMove = document.querySelector(".td.highlight-lm");
108 if (!curMove && this.moves.length > 0) {
109 // Cursor is before game beginning, and some moves were made:
111 document.querySelector(".moves-list > .tr:first-child > .td");
114 curMove.scrollIntoView({
123 evenNumbers: function() {
124 return [...Array(this.moves.length).keys()].filter(i => i%2==0);
126 btnRulesClass: function() {
127 // "rr" for "rules read"
130 !!this.vname && !localStorage.getItem("rr_" + this.vname)
135 notation: function(moveIdx) {
136 const move = this.moves[moveIdx];
137 if (this.score != "*") return getFullNotation(move);
139 ['none','highlight'].includes(this.show) ||
141 this.show == "byrow" &&
142 moveIdx == this.moves.length-1 &&
148 return getFullNotation(move);
150 btnTooltipClass: function() {
151 return { tooltip: !("ontouchstart" in window) };
153 clickRulesBtn: function() {
154 const key = "rr_" + this.vname;
155 if (!localStorage.getItem(key)) {
156 localStorage.setItem(key, '1');
157 document.getElementById("rulesBtn").classList.remove("highlightRules");
159 this.$emit("showrules");
161 gotoMove: function(index) {
162 // Goto move except if click on current move:
163 if (this.cursor != index) this.$emit("goto-move", index);
165 adjustBoard: function() {
166 const boardContainer = document.getElementById("boardContainer");
167 if (!boardContainer) return; //no board on page
168 const k = document.getElementById("boardSize").value;
169 const movesWidth = window.innerWidth >= 768 ? 280 : 0;
170 const minBoardWidth = 240; //TODO: these 240 and 280 are arbitrary...
171 // Value of 0 is board min size; 100 is window.width [- movesWidth]
174 (k * (window.innerWidth - (movesWidth + minBoardWidth))) / 100;
175 localStorage.setItem("boardSize", boardSize);
176 boardContainer.style.width = boardSize + "px";
177 document.getElementById("gameContainer").style.width =
178 boardSize + movesWidth + "px";
179 this.$emit("redraw-board");
185 <style lang="sass" scoped>
192 background-color: white
196 border-bottom: 1px solid lightgrey
206 @media screen and (max-width: 767px)
211 background-color: plum
215 background-color: yellow
217 #boardSizeBtnContainer
221 [type="checkbox"]#modalAdjust+div .card
226 @media screen and (max-width: 767px)
231 @media screen and (max-width: 767px)
235 display: inline-block
240 display: inline-block
245 display: inline-block
250 display: inline-block
257 background-color: #48C9B0