mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-22 19:49:31 -07:00
add speed setting close #49
This commit is contained in:
2
dist/index.html
vendored
2
dist/index.html
vendored
File diff suppressed because one or more lines are too long
2
dist/resources/ws.min.css
vendored
2
dist/resources/ws.min.css
vendored
File diff suppressed because one or more lines are too long
2
dist/resources/ws.min.js
vendored
2
dist/resources/ws.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -4,20 +4,28 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
init();
|
init();
|
||||||
});
|
});
|
||||||
|
|
||||||
const settings = {};
|
// default speed
|
||||||
|
const settings = { speed: { value: 1.0 } };
|
||||||
|
|
||||||
const init = () => {
|
const init = () => {
|
||||||
// create settings
|
// create settings
|
||||||
settings.wide = new Setting('wide', 'Widescreen', 'boolean', false, wideScreenChange, true);
|
settings.wide = new Setting('wide', 'Widescreen', 'boolean', false, wideScreenChange, true);
|
||||||
settings.kiosk = new Setting('kiosk', 'Kiosk', 'boolean', false, kioskChange, false);
|
settings.kiosk = new Setting('kiosk', 'Kiosk', 'boolean', false, kioskChange, false);
|
||||||
|
settings.speed = new Setting('speed', 'Speed', 'select', 1.0, null, true, [
|
||||||
|
[0.5, 'Very Fast'],
|
||||||
|
[0.75, 'Fast'],
|
||||||
|
[1.0, 'Normal'],
|
||||||
|
[1.25, 'Slow'],
|
||||||
|
[1.5, 'Very Slow'],
|
||||||
|
]);
|
||||||
|
|
||||||
// generate checkboxes
|
// generate html objects
|
||||||
const checkboxes = Object.values(settings).map((d) => d.generateCheckbox());
|
const settingHtml = Object.values(settings).map((d) => d.generate());
|
||||||
|
|
||||||
// write to page
|
// write to page
|
||||||
const settingsSection = document.querySelector('#settings');
|
const settingsSection = document.querySelector('#settings');
|
||||||
settingsSection.innerHTML = '';
|
settingsSection.innerHTML = '';
|
||||||
settingsSection.append(...checkboxes);
|
settingsSection.append(...settingHtml);
|
||||||
};
|
};
|
||||||
|
|
||||||
const wideScreenChange = (value) => {
|
const wideScreenChange = (value) => {
|
||||||
|
|||||||
@@ -31,6 +31,14 @@ const createLink = async (e) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// get all select boxes
|
||||||
|
const selects = document.querySelectorAll('select');
|
||||||
|
[...selects].forEach((elem) => {
|
||||||
|
if (elem?.id) {
|
||||||
|
queryStringElements[elem.id] = elem?.value ?? 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// add the location string
|
// add the location string
|
||||||
queryStringElements.latLonQuery = localStorage.getItem('latLonQuery');
|
queryStringElements.latLonQuery = localStorage.getItem('latLonQuery');
|
||||||
queryStringElements.latLon = localStorage.getItem('latLon');
|
queryStringElements.latLon = localStorage.getItem('latLon');
|
||||||
|
|||||||
@@ -3,23 +3,27 @@ import { parseQueryString } from '../share.mjs';
|
|||||||
const SETTINGS_KEY = 'Settings';
|
const SETTINGS_KEY = 'Settings';
|
||||||
|
|
||||||
class Setting {
|
class Setting {
|
||||||
constructor(shortName, name, type, defaultValue, changeAction, sticky) {
|
constructor(shortName, name, type, defaultValue, changeAction, sticky, values) {
|
||||||
// store values
|
// store values
|
||||||
this.shortName = shortName;
|
this.shortName = shortName;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.defaultValue = defaultValue;
|
this.defaultValue = defaultValue;
|
||||||
this.myValue = defaultValue;
|
this.myValue = defaultValue;
|
||||||
this.type = type;
|
this.type = type ?? 'checkbox';
|
||||||
this.sticky = sticky;
|
this.sticky = sticky;
|
||||||
|
this.values = values;
|
||||||
// a default blank change function is provided
|
// a default blank change function is provided
|
||||||
this.changeAction = changeAction ?? (() => { });
|
this.changeAction = changeAction ?? (() => { });
|
||||||
|
|
||||||
// get value from url
|
// get value from url
|
||||||
const urlValue = parseQueryString()?.[`settings-${shortName}-checkbox`];
|
const urlValue = parseQueryString()?.[`settings-${shortName}-${type}`];
|
||||||
let urlState;
|
let urlState;
|
||||||
if (urlValue !== undefined) {
|
if (type === 'checkbox' && urlValue !== undefined) {
|
||||||
urlState = urlValue === 'true';
|
urlState = urlValue === 'true';
|
||||||
}
|
}
|
||||||
|
if (type === 'select' && urlValue !== undefined) {
|
||||||
|
urlState = parseFloat(urlValue);
|
||||||
|
}
|
||||||
|
|
||||||
// get existing value if present
|
// get existing value if present
|
||||||
const storedValue = urlState ?? this.getFromLocalStorage();
|
const storedValue = urlState ?? this.getFromLocalStorage();
|
||||||
@@ -28,7 +32,46 @@ class Setting {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// call the change function on startup
|
// call the change function on startup
|
||||||
this.checkboxChange({ target: { checked: this.myValue } });
|
switch (type) {
|
||||||
|
case 'select':
|
||||||
|
this.selectChange({ target: { value: this.myValue } });
|
||||||
|
break;
|
||||||
|
case 'checkbox':
|
||||||
|
default:
|
||||||
|
this.checkboxChange({ target: { checked: this.myValue } });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
generateSelect() {
|
||||||
|
// create a radio button set in the selected displays area
|
||||||
|
const label = document.createElement('label');
|
||||||
|
label.for = `settings-${this.shortName}-select`;
|
||||||
|
label.id = `settings-${this.shortName}-label`;
|
||||||
|
|
||||||
|
const span = document.createElement('span');
|
||||||
|
span.innerHTML = `${this.name} `;
|
||||||
|
label.append(span);
|
||||||
|
|
||||||
|
const select = document.createElement('select');
|
||||||
|
select.id = `settings-${this.shortName}-select`;
|
||||||
|
select.name = `settings-${this.shortName}-select`;
|
||||||
|
select.addEventListener('change', (e) => this.selectChange(e));
|
||||||
|
|
||||||
|
this.values.forEach(([value, text]) => {
|
||||||
|
const option = document.createElement('option');
|
||||||
|
option.value = value.toFixed(2);
|
||||||
|
|
||||||
|
option.innerHTML = text;
|
||||||
|
select.append(option);
|
||||||
|
});
|
||||||
|
label.append(select);
|
||||||
|
|
||||||
|
this.element = label;
|
||||||
|
|
||||||
|
// set the initial value
|
||||||
|
this.selectHighlight(this.myValue);
|
||||||
|
|
||||||
|
return label;
|
||||||
}
|
}
|
||||||
|
|
||||||
generateCheckbox() {
|
generateCheckbox() {
|
||||||
@@ -48,7 +91,7 @@ class Setting {
|
|||||||
|
|
||||||
label.append(checkbox, span);
|
label.append(checkbox, span);
|
||||||
|
|
||||||
this.checkbox = label;
|
this.element = label;
|
||||||
|
|
||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
@@ -62,6 +105,15 @@ class Setting {
|
|||||||
this.changeAction(this.myValue);
|
this.changeAction(this.myValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
selectChange(e) {
|
||||||
|
// update the value
|
||||||
|
this.myValue = parseFloat(e.target.value);
|
||||||
|
this.storeToLocalStorage(this.myValue);
|
||||||
|
|
||||||
|
// call the change action
|
||||||
|
this.changeAction(this.myValue);
|
||||||
|
}
|
||||||
|
|
||||||
storeToLocalStorage(value) {
|
storeToLocalStorage(value) {
|
||||||
if (!this.sticky) return;
|
if (!this.sticky) return;
|
||||||
const allSettingsString = localStorage?.getItem(SETTINGS_KEY) ?? '{}';
|
const allSettingsString = localStorage?.getItem(SETTINGS_KEY) ?? '{}';
|
||||||
@@ -79,7 +131,7 @@ class Setting {
|
|||||||
switch (this.type) {
|
switch (this.type) {
|
||||||
case 'boolean':
|
case 'boolean':
|
||||||
return storedValue;
|
return storedValue;
|
||||||
case 'int':
|
case 'select':
|
||||||
return storedValue;
|
return storedValue;
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
@@ -99,12 +151,36 @@ class Setting {
|
|||||||
set value(newValue) {
|
set value(newValue) {
|
||||||
// update the state
|
// update the state
|
||||||
this.myValue = newValue;
|
this.myValue = newValue;
|
||||||
this.checkbox.checked = newValue;
|
switch (this.type) {
|
||||||
|
case 'select':
|
||||||
|
this.selectHighlight(newValue);
|
||||||
|
break;
|
||||||
|
case 'checkbox':
|
||||||
|
default:
|
||||||
|
this.element.checked = newValue;
|
||||||
|
}
|
||||||
this.storeToLocalStorage(this.myValue);
|
this.storeToLocalStorage(this.myValue);
|
||||||
|
|
||||||
// call change action
|
// call change action
|
||||||
this.changeAction(this.myValue);
|
this.changeAction(this.myValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
selectHighlight(newValue) {
|
||||||
|
// set the dropdown to the provided value
|
||||||
|
this.element.querySelectorAll('option').forEach((elem) => {
|
||||||
|
elem.selected = newValue.toFixed(2) === elem.value;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
generate() {
|
||||||
|
switch (this.type) {
|
||||||
|
case 'select':
|
||||||
|
return this.generateSelect();
|
||||||
|
case 'checkbox':
|
||||||
|
default:
|
||||||
|
return this.generateCheckbox();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Setting;
|
export default Setting;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
msg, displayNavMessage, isPlaying, updateStatus, timeZone,
|
msg, displayNavMessage, isPlaying, updateStatus, timeZone,
|
||||||
} from './navigation.mjs';
|
} from './navigation.mjs';
|
||||||
import { parseQueryString } from './share.mjs';
|
import { parseQueryString } from './share.mjs';
|
||||||
|
import settings from './settings.mjs';
|
||||||
|
|
||||||
class WeatherDisplay {
|
class WeatherDisplay {
|
||||||
constructor(navId, elemId, name, defaultEnabled) {
|
constructor(navId, elemId, name, defaultEnabled) {
|
||||||
@@ -358,7 +359,7 @@ class WeatherDisplay {
|
|||||||
|
|
||||||
// start and stop base counter
|
// start and stop base counter
|
||||||
startNavCount() {
|
startNavCount() {
|
||||||
if (!this.navInterval) this.navInterval = setInterval(() => this.navBaseTime(), this.timing.baseDelay);
|
if (!this.navInterval) this.navInterval = setInterval(() => this.navBaseTime(), this.timing.baseDelay * settings.speed.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
resetNavBaseCount() {
|
resetNavBaseCount() {
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user