client/posts: remember fit mode
This commit is contained in:
parent
c8e57146f3
commit
1f413763bd
4 changed files with 30 additions and 8 deletions
|
@ -39,6 +39,8 @@ class PostController {
|
|||
'unfavorite', e => this._evtUnfavoritePost(e));
|
||||
this._view.sidebarControl.addEventListener(
|
||||
'score', e => this._evtScorePost(e));
|
||||
this._view.sidebarControl.addEventListener(
|
||||
'fitModeChange', e => this._evtFitModeChange(e));
|
||||
}
|
||||
if (this._view.commentFormControl) {
|
||||
this._view.commentFormControl.addEventListener(
|
||||
|
@ -74,6 +76,12 @@ class PostController {
|
|||
return text.trim();
|
||||
}
|
||||
|
||||
_evtFitModeChange(e) {
|
||||
const browsingSettings = settings.get();
|
||||
browsingSettings.fitMode = e.detail.mode;
|
||||
settings.save(browsingSettings);
|
||||
}
|
||||
|
||||
_evtCommentChange(e) {
|
||||
misc.enableExitConfirmation();
|
||||
}
|
||||
|
|
|
@ -13,7 +13,12 @@ class PostContentControl {
|
|||
|
||||
this._install();
|
||||
|
||||
this._currentFitFunction = this.fitBoth;
|
||||
this._currentFitFunction = {
|
||||
'fit-both': this.fitBoth,
|
||||
'fit-original': this.fitOriginal,
|
||||
'fit-width': this.fitWidth,
|
||||
'fit-height': this.fitHeight,
|
||||
}[settings.get().fitMode] || this.fitBoth;
|
||||
this._currentFitFunction();
|
||||
}
|
||||
|
||||
|
|
|
@ -131,17 +131,25 @@ class PostReadonlySidebarControl extends events.EventTarget {
|
|||
e.target.blur();
|
||||
func();
|
||||
this._syncFitButton();
|
||||
this.dispatchEvent(new CustomEvent('fitModeChange', {
|
||||
detail: {
|
||||
mode: this._getFitMode(),
|
||||
},
|
||||
}));
|
||||
};
|
||||
}
|
||||
|
||||
_getFitMode() {
|
||||
const funcToName = {};
|
||||
funcToName[this._postContentControl.fitBoth] = 'fit-both';
|
||||
funcToName[this._postContentControl.fitOriginal] = 'fit-original';
|
||||
funcToName[this._postContentControl.fitWidth] = 'fit-width';
|
||||
funcToName[this._postContentControl.fitHeight] = 'fit-height';
|
||||
return funcToName[this._postContentControl._currentFitFunction];
|
||||
}
|
||||
|
||||
_syncFitButton() {
|
||||
const funcToClassName = {};
|
||||
funcToClassName[this._postContentControl.fitBoth] = 'fit-both';
|
||||
funcToClassName[this._postContentControl.fitOriginal] = 'fit-original';
|
||||
funcToClassName[this._postContentControl.fitWidth] = 'fit-width';
|
||||
funcToClassName[this._postContentControl.fitHeight] = 'fit-height';
|
||||
const className = funcToClassName[
|
||||
this._postContentControl._currentFitFunction];
|
||||
const className = this._getFitMode();
|
||||
const oldNode = this._hostNode.querySelector('.zoom a.active');
|
||||
const newNode = this._hostNode.querySelector(`.zoom a.${className}`);
|
||||
if (oldNode) {
|
||||
|
|
|
@ -12,6 +12,7 @@ const defaultSettings = {
|
|||
endlessScroll: false,
|
||||
keyboardShortcuts: true,
|
||||
transparencyGrid: true,
|
||||
fitMode: 'fit-both',
|
||||
};
|
||||
|
||||
class Settings extends events.EventTarget {
|
||||
|
|
Loading…
Reference in a new issue