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:
parent
5eb55baa95
commit
135423860d
5
edit.js
5
edit.js
|
@ -271,10 +271,7 @@ function initCodeMirror() {
|
|||
}
|
||||
document.getElementById("editor.keyMap").innerHTML = optionsHtmlFromArray(Object.keys(CM.keyMap).sort());
|
||||
document.getElementById("options").addEventListener("change", acmeEventListener, false);
|
||||
setupLivePrefs(
|
||||
document.querySelectorAll("#options *[data-option][id^='editor.']")
|
||||
.map(function(option) { return option.id })
|
||||
);
|
||||
setupLivePrefs();
|
||||
|
||||
hotkeyRerouter.setState(true);
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ function initGlobalEvents() {
|
|||
enforceInputRange($('#manage.newUI.targets'));
|
||||
|
||||
// N.B. triggers existing onchange listeners
|
||||
setupLivePrefs($$('input[id^="manage."]').map(el => el.id));
|
||||
setupLivePrefs();
|
||||
|
||||
$$('[data-filter]').forEach(el => {
|
||||
el.onchange = handleEvent.filterOnChange;
|
||||
|
|
|
@ -1,13 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
setupLivePrefs([
|
||||
'show-badge',
|
||||
'popup.stylesFirst',
|
||||
'badgeNormal',
|
||||
'badgeDisabled',
|
||||
'popupWidth',
|
||||
'updateInterval',
|
||||
]);
|
||||
setupLivePrefs();
|
||||
enforceInputRange($('#popupWidth'));
|
||||
|
||||
// overwrite the default URL if browser is Opera
|
||||
|
|
2
popup.js
2
popup.js
|
@ -62,7 +62,7 @@ function initPopup(url) {
|
|||
$('#disableAll').onchange = function() {
|
||||
installed.classList.toggle('disabled', this.checked);
|
||||
};
|
||||
setupLivePrefs(['disableAll']);
|
||||
setupLivePrefs();
|
||||
|
||||
$('#find-styles-link').onclick = handleEvent.openURLandHide;
|
||||
$('#popup-manage-button').onclick = handleEvent.openURLandHide;
|
||||
|
|
5
prefs.js
5
prefs.js
|
@ -302,7 +302,10 @@ var prefs = new function Prefs() {
|
|||
|
||||
// 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
|
||||
function setupLivePrefs(IDs) {
|
||||
function setupLivePrefs(
|
||||
IDs = Object.getOwnPropertyNames(prefs.readOnlyValues)
|
||||
.filter(id => document.getElementById(id))
|
||||
) {
|
||||
const checkedProps = {};
|
||||
for (const id of IDs) {
|
||||
const element = document.getElementById(id);
|
||||
|
|
Loading…
Reference in New Issue
Block a user