Commit ee5cca00 authored by Thomas Rientjes's avatar Thomas Rientjes
Browse files

Improve code documentation

parent d3f8e343
...@@ -6,18 +6,31 @@ ...@@ -6,18 +6,31 @@
'use strict'; 'use strict';
/**
* Page event aggregator.
*
* @var {Object} vent
*/
var vent = {}; var vent = {};
/**
* Fires at the end of the document loading process.
*/
window.onload = function () { window.onload = function () {
let controls = document.querySelectorAll('[data-setting-id]'); let controls = document.querySelectorAll('[data-setting-id]');
for (var index = 0, control; control = controls[index]; index++) { for (var index = 0, control; control = controls[index]; index++) {
control.addEventListener('change', handleSettingChange); control.addEventListener('change', handleSettingAlteration);
} }
}; };
function handleSettingChange ({ target }) { /**
* Fires once a setting value has been altered.
*
* @property {Event} event A representation of a DOM event.
*/
function handleSettingAlteration ({ target }) {
let settingId, previousValue, currentValue; let settingId, previousValue, currentValue;
...@@ -25,17 +38,20 @@ function handleSettingChange ({ target }) { ...@@ -25,17 +38,20 @@ function handleSettingChange ({ target }) {
previousValue = target.getAttribute('data-previous-value') || null; previousValue = target.getAttribute('data-previous-value') || null;
currentValue = target.value; currentValue = target.value;
// Apply the setting to the user interface.
applySetting({ applySetting({
id: settingId, id: settingId,
value: currentValue value: currentValue
}); });
// Inform the attached content script.
vent.emit('setting:altered', { vent.emit('setting:altered', {
settingId: settingId, settingId: settingId,
previousValue: previousValue, previousValue: previousValue,
currentValue: currentValue currentValue: currentValue
}); });
// Memorize the previous value of the setting.
target.setAttribute('data-previous-value', currentValue); target.setAttribute('data-previous-value', currentValue);
} }
...@@ -101,7 +117,6 @@ function applySetting (setting) { ...@@ -101,7 +117,6 @@ function applySetting (setting) {
* https://bugzilla.mozilla.org/show_bug.cgi?id=787351 * https://bugzilla.mozilla.org/show_bug.cgi?id=787351
* *
* @param {Object} l10n A localization object. * @param {Object} l10n A localization object.
* @private
*/ */
function applyL10n (l10n) { function applyL10n (l10n) {
......
...@@ -116,12 +116,15 @@ function showSettingsPanel () { ...@@ -116,12 +116,15 @@ function showSettingsPanel () {
if (settingsTab === null) { if (settingsTab === null) {
// Open up the settings panel in a new tab.
tabBrowser.addTab(SETTINGS_URI, { tabBrowser.addTab(SETTINGS_URI, {
selected: true, selected: true,
parentId: tabBrowser.selectedTab.id parentId: tabBrowser.selectedTab.id
}); });
} else { } else {
// Activate an existing settings panel tab.
tabBrowser.selectTab(settingsTab); tabBrowser.selectTab(settingsTab);
} }
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment