| 1 | <template lang="pug"> |
| 2 | div |
| 3 | input#modalSettings.modal(type="checkbox") |
| 4 | div#settingsDiv( |
| 5 | role="dialog" |
| 6 | data-checkbox="modalSettings" |
| 7 | ) |
| 8 | .card |
| 9 | label.modal-close(for="modalSettings") |
| 10 | - |
| 11 | var langName = { |
| 12 | "en": "English", |
| 13 | "es": "Español", |
| 14 | "fr": "Français", |
| 15 | }; |
| 16 | fieldset(@change="setLanguage($event)") |
| 17 | label(for="langSelect") |
| 18 | | {{ st.tr["Language"] }} |
| 19 | select#langSelect |
| 20 | each language,langCode in langName |
| 21 | option(value=langCode) |
| 22 | =language |
| 23 | #flagContainer |
| 24 | img( |
| 25 | v-if="!!st.lang" |
| 26 | :src="flagImage" |
| 27 | ) |
| 28 | div(@change="updateSettings($event)") |
| 29 | fieldset |
| 30 | label(for="setHints") {{ st.tr["Show possible moves"] }} |
| 31 | input#setHints( |
| 32 | type="checkbox" |
| 33 | v-model="st.settings.hints" |
| 34 | ) |
| 35 | fieldset |
| 36 | label(for="setHighlight") |
| 37 | | {{ st.tr["Highlight last move"] }} |
| 38 | input#setHighlight( |
| 39 | type="checkbox" |
| 40 | v-model="st.settings.highlight" |
| 41 | ) |
| 42 | fieldset |
| 43 | label(for="setBcolor") {{ st.tr["Board colors"] }} |
| 44 | select#setBcolor(v-model="st.settings.bcolor") |
| 45 | option(value="lichess") {{ st.tr["brown"] }} |
| 46 | option(value="chesscom") {{ st.tr["green"] }} |
| 47 | option(value="chesstempo") {{ st.tr["blue"] }} |
| 48 | option(value="orangecc") {{ st.tr["orange"] }} |
| 49 | fieldset |
| 50 | label(for="setSound") |
| 51 | | {{ st.tr["Sound alert at game start"] }} |
| 52 | input#setSound( |
| 53 | type="checkbox" |
| 54 | v-model="st.settings.sound" |
| 55 | ) |
| 56 | fieldset |
| 57 | label(for="setGotonext") |
| 58 | | {{ st.tr["Show next game after a move"] }} |
| 59 | input#setGotonext( |
| 60 | type="checkbox" |
| 61 | v-model="st.settings.gotonext" |
| 62 | ) |
| 63 | fieldset(v-if="desktopBrowser") |
| 64 | label(for="setScrollmove") |
| 65 | | {{ st.tr["Mouse scroll to replay moves"] }} |
| 66 | input#setScrollmove( |
| 67 | type="checkbox" |
| 68 | v-model="st.settings.scrollmove" |
| 69 | ) |
| 70 | </template> |
| 71 | |
| 72 | <script> |
| 73 | import { store } from "@/store.js"; |
| 74 | import { processModalClick } from "@/utils/modalClick.js"; |
| 75 | export default { |
| 76 | name: "my-settings", |
| 77 | data: function() { |
| 78 | return { |
| 79 | st: store.state |
| 80 | }; |
| 81 | }, |
| 82 | mounted: function() { |
| 83 | document.getElementById("settingsDiv") |
| 84 | .addEventListener("click", processModalClick); |
| 85 | // NOTE: better style would be in pug directly, but how? |
| 86 | document.querySelectorAll("#langSelect > option").forEach(opt => { |
| 87 | if (opt.value == this.st.lang) opt.selected = true; |
| 88 | }); |
| 89 | }, |
| 90 | computed: { |
| 91 | flagImage: function() { |
| 92 | return `/images/flags/${this.st.lang}.svg`; |
| 93 | }, |
| 94 | desktopBrowser: function() { |
| 95 | return !("ontouchstart" in window); |
| 96 | } |
| 97 | }, |
| 98 | methods: { |
| 99 | setLanguage: function(e) { |
| 100 | localStorage["lang"] = e.target.value; |
| 101 | store.setLanguage(e.target.value); |
| 102 | }, |
| 103 | updateSettings: function(event) { |
| 104 | const propName = event.target.id |
| 105 | .substr(3) |
| 106 | .replace(/^\w/, c => c.toLowerCase()); |
| 107 | const value = propName == "bcolor" |
| 108 | ? event.target.value |
| 109 | : event.target.checked; |
| 110 | store.updateSetting(propName, value); |
| 111 | } |
| 112 | } |
| 113 | }; |
| 114 | </script> |
| 115 | |
| 116 | <style lang="sass" scoped> |
| 117 | [type="checkbox"].modal+div .card |
| 118 | max-width: 520px |
| 119 | max-height: 100% |
| 120 | #flagContainer |
| 121 | display: inline-block |
| 122 | height: 100% |
| 123 | & > img |
| 124 | vertical-align: middle |
| 125 | padding: 0 0 0 10px |
| 126 | width: 36px |
| 127 | height: 27px |
| 128 | </style> |