Microsoft is acquiring GitHub. Decentraleyes is leaving GitHub. Welcome to its new home!

To participate, please register, or sign in with an existing GitLab.com, Bitbucket, or GitHub account.

Past contributions on GitHub? Be sure to reclaim your Comments, Issues, and Pull Requests.

Commit d6123121 authored by Thomas Rientjes's avatar Thomas Rientjes

Create Setting and SettingAlteration models

parent 0b7aec0b
/**
* Setting alteration model.
*/
class SettingAlteration {
/**
* Creates a setting alteration model.
*
* @param {String} settingId - The identifier of the altered setting.
* @param {String} previousValue - The previous value of the altered setting.
* @param {String} currentValue - The current value of the altered setting.
*/
constructor (settingId, previousValue, currentValue) {
this.settingId = settingId;
this.previousValue = previousValue;
this.currentValue = currentValue;
}
}
/**
* Application settings page script.
*
* @module chrome/settings
*/
'use strict';
window.onload = function () {
var controls = {
securityLevel: document.querySelector('[data-setting-id="security_level"]')
};
controls.securityLevel.addEventListener('change', function () {
// TODO
});
}
......@@ -11,6 +11,9 @@
<link rel="stylesheet" type="text/css" href="css/settings.css">
<script src="js/models/setting-alteration.js"></script>
<script src="js/settings.js"></script>
</head>
<body>
......
......@@ -25,7 +25,6 @@ self.port.once('worker:initialized', function (initialState) {
* @param {Object} setting The fetched application setting.
*/
self.port.on('setting:fetched', function (setting) {
applySetting(setting);
});
......@@ -58,26 +57,24 @@ function applyL10n (l10n) {
*/
function applySettings (settings) {
let settingKeys = Object.keys(settings);
let settingIds = Object.keys(settings);
settingKeys.forEach(function (settingKey) {
settingIds.forEach(function (settingId) {
applySetting({
key: settingKey,
value: settings[settingKey]
});
let setting = settings[settingId];
applySetting(setting);
});
}
/**
* Applies a given setting to the user interface.
*
* @param {Object} setting An application setting object.
* @param {Setting} setting An application setting object.
* @private
*/
function applySetting (setting) {
let elements = document.querySelectorAll('[data-setting-id="' + setting.key + '"]');
let elements = document.querySelectorAll('[data-setting-id="' + setting.id + '"]');
for (let element of elements) {
......@@ -91,18 +88,18 @@ function applySetting (setting) {
* Fetch setting event emitter.
*
* @event setting:fetch
* @property {String} settingKey The key of the requested setting.
* @property {String} settingId The identifier of the requested setting.
*/
function fetchSetting (settingKey) {
self.port.emit('setting:fetch', settingKey);
function fetchSetting (settingId) {
self.port.emit('setting:fetch', settingId);
}
/**
* Setting changed event emitter.
* Setting altered event emitter.
*
* @event setting:changed
* @property {Object} setting The updated setting.
* @event setting:altered
* @property {SettingAlteration} settingAlteration The setting alteration details.
*/
function settingChanged (setting) {
self.port.emit('setting:changed', setting);
function settingAltered (settingAlteration) {
self.port.emit('setting:altered', settingAlteration);
}
/**
* Setting model.
*/
class Setting {
/**
* Creates a setting model.
*
* @param {String} id - The setting identifier.
* @param {String} value - The value of the setting.
*/
constructor (id, value) {
this.id = id;
this.value = value;
}
};
exports.Setting = Setting;
......@@ -24,6 +24,13 @@ const BROWSER_NAME = 'Orfox';
*/
const SETTINGS_URI = 'chrome://tor-browser-settings/content/settings.html';
/**
* The setting model.
*
* @var {Setting} Setting
*/
var { Setting } = require('./models/setting');
/**
* Can be used to get localization entries by key name.
*
......@@ -90,23 +97,23 @@ function startListening (worker) {
learn_more_label: _('learn_more_label')
},
settings: {
security_level: 1
security_level: new Setting('security_level', 2)
}
});
worker.port.on('setting:fetch', function (settingKey) {
worker.port.on('setting:fetch', function (settingId) {
let fetchedSetting = {
key: settingKey,
value: settings[settingKey]
};
let fetchedSetting;
fetchedSetting = new Setting(settingId, settings[settingId]);
worker.port.emit('setting:fetched', fetchedSetting);
});
worker.port.on('setting:changed', function (details) {
worker.port.on('setting:altered', function (settingId, newValue) {
settings[settingId] = newValue;
settings[details.key] = details.value;
worker.port.emit('setting:persisted', details);
var persistedSetting = new Setting(settingId, newValue);
worker.port.emit('setting:persisted', persistedSetting);
});
}
Markdown is supported
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