Fix: use switch-case

This commit is contained in:
eight 2017-11-09 09:00:46 +08:00
parent 7842ac752a
commit c17433c350

View File

@ -42,58 +42,68 @@ function configDialog(style) {
for (const key of Object.keys(vars)) { for (const key of Object.keys(vars)) {
const va = vars[key]; const va = vars[key];
let appendChild; let appendChild;
if (va.type === 'color') { switch (va.type) {
va.inputColor = $element({tag: 'input', type: 'color'}); case 'color':
va.inputAlpha = $element({ va.inputColor = $element({tag: 'input', type: 'color'});
tag: 'input', va.inputAlpha = $element({
type: 'range', tag: 'input',
min: 0, type: 'range',
max: 1, min: 0,
title: chrome.i18n.getMessage('alphaChannel'), max: 1,
step: 'any' title: chrome.i18n.getMessage('alphaChannel'),
}); step: 'any'
va.inputColor.onchange = va.inputAlpha.oninput = () => { });
va.dirty = true; va.inputColor.onchange = va.inputAlpha.oninput = () => {
const color = colorParser.parse(va.inputColor.value); va.dirty = true;
color.a = Number(va.inputAlpha.value); const color = colorParser.parse(va.inputColor.value);
va.value = colorParser.format(color); color.a = Number(va.inputAlpha.value);
va.inputColor.style.opacity = color.a; va.value = colorParser.format(color);
}; va.inputColor.style.opacity = color.a;
appendChild = [ };
$element({appendChild: [va.inputColor, va.inputAlpha]}) appendChild = [
]; $element({appendChild: [va.inputColor, va.inputAlpha]})
} else if (va.type === 'checkbox') { ];
va.input = $element({tag: 'input', type: 'checkbox'}); break;
va.input.onchange = () => {
va.dirty = true; case 'checkbox':
va.value = String(Number(va.input.checked)); va.input = $element({tag: 'input', type: 'checkbox'});
}; va.input.onchange = () => {
appendChild = [ va.dirty = true;
$element({tag: 'span', className: 'onoffswitch', appendChild: [ va.value = String(Number(va.input.checked));
va.input, };
$element({tag: 'span'}) appendChild = [
]}) $element({tag: 'span', className: 'onoffswitch', appendChild: [
]; va.input,
} else if (va.type === 'select' || va.type === 'dropdown' || va.type === 'image') { $element({tag: 'span'})
// TODO: a image picker input? ]})
va.input = $element({ ];
tag: 'select', break;
appendChild: va.options.map(o => $element({
tag: 'option', value: o.name, textContent: o.label case 'select':
})) case 'dropdown':
}); case 'image':
va.input.onchange = () => { // TODO: a image picker input?
va.dirty = true; va.input = $element({
va.value = va.input.value; tag: 'select',
}; appendChild: va.options.map(o => $element({
appendChild = [va.input]; tag: 'option', value: o.name, textContent: o.label
} else { }))
va.input = $element({tag: 'input', type: 'text'}); });
va.input.oninput = () => { va.input.onchange = () => {
va.dirty = true; va.dirty = true;
va.value = va.input.value; va.value = va.input.value;
}; };
appendChild = [va.input]; appendChild = [va.input];
break;
default:
va.input = $element({tag: 'input', type: 'text'});
va.input.oninput = () => {
va.dirty = true;
va.value = va.input.value;
};
appendChild = [va.input];
break;
} }
appendChild.unshift($element({tag: 'span', appendChild: va.label})); appendChild.unshift($element({tag: 'span', appendChild: va.label}));
labels.push($element({ labels.push($element({