client/settings: add option to upscale small posts

This commit is contained in:
rr- 2016-06-01 22:37:12 +02:00
parent d6f27e82c6
commit aa2f4559b7
4 changed files with 19 additions and 5 deletions

View File

@ -4,6 +4,9 @@
<p>These settings are saved to the browser's local storage and are not coupled to the user account, so they don't apply to other devices or browsers alike.</p> <p>These settings are saved to the browser's local storage and are not coupled to the user account, so they don't apply to other devices or browsers alike.</p>
<div class='input'> <div class='input'>
<ul> <ul>
<li>
<%= ctx.makeCheckbox({text: 'Upscale small posts', id: 'upscale-small-posts', name: 'upscale-small-posts', checked: ctx.browsingSettings.upscaleSmallPosts}) %>
</li>
<li> <li>
<%= ctx.makeCheckbox({text: 'Endless scroll', id: 'endless-scroll', name: 'endless-scroll', checked: ctx.browsingSettings.endlessScroll}) %> <%= ctx.makeCheckbox({text: 'Endless scroll', id: 'endless-scroll', name: 'endless-scroll', checked: ctx.browsingSettings.endlessScroll}) %>
<p class='hint'>Rather than using a paged navigation, smoothly scroll through the content.</p> <p class='hint'>Rather than using a paged navigation, smoothly scroll through the content.</p>

View File

@ -1,5 +1,6 @@
'use strict'; 'use strict';
const settings = require('../settings.js');
const views = require('../util/views.js'); const views = require('../util/views.js');
const optimizedResize = require('../util/optimized_resize.js'); const optimizedResize = require('../util/optimized_resize.js');
@ -22,23 +23,30 @@ class PostContentControl {
fitWidth() { fitWidth() {
this._currentFitFunction = this.fitWidth; this._currentFitFunction = this.fitWidth;
const mul = this._post.canvasHeight / this._post.canvasWidth; const mul = this._post.canvasHeight / this._post.canvasWidth;
this._resize(this._viewportWidth, this._viewportWidth * mul); let width = this._viewportWidth;
if (!settings.getSettings().upscaleSmallPosts) {
width = Math.min(this._post.canvasWidth, width);
}
this._resize(width, width * mul);
} }
fitHeight() { fitHeight() {
this._currentFitFunction = this.fitHeight; this._currentFitFunction = this.fitHeight;
const mul = this._post.canvasWidth / this._post.canvasHeight; const mul = this._post.canvasWidth / this._post.canvasHeight;
this._resize(this._viewportHeight * mul, this._viewportHeight); let height = this._viewportHeight;
if (!settings.getSettings().upscaleSmallPosts) {
height = Math.min(this._post.canvasHeight, height);
}
this._resize(height * mul, height);
} }
fitBoth() { fitBoth() {
this._currentFitFunction = this.fitBoth; this._currentFitFunction = this.fitBoth;
let mul = this._post.canvasHeight / this._post.canvasWidth; let mul = this._post.canvasHeight / this._post.canvasWidth;
if (this._viewportWidth * mul < this._viewportHeight) { if (this._viewportWidth * mul < this._viewportHeight) {
this._resize(this._viewportWidth, this._viewportWidth * mul); this.fitWidth();
} else { } else {
mul = this._post.canvasWidth / this._post.canvasHeight; this.fitHeight();
this._resize(this._viewportHeight * mul, this._viewportHeight);
} }
} }

View File

@ -10,6 +10,7 @@ function saveSettings(browsingSettings) {
function getSettings(settings) { function getSettings(settings) {
const defaultSettings = { const defaultSettings = {
upscaleSmallPosts: false,
endlessScroll: false, endlessScroll: false,
keyboardShortcuts: true, keyboardShortcuts: true,
}; };

View File

@ -18,6 +18,8 @@ class SettingsView {
e.preventDefault(); e.preventDefault();
views.clearMessages(source); views.clearMessages(source);
ctx.saveSettings({ ctx.saveSettings({
upscaleSmallPosts:
form.querySelector('#upscale-small-posts').checked,
endlessScroll: endlessScroll:
form.querySelector('#endless-scroll').checked, form.querySelector('#endless-scroll').checked,
keyboardShortcuts: keyboardShortcuts: