54e3099c56
- Controller lifetime is bound to route lifetime - View lifetime is bound to controller lifetime - Control lifetime is bound to view lifetime - Enhanced event dispatching - Enhanced responsiveness in some places - Views communicate user input to controllers via new event system
51 lines
1.5 KiB
JavaScript
51 lines
1.5 KiB
JavaScript
'use strict';
|
|
|
|
const events = require('../events.js');
|
|
const views = require('../util/views.js');
|
|
|
|
const template = views.getTemplate('settings');
|
|
|
|
class SettingsView extends events.EventTarget {
|
|
constructor(ctx) {
|
|
super();
|
|
|
|
this._hostNode = document.getElementById('content-holder');
|
|
views.replaceContent(
|
|
this._hostNode, template({browsingSettings: ctx.settings}));
|
|
views.decorateValidator(this._formNode);
|
|
|
|
this._formNode.addEventListener('submit', e => this._evtSubmit(e));
|
|
}
|
|
|
|
clearMessages() {
|
|
views.clearMessages(this._hostNode);
|
|
}
|
|
|
|
showSuccess(text) {
|
|
views.showSuccess(this._hostNode, text);
|
|
}
|
|
|
|
_evtSubmit(e) {
|
|
e.preventDefault();
|
|
this.dispatchEvent(new CustomEvent('change', {
|
|
detail: {
|
|
settings: {
|
|
upscaleSmallPosts: this._formNode.querySelector(
|
|
'#upscale-small-posts').checked,
|
|
endlessScroll: this._formNode.querySelector(
|
|
'#endless-scroll').checked,
|
|
keyboardShortcuts: this._formNode.querySelector(
|
|
'#keyboard-shortcuts').checked,
|
|
transparencyGrid: this._formNode.querySelector(
|
|
'#transparency-grid').checked,
|
|
},
|
|
},
|
|
}));
|
|
}
|
|
|
|
get _formNode() {
|
|
return this._hostNode.querySelector('form');
|
|
}
|
|
}
|
|
|
|
module.exports = SettingsView;
|