setupLivePrefs() now automatically finds the elements

To make an element a live pref discoverable by setupLivePrefs() just use the corresponding pref's id as the element's HTML id attribute.
This commit is contained in:
tophf 2017-04-21 19:39:34 +03:00
parent 5eb55baa95
commit 135423860d
5 changed files with 8 additions and 15 deletions

View File

@ -271,10 +271,7 @@ function initCodeMirror() {
} }
document.getElementById("editor.keyMap").innerHTML = optionsHtmlFromArray(Object.keys(CM.keyMap).sort()); document.getElementById("editor.keyMap").innerHTML = optionsHtmlFromArray(Object.keys(CM.keyMap).sort());
document.getElementById("options").addEventListener("change", acmeEventListener, false); document.getElementById("options").addEventListener("change", acmeEventListener, false);
setupLivePrefs( setupLivePrefs();
document.querySelectorAll("#options *[data-option][id^='editor.']")
.map(function(option) { return option.id })
);
hotkeyRerouter.setState(true); hotkeyRerouter.setState(true);
} }

View File

@ -80,7 +80,7 @@ function initGlobalEvents() {
enforceInputRange($('#manage.newUI.targets')); enforceInputRange($('#manage.newUI.targets'));
// N.B. triggers existing onchange listeners // N.B. triggers existing onchange listeners
setupLivePrefs($$('input[id^="manage."]').map(el => el.id)); setupLivePrefs();
$$('[data-filter]').forEach(el => { $$('[data-filter]').forEach(el => {
el.onchange = handleEvent.filterOnChange; el.onchange = handleEvent.filterOnChange;

View File

@ -1,13 +1,6 @@
'use strict'; 'use strict';
setupLivePrefs([ setupLivePrefs();
'show-badge',
'popup.stylesFirst',
'badgeNormal',
'badgeDisabled',
'popupWidth',
'updateInterval',
]);
enforceInputRange($('#popupWidth')); enforceInputRange($('#popupWidth'));
// overwrite the default URL if browser is Opera // overwrite the default URL if browser is Opera

View File

@ -62,7 +62,7 @@ function initPopup(url) {
$('#disableAll').onchange = function() { $('#disableAll').onchange = function() {
installed.classList.toggle('disabled', this.checked); installed.classList.toggle('disabled', this.checked);
}; };
setupLivePrefs(['disableAll']); setupLivePrefs();
$('#find-styles-link').onclick = handleEvent.openURLandHide; $('#find-styles-link').onclick = handleEvent.openURLandHide;
$('#popup-manage-button').onclick = handleEvent.openURLandHide; $('#popup-manage-button').onclick = handleEvent.openURLandHide;

View File

@ -302,7 +302,10 @@ var prefs = new function Prefs() {
// Accepts an array of pref names (values are fetched via prefs.get) // Accepts an array of pref names (values are fetched via prefs.get)
// and establishes a two-way connection between the document elements and the actual prefs // and establishes a two-way connection between the document elements and the actual prefs
function setupLivePrefs(IDs) { function setupLivePrefs(
IDs = Object.getOwnPropertyNames(prefs.readOnlyValues)
.filter(id => document.getElementById(id))
) {
const checkedProps = {}; const checkedProps = {};
for (const id of IDs) { for (const id of IDs) {
const element = document.getElementById(id); const element = document.getElementById(id);