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"
128 return { highlightRules: !localStorage.getItem("rr_" + this.vname) };
132 notation: function(moveIdx) {
133 const move = this.moves[moveIdx];
134 if (this.score != "*") return getFullNotation(move);
136 ['none','highlight'].includes(this.show) ||
138 this.show == "byrow" &&
139 moveIdx == this.moves.length-1 &&
145 return getFullNotation(move);
147 btnTooltipClass: function() {
148 return { tooltip: !("ontouchstart" in window) };
150 clickRulesBtn: function() {
151 const key = "rr_" + this.vname;
152 if (!localStorage.getItem(key)) {
153 localStorage.setItem(key, '1');
154 document.getElementById("rulesBtn").classList.remove("highlightRules");
156 this.$emit("showrules");
158 gotoMove: function(index) {
159 // Goto move except if click on current move:
160 if (this.cursor != index) this.$emit("goto-move", index);
162 adjustBoard: function() {
163 const boardContainer = document.getElementById("boardContainer");
164 if (!boardContainer) return; //no board on page
165 const k = document.getElementById("boardSize").value;
166 const movesWidth = window.innerWidth >= 768 ? 280 : 0;
167 const minBoardWidth = 240; //TODO: these 240 and 280 are arbitrary...
168 // Value of 0 is board min size; 100 is window.width [- movesWidth]
171 (k * (window.innerWidth - (movesWidth + minBoardWidth))) / 100;
172 localStorage.setItem("boardSize", boardSize);
173 boardContainer.style.width = boardSize + "px";
174 document.getElementById("gameContainer").style.width =
175 boardSize + movesWidth + "px";
176 this.$emit("redraw-board");
182 <style lang="sass" scoped>
189 background-color: white
193 border-bottom: 1px solid lightgrey
203 @media screen and (max-width: 767px)
208 background-color: plum
212 background-color: yellow
214 #boardSizeBtnContainer
218 [type="checkbox"]#modalAdjust+div .card
223 @media screen and (max-width: 767px)
228 @media screen and (max-width: 767px)
232 display: inline-block
237 display: inline-block
242 display: inline-block
247 display: inline-block
254 background-color: #48C9B0