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)"
56 v-html="notation(moveIdx)")
58 v-if="moveIdx < moves.length-1"
59 :class="{'highlight-lm': cursor == moveIdx+1}"
60 @click="() => gotoMove(moveIdx+1)"
61 v-html="notation(moveIdx + 1)")
65 import { store } from "@/store";
66 import { getFullNotation } from "@/utils/notation";
67 import { processModalClick } from "@/utils/modalClick";
71 "moves", "show", "canAnalyze", "canDownload",
72 "vname", "cursor", "score", "message", "firstNum"],
79 document.getElementById("adjuster")
80 .addEventListener("click", processModalClick);
81 // Take full width on small screens:
83 window.innerWidth >= 768
84 ? 0.7 * Math.min(window.innerWidth, window.innerHeight)
86 const movesWidth = window.innerWidth >= 768 ? 280 : 0;
87 document.getElementById("boardContainer").style.width = boardSize + "px";
88 let gameContainer = document.getElementById("gameContainer");
89 gameContainer.style.width = boardSize + movesWidth + "px";
90 document.getElementById("boardSize").value =
91 (boardSize * 100) / (window.innerWidth - movesWidth);
92 window.addEventListener("resize", () => this.adjustBoard());
93 if ("ontouchstart" in window) {
94 // TODO: find something better than next height adjustment...
95 // maybe each variant could give its ratio (?!)
96 setTimeout( () => { this.adjustBoard("vertical"); }, 1000);
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(vertical) {
166 const boardContainer = document.getElementById("boardContainer");
167 if (!boardContainer) return; //no board on page
168 const movesWidth = window.innerWidth >= 768 ? 280 : 0;
169 let gameContainer = document.getElementById("gameContainer");
172 document.getElementById("rootBoardElement").getBoundingClientRect();
173 if (bRect.bottom > window.innerHeight) {
174 const maxHeight = window.innerHeight - 20;
175 gameContainer.style.height = maxHeight + "px";
176 const boardSize = maxHeight * bRect.width / bRect.height;
177 boardContainer.style.width = boardSize + "px";
178 gameContainer.style.width = boardSize + movesWidth + "px";
179 this.$emit("redraw-board");
180 setTimeout( () => window.scroll(0, bRect.top), 1000);
184 const k = document.getElementById("boardSize").value;
185 const minBoardWidth = 160; //TODO: these 160 and 280 are arbitrary...
186 // Value of 0 is board min size; 100 is window.width [- movesWidth]
189 (k * (window.innerWidth - (movesWidth + minBoardWidth))) / 100;
190 boardContainer.style.width = boardSize + "px";
191 gameContainer.style.width = boardSize + movesWidth + "px";
192 this.$emit("redraw-board");
199 <style lang="sass" scoped>
206 background-color: white
210 border-bottom: 1px solid lightgrey
220 @media screen and (max-width: 767px)
225 background-color: plum
229 background-color: yellow
231 #boardSizeBtnContainer
235 [type="checkbox"]#modalAdjust+div .card
240 @media screen and (max-width: 767px)
245 @media screen and (max-width: 767px)
249 display: inline-block
254 display: inline-block
259 display: inline-block
264 display: inline-block
271 background-color: #48C9B0