More suggested changes

This commit is contained in:
Rob Garrison 2018-09-17 23:08:16 -05:00
parent 0678a6b302
commit 314ec99e5c

View File

@ -197,8 +197,12 @@ function configDialog(style) {
renderValues(); renderValues();
} }
function isNullOrUndefined(value) {
return value === null || value === undefined;
}
function isDefault(va) { function isDefault(va) {
return va.value === null || va.value === undefined || va.value === va.default; return isNullOrUndefined(va.value) || va.value === va.default;
} }
function buildConfigForm() { function buildConfigForm() {
@ -259,33 +263,40 @@ function configDialog(style) {
break; break;
case 'range': case 'range':
case 'number': case 'number': {
children = [ const options = {
va.type === 'range' && $create('span.current-value', {textContent: va.value + va.units}),
va.input = $create('input.config-value', {
va, va,
type: va.type, type: va.type,
value: va.default, onfocus: va.type === 'number' ? selectAllOnFocus : null,
min: va.min, onchange: updateVarOnChange,
max: va.max, oninput: updateVarOnInput
step: va.step, };
onchange: updateVarOnChange if (!isNullOrUndefined(va.min)) {
}) options.min = va.min;
}
if (!isNullOrUndefined(va.max)) {
options.max = va.max;
}
if (!isNullOrUndefined(va.step)) {
options.step = va.step;
}
children = [
va.type === 'range' && $create('span.current-value'),
va.input = $create('input.config-value', options)
]; ];
break; break;
}
default: { default:
const options = { children = [
va.input = $create('input.config-value', {
va, va,
type: va.type, type: va.type,
onchange: updateVarOnChange, onchange: updateVarOnChange,
oninput: updateVarOnInput, oninput: updateVarOnInput,
onfocus: selectAllOnFocus, onfocus: selectAllOnFocus,
}; }),
children = [
va.input = $create('input.config-value', options),
]; ];
}
} }
@ -308,7 +319,7 @@ function configDialog(style) {
if (this.type === 'number') { if (this.type === 'number') {
this.value = this.va.value = clampValue(this.value, this.va); this.value = this.va.value = clampValue(this.value, this.va);
} else if (this.type === 'range') { } else if (this.type === 'range') {
this.va.value = parseFloat(this.value); this.va.value = Number(this.value);
$('.current-value', this.closest('.config-range')).textContent = this.va.value + (this.va.units || ''); $('.current-value', this.closest('.config-range')).textContent = this.va.value + (this.va.units || '');
} else { } else {
this.va.value = this.type !== 'checkbox' ? this.value : this.checked ? '1' : '0'; this.va.value = this.type !== 'checkbox' ? this.value : this.checked ? '1' : '0';