diff --git a/frontend/src/js/controllers/input-controller.js b/frontend/src/js/controllers/input-controller.js index 146651b5a..4f68d3e8a 100644 --- a/frontend/src/js/controllers/input-controller.js +++ b/frontend/src/js/controllers/input-controller.js @@ -124,7 +124,7 @@ function handleSpace() { .toString() .toUpperCase() ); - Settings.groups.layout?.updateButton(); + Settings.groups.layout?.updateInput(); } dontInsertSpace = true; diff --git a/frontend/src/js/elements/commandline-lists.js b/frontend/src/js/elements/commandline-lists.js index 487b55bc9..932cdaca8 100644 --- a/frontend/src/js/elements/commandline-lists.js +++ b/frontend/src/js/elements/commandline-lists.js @@ -192,7 +192,7 @@ Misc.getFontsList().then((fonts) => { }, exec: (name) => { UpdateConfig.setFontFamily(name.replace(/\s/g, "_")); - // Settings.groups.fontFamily.updateButton(); + // Settings.groups.fontFamily.updateInput(); }, }); }); diff --git a/frontend/src/js/pages/settings.js b/frontend/src/js/pages/settings.js index ff9016e66..4276dc639 100644 --- a/frontend/src/js/pages/settings.js +++ b/frontend/src/js/pages/settings.js @@ -22,37 +22,48 @@ async function initGroups() { await UpdateConfig.loadPromise; groups.smoothCaret = new SettingsGroup( "smoothCaret", - UpdateConfig.setSmoothCaret + UpdateConfig.setSmoothCaret, + "button" ); groups.difficulty = new SettingsGroup( "difficulty", - UpdateConfig.setDifficulty + UpdateConfig.setDifficulty, + "button" + ); + groups.quickTab = new SettingsGroup( + "quickTab", + UpdateConfig.setQuickTabMode, + "button" ); - groups.quickTab = new SettingsGroup("quickTab", UpdateConfig.setQuickTabMode); groups.showLiveWpm = new SettingsGroup( "showLiveWpm", UpdateConfig.setShowLiveWpm, + "button", () => { - groups.keymapMode.updateButton(); + groups.keymapMode.updateInput(); } ); groups.showLiveAcc = new SettingsGroup( "showLiveAcc", - UpdateConfig.setShowLiveAcc + UpdateConfig.setShowLiveAcc, + "button" ); groups.showLiveBurst = new SettingsGroup( "showLiveBurst", - UpdateConfig.setShowLiveBurst + UpdateConfig.setShowLiveBurst, + "button" ); groups.showTimerProgress = new SettingsGroup( "showTimerProgress", - UpdateConfig.setShowTimerProgress + UpdateConfig.setShowTimerProgress, + "button" ); groups.keymapMode = new SettingsGroup( "keymapMode", UpdateConfig.setKeymapMode, + "button", () => { - groups.showLiveWpm.updateButton(); + groups.showLiveWpm.updateInput(); }, () => { if (Config.keymapMode === "off") { @@ -68,19 +79,23 @@ async function initGroups() { ); groups.keymapMatrix = new SettingsGroup( "keymapStyle", - UpdateConfig.setKeymapStyle + UpdateConfig.setKeymapStyle, + "button" ); groups.keymapLayout = new SettingsGroup( "keymapLayout", - UpdateConfig.setKeymapLayout + UpdateConfig.setKeymapLayout, + "select" ); groups.keymapLegendStyle = new SettingsGroup( "keymapLegendStyle", - UpdateConfig.setKeymapLegendStyle + UpdateConfig.setKeymapLegendStyle, + "button" ); groups.showKeyTips = new SettingsGroup( "showKeyTips", UpdateConfig.setKeyTips, + "button", null, () => { if (Config.showKeyTips) { @@ -93,96 +108,128 @@ async function initGroups() { groups.freedomMode = new SettingsGroup( "freedomMode", UpdateConfig.setFreedomMode, + "button", () => { - groups.confidenceMode.updateButton(); + groups.confidenceMode.updateInput(); } ); groups.strictSpace = new SettingsGroup( "strictSpace", - UpdateConfig.setStrictSpace + UpdateConfig.setStrictSpace, + "button" ); groups.oppositeShiftMode = new SettingsGroup( "oppositeShiftMode", - UpdateConfig.setOppositeShiftMode + UpdateConfig.setOppositeShiftMode, + "button" ); groups.confidenceMode = new SettingsGroup( "confidenceMode", UpdateConfig.setConfidenceMode, + "button", () => { - groups.freedomMode.updateButton(); - groups.stopOnError.updateButton(); + groups.freedomMode.updateInput(); + groups.stopOnError.updateInput(); } ); groups.indicateTypos = new SettingsGroup( "indicateTypos", - UpdateConfig.setIndicateTypos + UpdateConfig.setIndicateTypos, + "button" ); groups.hideExtraLetters = new SettingsGroup( "hideExtraLetters", - UpdateConfig.setHideExtraLetters + UpdateConfig.setHideExtraLetters, + "button" + ); + groups.blindMode = new SettingsGroup( + "blindMode", + UpdateConfig.setBlindMode, + "button" + ); + groups.quickEnd = new SettingsGroup( + "quickEnd", + UpdateConfig.setQuickEnd, + "button" ); - groups.blindMode = new SettingsGroup("blindMode", UpdateConfig.setBlindMode); - groups.quickEnd = new SettingsGroup("quickEnd", UpdateConfig.setQuickEnd); groups.repeatQuotes = new SettingsGroup( "repeatQuotes", - UpdateConfig.setRepeatQuotes + UpdateConfig.setRepeatQuotes, + "button" + ); + groups.enableAds = new SettingsGroup( + "enableAds", + UpdateConfig.setEnableAds, + "button" ); - groups.enableAds = new SettingsGroup("enableAds", UpdateConfig.setEnableAds); groups.alwaysShowWordsHistory = new SettingsGroup( "alwaysShowWordsHistory", - UpdateConfig.setAlwaysShowWordsHistory + UpdateConfig.setAlwaysShowWordsHistory, + "button" ); groups.britishEnglish = new SettingsGroup( "britishEnglish", - UpdateConfig.setBritishEnglish + UpdateConfig.setBritishEnglish, + "button" ); groups.singleListCommandLine = new SettingsGroup( "singleListCommandLine", - UpdateConfig.setSingleListCommandLine + UpdateConfig.setSingleListCommandLine, + "button" ); groups.capsLockWarning = new SettingsGroup( "capsLockWarning", - UpdateConfig.setCapsLockWarning + UpdateConfig.setCapsLockWarning, + "button" ); groups.flipTestColors = new SettingsGroup( "flipTestColors", - UpdateConfig.setFlipTestColors + UpdateConfig.setFlipTestColors, + "button" ); groups.swapEscAndTab = new SettingsGroup( "swapEscAndTab", - UpdateConfig.setSwapEscAndTab + UpdateConfig.setSwapEscAndTab, + "button" ); groups.showOutOfFocusWarning = new SettingsGroup( "showOutOfFocusWarning", - UpdateConfig.setShowOutOfFocusWarning + UpdateConfig.setShowOutOfFocusWarning, + "button" ); groups.colorfulMode = new SettingsGroup( "colorfulMode", - UpdateConfig.setColorfulMode + UpdateConfig.setColorfulMode, + "button" ); groups.startGraphsAtZero = new SettingsGroup( "startGraphsAtZero", - UpdateConfig.setStartGraphsAtZero + UpdateConfig.setStartGraphsAtZero, + "button" ); groups.randomTheme = new SettingsGroup( "randomTheme", - UpdateConfig.setRandomTheme + UpdateConfig.setRandomTheme, + "button" ); groups.stopOnError = new SettingsGroup( "stopOnError", UpdateConfig.setStopOnError, + "button", () => { - groups.confidenceMode.updateButton(); + groups.confidenceMode.updateInput(); } ); groups.soundVolume = new SettingsGroup( "soundVolume", UpdateConfig.setSoundVolume, + "button", () => {} ); groups.playSoundOnError = new SettingsGroup( "playSoundOnError", UpdateConfig.setPlaySoundOnError, + "button", () => { if (Config.playSoundOnError) Sound.playError(); } @@ -190,6 +237,7 @@ async function initGroups() { groups.playSoundOnClick = new SettingsGroup( "playSoundOnClick", UpdateConfig.setPlaySoundOnClick, + "button", () => { if (Config.playSoundOnClick !== "off") Sound.playClick(Config.playSoundOnClick); @@ -197,52 +245,86 @@ async function initGroups() { ); groups.showAllLines = new SettingsGroup( "showAllLines", - UpdateConfig.setShowAllLines + UpdateConfig.setShowAllLines, + "button" + ); + groups.paceCaret = new SettingsGroup( + "paceCaret", + UpdateConfig.setPaceCaret, + "button" ); - groups.paceCaret = new SettingsGroup("paceCaret", UpdateConfig.setPaceCaret); groups.repeatedPace = new SettingsGroup( "repeatedPace", - UpdateConfig.setRepeatedPace + UpdateConfig.setRepeatedPace, + "button" + ); + groups.minWpm = new SettingsGroup("minWpm", UpdateConfig.setMinWpm, "button"); + groups.minAcc = new SettingsGroup("minAcc", UpdateConfig.setMinAcc, "button"); + groups.minBurst = new SettingsGroup( + "minBurst", + UpdateConfig.setMinBurst, + "button" ); - groups.minWpm = new SettingsGroup("minWpm", UpdateConfig.setMinWpm); - groups.minAcc = new SettingsGroup("minAcc", UpdateConfig.setMinAcc); - groups.minBurst = new SettingsGroup("minBurst", UpdateConfig.setMinBurst); groups.smoothLineScroll = new SettingsGroup( "smoothLineScroll", - UpdateConfig.setSmoothLineScroll + UpdateConfig.setSmoothLineScroll, + "button" + ); + groups.lazyMode = new SettingsGroup( + "lazyMode", + UpdateConfig.setLazyMode, + "button" + ); + groups.layout = new SettingsGroup("layout", UpdateConfig.setLayout, "select"); + groups.language = new SettingsGroup( + "language", + UpdateConfig.setLanguage, + "select" + ); + groups.fontSize = new SettingsGroup( + "fontSize", + UpdateConfig.setFontSize, + "button" + ); + groups.pageWidth = new SettingsGroup( + "pageWidth", + UpdateConfig.setPageWidth, + "button" ); - groups.lazyMode = new SettingsGroup("lazyMode", UpdateConfig.setLazyMode); - groups.layout = new SettingsGroup("layout", UpdateConfig.setLayout); - groups.language = new SettingsGroup("language", UpdateConfig.setLanguage); - groups.fontSize = new SettingsGroup("fontSize", UpdateConfig.setFontSize); - groups.pageWidth = new SettingsGroup("pageWidth", UpdateConfig.setPageWidth); groups.caretStyle = new SettingsGroup( "caretStyle", - UpdateConfig.setCaretStyle + UpdateConfig.setCaretStyle, + "button" ); groups.paceCaretStyle = new SettingsGroup( "paceCaretStyle", - UpdateConfig.setPaceCaretStyle + UpdateConfig.setPaceCaretStyle, + "button" ); groups.timerStyle = new SettingsGroup( "timerStyle", - UpdateConfig.setTimerStyle + UpdateConfig.setTimerStyle, + "button" ); groups.highlighteMode = new SettingsGroup( "highlightMode", - UpdateConfig.setHighlightMode + UpdateConfig.setHighlightMode, + "button" ); groups.timerOpacity = new SettingsGroup( "timerOpacity", - UpdateConfig.setTimerOpacity + UpdateConfig.setTimerOpacity, + "button" ); groups.timerColor = new SettingsGroup( "timerColor", - UpdateConfig.setTimerColor + UpdateConfig.setTimerColor, + "button" ); groups.fontFamily = new SettingsGroup( "fontFamily", UpdateConfig.setFontFamily, + "button", null, () => { let customButton = $( @@ -260,15 +342,18 @@ async function initGroups() { ); groups.alwaysShowDecimalPlaces = new SettingsGroup( "alwaysShowDecimalPlaces", - UpdateConfig.setAlwaysShowDecimalPlaces + UpdateConfig.setAlwaysShowDecimalPlaces, + "button" ); groups.alwaysShowCPM = new SettingsGroup( "alwaysShowCPM", - UpdateConfig.setAlwaysShowCPM + UpdateConfig.setAlwaysShowCPM, + "button" ); groups.customBackgroundSize = new SettingsGroup( "customBackgroundSize", - UpdateConfig.setCustomBackgroundSize + UpdateConfig.setCustomBackgroundSize, + "button" ); // groups.customLayoutfluid = new SettingsGroup( // "customLayoutfluid", @@ -280,8 +365,9 @@ export function reset() { $(".pageSettings .section.themes .favThemes.buttons").empty(); $(".pageSettings .section.themes .allThemes.buttons").empty(); $(".pageSettings .section.languageGroups .buttons").empty(); - $(".pageSettings .section.layout .buttons").empty(); - $(".pageSettings .section.keymapLayout .buttons").empty(); + $(".pageSettings .section.layout select").empty().select2("destroy"); + $(".pageSettings .section.keymapLayout select").empty().select2("destroy"); + $(".pageSettings .section.language select").empty().select2("destroy"); $(".pageSettings .section.funbox .buttons").empty(); $(".pageSettings .section.fontFamily .buttons").empty(); } @@ -291,43 +377,42 @@ export async function fillSettingsPage() { await UpdateConfig.loadPromise; ThemePicker.refreshButtons(); - let langGroupsEl = $( - ".pageSettings .section.languageGroups .buttons" - ).empty(); - let currentLanguageGroup = await Misc.findCurrentGroup(Config.language); + let languageEl = $(".pageSettings .section.language select").empty(); Misc.getLanguageGroups().then((groups) => { groups.forEach((group) => { - langGroupsEl.append( - `
${group.name}
` - ); + let append = ``; + group.languages.forEach((language) => { + append += ``; + }); + append += ``; + languageEl.append(append); }); }); + languageEl.select2(); - let layoutEl = $(".pageSettings .section.layout .buttons").empty(); + let layoutEl = $(".pageSettings .section.layout select").empty(); Object.keys(layouts).forEach((layout) => { layoutEl.append( - `
${ + `
` + }` ); }); + layoutEl.select2(); - let keymapEl = $(".pageSettings .section.keymapLayout .buttons").empty(); - keymapEl.append( - `
emulator sync
` - ); + let keymapEl = $(".pageSettings .section.keymapLayout select").empty(); + keymapEl.append(``); Object.keys(layouts).forEach((layout) => { if (layout.toString() != "default") { keymapEl.append( - `
${layout.replace( - /_/g, - " " - )}
` + `` ); } }); + keymapEl.select2(); let funboxEl = $(".pageSettings .section.funbox .buttons").empty(); funboxEl.append(`
none
`); @@ -553,7 +638,7 @@ export function showAccountSection() { export function update() { Object.keys(groups).forEach((group) => { - groups[group].updateButton(); + groups[group].updateInput(); }); refreshTagsSettingsSection(); diff --git a/frontend/src/js/settings/settings-group.js b/frontend/src/js/settings/settings-group.js index 43363973e..d82473957 100644 --- a/frontend/src/js/settings/settings-group.js +++ b/frontend/src/js/settings/settings-group.js @@ -3,65 +3,71 @@ import Config from "../config"; export default class SettingsGroup { constructor( configName, - toggleFunction, + configFunction, + mode, setCallback = null, updateCallback = null ) { this.configName = configName; this.configValue = Config[configName]; - this.onOff = typeof this.configValue === "boolean"; - this.toggleFunction = toggleFunction; + this.mode = mode; + this.configFunction = configFunction; this.setCallback = setCallback; this.updateCallback = updateCallback; - this.updateButton(); + this.updateInput(); - $(document).on( - "click", - `.pageSettings .section.${this.configName} .button`, - (e) => { - let target = $(e.currentTarget); - if (target.hasClass("disabled") || target.hasClass("no-auto-handle")) - return; - if (this.onOff) { - if (target.hasClass("on")) { - this.setValue(true); - } else { - this.setValue(false); - } - this.updateButton(); - if (this.setCallback !== null) this.setCallback(); - } else { - const value = target.attr(configName); + if (this.mode === "select") { + $(document).on( + "change", + `.pageSettings .section.${this.configName} select`, + (e) => { + const target = $(e.currentTarget); + if (target.hasClass("disabled") || target.hasClass("no-auto-handle")) + return; + this.setValue(target.val()); + } + ); + } else if (this.mode === "button") { + $(document).on( + "click", + `.pageSettings .section.${this.configName} .button`, + (e) => { + let target = $(e.currentTarget); + if (target.hasClass("disabled") || target.hasClass("no-auto-handle")) + return; + let value = target.attr(configName); const params = target.attr("params"); if (!value && !params) return; + if (value === "true") value = true; + if (value === "false") value = false; this.setValue(value, params); } - } - ); + ); + } } setValue(value, params = undefined) { if (params === undefined) { - this.toggleFunction(value); + this.configFunction(value); } else { - this.toggleFunction(value, ...params); + this.configFunction(value, ...params); } - this.updateButton(); + console.log(`${this.configName} set to ${value}`); + this.updateInput(); if (this.setCallback !== null) this.setCallback(); } - updateButton() { + updateInput() { this.configValue = Config[this.configName]; $(`.pageSettings .section.${this.configName} .button`).removeClass( "active" ); - if (this.onOff) { - const onOffString = this.configValue ? "on" : "off"; - $( - `.pageSettings .section.${this.configName} .buttons .button.${onOffString}` - ).addClass("active"); - } else { + if (this.mode === "select") { + $(`.pageSettings .section.${this.configName} select`) + .val(this.configValue) + .trigger("change.select2"); + } else if (this.mode === "button") { $( `.pageSettings .section.${this.configName} .button[${this.configName}='${this.configValue}']` ).addClass("active"); diff --git a/frontend/src/js/test/funbox.js b/frontend/src/js/test/funbox.js index 04b87cf95..69cbc821a 100644 --- a/frontend/src/js/test/funbox.js +++ b/frontend/src/js/test/funbox.js @@ -155,7 +155,7 @@ export async function activate(funbox) { if (funbox === "simon_says") { UpdateConfig.setKeymapMode("next", true); - Settings.groups.keymapMode?.updateButton(); + Settings.groups.keymapMode?.updateInput(); TestLogic.restart(undefined, true); } @@ -172,11 +172,11 @@ export async function activate(funbox) { $("#funBoxTheme").attr("href", `funbox/simon_says.css`); UpdateConfig.setKeymapMode("off", true); UpdateConfig.setHighlightMode("letter", true); - Settings.groups.keymapMode?.updateButton(); + Settings.groups.keymapMode?.updateInput(); TestLogic.restart(undefined, true); } else if (funbox === "layoutfluid") { // UpdateConfig.setKeymapMode("next"); - Settings.groups.keymapMode?.updateButton(); + Settings.groups.keymapMode?.updateInput(); // UpdateConfig.setSavedLayout(Config.layout); UpdateConfig.setLayout( Config.customLayoutfluid @@ -184,14 +184,14 @@ export async function activate(funbox) { : "qwerty", true ); - Settings.groups.layout?.updateButton(); + Settings.groups.layout?.updateInput(); UpdateConfig.setKeymapLayout( Config.customLayoutfluid ? Config.customLayoutfluid.split("#")[0] : "qwerty", true ); - Settings.groups.keymapLayout?.updateButton(); + Settings.groups.keymapLayout?.updateInput(); TestLogic.restart(undefined, true); } else if (funbox === "memory") { UpdateConfig.setMode("words", true); @@ -214,7 +214,7 @@ export async function activate(funbox) { // if (funbox !== "layoutfluid" || mode !== "script") { // if (Config.layout !== Config.savedLayout) { // UpdateConfig.setLayout(Config.savedLayout); - // Settings.groups.layout.updateButton(); + // Settings.groups.layout.updateInput(); // } // } TestUI.updateModesNotice(); diff --git a/frontend/static/index.html b/frontend/static/index.html index 3fc8633b6..38d9f3435 100644 --- a/frontend/static/index.html +++ b/frontend/static/index.html @@ -2047,10 +2047,20 @@ page. This function disables tab navigation on the website.
-
+
off
-
+
on
@@ -2094,29 +2104,24 @@ focus on raw speed. If enabled, quick end is recommended.
-
+
off
-
+
-

always show words history

@@ -2124,10 +2129,19 @@ end of the test. Can cause slight lag with a lot of words.
-
+
off
-
+
on
@@ -2314,25 +2328,30 @@
off
-
+
on
-
-

language groups

-
-
-
+

language

-
+
+ Change in which language you want to type. +
+

funbox

@@ -2375,10 +2394,20 @@ Allows you to delete any word, even if it was typed correctly.
-
+
off
-
+
on
@@ -2390,10 +2419,20 @@ character when this mode is enabled.
-
+
off
-
+
on
@@ -2521,10 +2560,20 @@ last incorrect entry with a space.
-
+
off
-
+
on
@@ -2571,10 +2620,20 @@ when you press a key and nothing happens.
-
+
off
-
+
on
@@ -2585,10 +2644,20 @@ Swap the behavior of tab and escape keys.
-
+
off
-
+
on
@@ -2599,22 +2668,34 @@ Replaces accented letters with their normal equivalents.
-
+
off
-
+
on
-
+

layout emulator

With this setting you can emulate other layouts. This setting is best kept off, as it can break things like dead keys and alt layers.
-
+ +
@@ -2735,10 +2816,20 @@ space too early.
-
+
off
-
+
on
@@ -2757,10 +2848,20 @@ The caret will move smoothly between letters and words.
-
+
off
-
+
on
@@ -2882,10 +2983,20 @@ does not override the pace caret if it's already enabled.
-
+
off
-
+
on
@@ -3102,10 +3213,20 @@ When enabled, the line transition will be animated.
-
+
off
-
+
on
@@ -3119,10 +3240,20 @@ timer text and live wpm to not be visible.
-
+
off
-
+
on
@@ -3134,10 +3265,20 @@ without the need to hover over the stats.
-
+
off
-
+
on
@@ -3149,10 +3290,20 @@ default words per minute calculation.
-
+
off
-
+
on
@@ -3164,10 +3315,20 @@ data is. Turning this off may exaggerate the value changes.
-
+
off
-
+
on
@@ -3318,6 +3479,13 @@
+
+

keymap layout

+
+ Controls which layout is displayed on the keymap. +
+ +

keymap style

@@ -3393,10 +3561,6 @@
-
-

keymap layout

-
-
@@ -3415,10 +3579,20 @@ be brighter than the already typed text.
-
+
off
-
+
on
@@ -3430,10 +3604,20 @@ of the text color, making the website more colorful.
-
+
off
-
+
on
@@ -3830,10 +4014,20 @@ second.
-
+
hide
-
+
show
@@ -3842,10 +4036,20 @@

live accuracy

Displays live accuracy during the test.
-
+
hide
-
+
show
@@ -3857,10 +4061,20 @@ typed.
-
+
hide
-
+
show
@@ -3872,10 +4086,20 @@ words/custom tests.
-
+
hide
-
+
show
@@ -3886,10 +4110,20 @@ Shows the keybind tips at the bottom of the page.
-
+
hide
-
+
show
@@ -3901,10 +4135,20 @@ focus' (not being able to type).
-
+
hide
-
+
show
@@ -3913,10 +4157,20 @@

caps lock warning

Displays a warning when caps lock is on.
-
+
hide
-
+
show
@@ -3938,7 +4192,7 @@
Import or export the settings as JSON.
-