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 let boardSize = parseInt(localStorage.getItem("boardSize"), 10);
85 window.innerWidth >= 768
86 ? 0.75 * Math.min(window.innerWidth, window.innerHeight)
89 const movesWidth = window.innerWidth >= 768 ? 280 : 0;
90 document.getElementById("boardContainer").style.width = boardSize + "px";
91 let gameContainer = document.getElementById("gameContainer");
92 gameContainer.style.width = boardSize + movesWidth + "px";
93 document.getElementById("boardSize").value =
94 (boardSize * 100) / (window.innerWidth - movesWidth);
95 window.addEventListener("resize", this.adjustBoard);
97 beforeDestroy: function() {
98 window.removeEventListener("resize", this.adjustBoard);
101 cursor: function(newCursor) {
102 if (window.innerWidth <= 767) return; //scrolling would hide chessboard
103 // $nextTick to wait for table > tr to be rendered
104 this.$nextTick(() => {
105 let curMove = document.querySelector(".td.highlight-lm");
106 if (!curMove && this.moves.length > 0) {
107 // Cursor is before game beginning, and some moves were made:
109 document.querySelector(".moves-list > .tr:first-child > .td");
112 curMove.scrollIntoView({
121 evenNumbers: function() {
122 return [...Array(this.moves.length).keys()].filter(i => i%2==0);
124 btnRulesClass: function() {
125 // "rr" for "rules read"
128 !!this.vname && !localStorage.getItem("rr_" + this.vname)
133 notation: function(moveIdx) {
134 const move = this.moves[moveIdx];
135 if (this.score != "*") return getFullNotation(move);
137 ['none','highlight'].includes(this.show) ||
139 this.show == "byrow" &&
140 moveIdx == this.moves.length-1 &&
146 return getFullNotation(move);
148 btnTooltipClass: function() {
149 return { tooltip: !("ontouchstart" in window) };
151 clickRulesBtn: function() {
152 const key = "rr_" + this.vname;
153 if (!localStorage.getItem(key)) {
154 localStorage.setItem(key, '1');
155 document.getElementById("rulesBtn").classList.remove("highlightRules");
157 this.$emit("showrules");
159 gotoMove: function(index) {
160 // Goto move except if click on current move:
161 if (this.cursor != index) this.$emit("goto-move", index);
163 adjustBoard: function() {
164 const boardContainer = document.getElementById("boardContainer");
165 if (!boardContainer) return; //no board on page
166 const k = document.getElementById("boardSize").value;
167 const movesWidth = window.innerWidth >= 768 ? 280 : 0;
168 const minBoardWidth = 240; //TODO: these 240 and 280 are arbitrary...
169 // Value of 0 is board min size; 100 is window.width [- movesWidth]
172 (k * (window.innerWidth - (movesWidth + minBoardWidth))) / 100;
173 localStorage.setItem("boardSize", boardSize);
174 boardContainer.style.width = boardSize + "px";
175 document.getElementById("gameContainer").style.width =
176 boardSize + movesWidth + "px";
177 this.$emit("redraw-board");
183 <style lang="sass" scoped>
190 background-color: white
194 border-bottom: 1px solid lightgrey
204 @media screen and (max-width: 767px)
209 background-color: plum
213 background-color: yellow
215 #boardSizeBtnContainer
219 [type="checkbox"]#modalAdjust+div .card
224 @media screen and (max-width: 767px)
229 @media screen and (max-width: 767px)
233 display: inline-block
238 display: inline-block
243 display: inline-block
248 display: inline-block
255 background-color: #48C9B0