optionsHtmlFromArray to optionsFromArray

This commit is contained in:
Jeremy Schomery 2017-07-19 13:01:09 +04:30 committed by tophf
parent f5c125d61c
commit 0e9c8f290c

View File

@ -260,24 +260,26 @@ function initCodeMirror() {
}; };
// initialize global editor controls // initialize global editor controls
function optionsHtmlFromArray(options) { function optionsFromArray(parent, options) {
return options.map(opt => '<option>' + opt + '</option>').join(''); console.log(parent, options);
options.map(opt => $element({tag: 'option', textContent: opt}))
.forEach(opt => parent.appendChild(opt));
} }
const themeControl = document.getElementById('editor.theme'); const themeControl = document.getElementById('editor.theme');
const themeList = localStorage.codeMirrorThemes; const themeList = localStorage.codeMirrorThemes;
if (themeList) { if (themeList) {
themeControl.innerHTML = optionsHtmlFromArray(themeList.split(/\s+/)); optionsFromArray(themeControl, themeList.split(/\s+/));
} else { } else {
// Chrome is starting up and shows our edit.html, but the background page isn't loaded yet // Chrome is starting up and shows our edit.html, but the background page isn't loaded yet
const theme = prefs.get('editor.theme'); const theme = prefs.get('editor.theme');
themeControl.innerHTML = optionsHtmlFromArray([theme === 'default' ? t('defaultTheme') : theme]); optionsFromArray(themeControl, [theme === 'default' ? t('defaultTheme') : theme]);
getCodeMirrorThemes().then(() => { getCodeMirrorThemes().then(() => {
const themes = (localStorage.codeMirrorThemes || '').split(/\s+/); const themes = (localStorage.codeMirrorThemes || '').split(/\s+/);
themeControl.innerHTML = optionsHtmlFromArray(themes); optionsFromArray(themeControl, themes);
themeControl.selectedIndex = Math.max(0, themes.indexOf(theme)); themeControl.selectedIndex = Math.max(0, themes.indexOf(theme));
}); });
} }
document.getElementById('editor.keyMap').innerHTML = optionsHtmlFromArray(Object.keys(CM.keyMap).sort()); optionsFromArray($('#editor.keyMap'), Object.keys(CM.keyMap).sort());
document.getElementById('options').addEventListener('change', acmeEventListener, false); document.getElementById('options').addEventListener('change', acmeEventListener, false);
setupLivePrefs(); setupLivePrefs();