2016-04-11 20:38:59 +00:00
|
|
|
'use strict';
|
|
|
|
|
2016-06-14 08:31:48 +00:00
|
|
|
const events = require('../events.js');
|
2016-04-11 20:38:59 +00:00
|
|
|
const views = require('../util/views.js');
|
|
|
|
|
2016-06-14 08:31:48 +00:00
|
|
|
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}));
|
2016-07-13 15:18:28 +00:00
|
|
|
views.syncScrollPosition();
|
2016-06-14 08:31:48 +00:00
|
|
|
|
2016-07-13 15:18:28 +00:00
|
|
|
views.decorateValidator(this._formNode);
|
2016-06-14 08:31:48 +00:00
|
|
|
this._formNode.addEventListener('submit', e => this._evtSubmit(e));
|
|
|
|
}
|
|
|
|
|
|
|
|
clearMessages() {
|
|
|
|
views.clearMessages(this._hostNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
showSuccess(text) {
|
|
|
|
views.showSuccess(this._hostNode, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
_evtSubmit(e) {
|
|
|
|
e.preventDefault();
|
2016-08-22 18:45:58 +00:00
|
|
|
this.dispatchEvent(new CustomEvent('submit', {
|
2016-06-14 08:31:48 +00:00
|
|
|
detail: {
|
2016-08-05 18:09:11 +00:00
|
|
|
upscaleSmallPosts: this._find('upscale-small-posts').checked,
|
|
|
|
endlessScroll: this._find('endless-scroll').checked,
|
|
|
|
keyboardShortcuts: this._find('keyboard-shortcuts').checked,
|
|
|
|
transparencyGrid: this._find('transparency-grid').checked,
|
|
|
|
tagSuggestions: this._find('tag-suggestions').checked,
|
2016-11-11 22:14:51 +00:00
|
|
|
autoplayVideos: this._find('autoplay-videos').checked,
|
2016-08-05 18:09:11 +00:00
|
|
|
postsPerPage: this._find('posts-per-page').value,
|
2016-06-14 08:31:48 +00:00
|
|
|
},
|
|
|
|
}));
|
2016-04-11 20:38:59 +00:00
|
|
|
}
|
|
|
|
|
2016-06-14 08:31:48 +00:00
|
|
|
get _formNode() {
|
|
|
|
return this._hostNode.querySelector('form');
|
2016-04-11 20:38:59 +00:00
|
|
|
}
|
2016-08-05 18:09:11 +00:00
|
|
|
|
|
|
|
_find(nodeName) {
|
|
|
|
return this._formNode.querySelector('[name=' + nodeName + ']');
|
|
|
|
}
|
2016-04-11 20:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = SettingsView;
|