mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-17 09:09:30 -07:00
parse settings from querystring
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { parseQueryString } from '../share.mjs';
|
||||
|
||||
const SETTINGS_KEY = 'Settings';
|
||||
|
||||
class Setting {
|
||||
@@ -9,10 +11,17 @@ class Setting {
|
||||
this.myValue = defaultValue;
|
||||
this.type = type;
|
||||
// a default blank change function is provided
|
||||
this.changeAction = changeAction ?? (() => {});
|
||||
this.changeAction = changeAction ?? (() => { });
|
||||
|
||||
// get value from url
|
||||
const urlValue = parseQueryString()?.[`settings-${shortName}-checkbox`];
|
||||
let urlState;
|
||||
if (urlValue !== undefined) {
|
||||
urlState = urlValue === 'true';
|
||||
}
|
||||
|
||||
// get existing value if present
|
||||
const storedValue = this.getFromLocalStorage();
|
||||
const storedValue = urlState ?? this.getFromLocalStorage();
|
||||
if (sticky && storedValue !== null) {
|
||||
this.myValue = storedValue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user