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:
82 const winBound = Math.min(window.innerWidth, window.innerHeight);
83 let boardSize = (window.innerWidth >= 768 ? 0.7 : 1.0) * winBound;
84 const movesWidth = window.innerWidth >= 768 ? 280 : 0;
85 document.getElementById("boardContainer").style.width = boardSize + "px";
86 let gameContainer = document.getElementById("gameContainer");
87 gameContainer.style.width = boardSize + movesWidth + "px";
89 Math.min(window.innerHeight, window.innerWidth - movesWidth);
90 document.getElementById("boardSize").value = (boardSize * 100) / maxWidth;
91 window.addEventListener("resize", () => this.adjustBoard());
93 beforeDestroy: function() {
94 window.removeEventListener("resize", this.adjustBoard);
97 cursor: function(newCursor) {
98 if (window.innerWidth <= 767) return; //scrolling would hide chessboard
99 // $nextTick to wait for table > tr to be rendered
100 this.$nextTick(() => {
101 let curMove = document.querySelector(".td.highlight-lm");
102 if (!curMove && this.moves.length > 0) {
103 // Cursor is before game beginning, and some moves were made:
105 document.querySelector(".moves-list > .tr:first-child > .td");
108 curMove.scrollIntoView({
117 evenNumbers: function() {
118 return [...Array(this.moves.length).keys()].filter(i => i%2==0);
120 btnRulesClass: function() {
121 // "rr" for "rules read"
124 !!this.vname && !localStorage.getItem("rr_" + this.vname)
129 notation: function(moveIdx) {
130 const move = this.moves[moveIdx];
131 if (this.score != "*") return getFullNotation(move);
133 ['none','highlight'].includes(this.show) ||
135 this.show == "byrow" &&
136 moveIdx == this.moves.length-1 &&
142 return getFullNotation(move);
144 btnTooltipClass: function() {
145 return { tooltip: !("ontouchstart" in window) };
147 clickRulesBtn: function() {
148 const key = "rr_" + this.vname;
149 if (!localStorage.getItem(key)) {
150 localStorage.setItem(key, '1');
151 document.getElementById("rulesBtn").classList.remove("highlightRules");
153 this.$emit("showrules");
155 gotoMove: function(index) {
156 // Goto move except if click on current move:
157 if (this.cursor != index) this.$emit("goto-move", index);
159 adjustBoard: function(vertical) {
160 const boardContainer = document.getElementById("boardContainer");
161 if (!boardContainer) return; //no board on page
162 const movesWidth = window.innerWidth >= 768 ? 280 : 0;
163 let gameContainer = document.getElementById("gameContainer");
166 document.getElementById("rootBoardElement").getBoundingClientRect();
167 if (bRect.bottom > window.innerHeight) {
168 const maxHeight = window.innerHeight - 20;
169 gameContainer.style.height = maxHeight + "px";
170 const boardSize = maxHeight * bRect.width / bRect.height;
171 boardContainer.style.width = boardSize + "px";
172 gameContainer.style.width = boardSize + movesWidth + "px";
173 this.$emit("redraw-board");
174 setTimeout( () => window.scroll(0, bRect.top), 1000);
178 const k = document.getElementById("boardSize").value;
179 // TODO: these 160 and 280 are arbitrary...
180 const minBoardWidth =
181 (window.innerWidth <= 767 || "ontouchstart" in window) ? 160 : 240;
182 // Value of 0 is board min size; 100 is window.width [- movesWidth]
184 Math.min(window.innerHeight, window.innerWidth - movesWidth);
186 minBoardWidth + (k * (maxWidth - minBoardWidth)) / 100;
187 boardContainer.style.width = boardSize + "px";
188 gameContainer.style.width = boardSize + movesWidth + "px";
189 this.$emit("redraw-board");
196 <style lang="sass" scoped>
203 background-color: white
207 border-bottom: 1px solid lightgrey
217 @media screen and (max-width: 767px)
222 background-color: plum
226 background-color: yellow
228 #boardSizeBtnContainer
232 [type="checkbox"]#modalAdjust+div .card
237 @media screen and (max-width: 767px)
242 @media screen and (max-width: 767px)
246 display: inline-block
251 display: inline-block
256 display: inline-block
261 display: inline-block
268 background-color: #48C9B0