Commit | Line | Data |
---|---|---|
98db2082 BA |
1 | <template lang="pug"> |
2 | div | |
3 | input#modalSettings.modal(type="checkbox") | |
4 | div(role="dialog" aria-labelledby="settingsTitle") | |
5 | .card.smallpad(@change="updateSettings") | |
6 | label.modal-close(for="modalSettings") | |
c66a829b | 7 | h3#settingsTitle.section {{ st.tr["Preferences"] }} |
98db2082 | 8 | fieldset |
c66a829b BA |
9 | label(for="setSqSize") {{ st.tr["Square size (in pixels). 0 for 'adaptative'"] }} |
10 | input#setSqSize(type="number" v-model="st.settings.sqSize") | |
98db2082 | 11 | fieldset |
c66a829b BA |
12 | label(for="selectHints") {{ st.tr["Show move hints?"] }} |
13 | select#setHints(v-model="st.settings.hints") | |
14 | option(value="0") {{ st.tr["None"] }} | |
15 | option(value="1") {{ st.tr["Moves from a square"] }} | |
16 | option(value="2") {{ st.tr["Pieces which can move"] }} | |
98db2082 | 17 | fieldset |
c66a829b BA |
18 | label(for="setHighlight") {{ st.tr["Highlight squares? (Last move & checks)"] }} |
19 | input#setHighlight(type="checkbox" v-model="st.settings.highlight") | |
98db2082 | 20 | fieldset |
c66a829b BA |
21 | label(for="setCoords") {{ st.tr["Show board coordinates?"] }} |
22 | input#setCoords(type="checkbox" v-model="st.settings.coords") | |
98db2082 | 23 | fieldset |
c66a829b BA |
24 | label(for="selectColor") {{ st.tr["Board colors"] }} |
25 | select#setBcolor(v-model="st.settings.bcolor") | |
26 | option(value="lichess") {{ st.tr["brown"] }} | |
27 | option(value="chesscom") {{ st.tr["green"] }} | |
28 | option(value="chesstempo") {{ st.tr["blue"] }} | |
98db2082 | 29 | fieldset |
c66a829b BA |
30 | label(for="selectSound") {{ st.tr["Play sounds?"] }} |
31 | select#setSound(v-model="st.settings.sound") | |
32 | option(value="0") {{ st.tr["None"] }} | |
33 | option(value="1") {{ st.tr["New game"] }} | |
34 | option(value="2") {{ st.tr["All"] }} | |
7b3cf1b7 BA |
35 | fieldset |
36 | .slidecontainer | |
cf94b843 | 37 | input#myRange.slider(type="range" min="0" max="100" value="50" |
7b3cf1b7 | 38 | @input="adjustBoard") |
98db2082 BA |
39 | </template> |
40 | ||
41 | <script> | |
c66a829b | 42 | import { store } from "@/store.js"; |
98db2082 | 43 | export default { |
c66a829b BA |
44 | name: "my-settings", |
45 | data: function() { | |
46 | return { | |
47 | st: store.state, | |
48 | }; | |
5701c228 BA |
49 | }, |
50 | mounted: function() { | |
51 | const boardSize = localStorage.getItem("boardSize"); | |
52 | if (!!boardSize) | |
53 | document.getElementById("myRange").value = Math.floor(boardSize / 10); | |
c66a829b | 54 | }, |
98db2082 BA |
55 | methods: { |
56 | updateSettings: function(event) { | |
57 | const propName = | |
58 | event.target.id.substr(3).replace(/^\w/, c => c.toLowerCase()) | |
59 | localStorage[propName] = ["highlight","coords"].includes(propName) | |
60 | ? event.target.checked | |
61 | : event.target.value; | |
7b3cf1b7 BA |
62 | }, |
63 | adjustBoard: function() { | |
cf94b843 BA |
64 | const boardContainer = document.getElementById("boardContainer"); |
65 | if (!boardContainer) | |
7b3cf1b7 | 66 | return; //no board on page |
cf94b843 BA |
67 | const k = document.getElementById("myRange").value; |
68 | const movesWidth = 280; //TODO: constant somewhere...; | |
69 | const minBoardWidth = 240; //TODO: same | |
70 | // Value of 0 is board min size; 100 is screen.width - movesWidth | |
71 | const boardSize = k * (screen.width - (movesWidth+minBoardWidth)) / 100 + minBoardWidth; | |
7b3cf1b7 | 72 | localStorage.setItem("boardSize", boardSize); |
cf94b843 BA |
73 | boardContainer.style.width = boardSize + "px"; |
74 | document.getElementById("gameContainer").style.width = (boardSize + movesWidth) + "px"; | |
98db2082 BA |
75 | }, |
76 | }, | |
77 | }; | |
78 | </script> |