2020-02-06 05:08:45 +08:00
|
|
|
import options from "../services/options.js";
|
|
|
|
import splitService from "../services/split.js";
|
|
|
|
import BasicWidget from "./basic_widget.js";
|
|
|
|
|
|
|
|
const TPL = `
|
2020-02-06 05:46:20 +08:00
|
|
|
<div class="hide-in-zen-mode">
|
2020-02-06 05:08:45 +08:00
|
|
|
<style>
|
2020-02-06 05:46:20 +08:00
|
|
|
.hide-right-pane-button, .show-right-pane-button {
|
2020-02-06 05:08:45 +08:00
|
|
|
position: fixed;
|
|
|
|
bottom: 10px;
|
|
|
|
right: 10px;
|
|
|
|
z-index: 1000;
|
|
|
|
}
|
|
|
|
|
2020-02-06 05:46:20 +08:00
|
|
|
.hide-left-pane-button, .show-left-pane-button {
|
2020-02-06 05:08:45 +08:00
|
|
|
position: fixed;
|
|
|
|
bottom: 10px;
|
|
|
|
left: 10px;
|
|
|
|
z-index: 1000;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|
2020-02-06 05:46:20 +08:00
|
|
|
<button class="hide-left-pane-button btn btn-sm icon-button bx bx-chevrons-left" title="Show sidebar"></button>
|
|
|
|
<button class="show-left-pane-button btn btn-sm icon-button bx bx-chevrons-right" title="Hide sidebar"></button>
|
2020-02-06 05:08:45 +08:00
|
|
|
|
2020-02-06 05:46:20 +08:00
|
|
|
<button class="hide-right-pane-button btn btn-sm icon-button bx bx-chevrons-right" title="Hide sidebar"></button>
|
|
|
|
<button class="show-right-pane-button btn btn-sm icon-button bx bx-chevrons-left" title="Show sidebar"></button>
|
2020-02-06 05:08:45 +08:00
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
|
2020-02-07 03:04:43 +08:00
|
|
|
export default class SidePaneToggles extends BasicWidget {
|
2020-02-06 05:08:45 +08:00
|
|
|
constructor(appContext) {
|
|
|
|
super(appContext);
|
|
|
|
|
|
|
|
this.paneVisible = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
doRender() {
|
|
|
|
this.$widget = $(TPL);
|
|
|
|
|
|
|
|
this.toggleSidebar('left', options.is('leftPaneVisible'));
|
|
|
|
this.toggleSidebar('right', options.is('rightPaneVisible'));
|
|
|
|
|
2020-02-06 05:46:20 +08:00
|
|
|
this.$widget.find(".show-right-pane-button").on('click', () => this.toggleAndSave('right', true));
|
|
|
|
this.$widget.find(".hide-right-pane-button").on('click', () => this.toggleAndSave('right', false));
|
2020-02-06 05:08:45 +08:00
|
|
|
|
2020-02-06 05:46:20 +08:00
|
|
|
this.$widget.find(".show-left-pane-button").on('click', () => this.toggleAndSave('left', true));
|
|
|
|
this.$widget.find(".hide-left-pane-button").on('click', () => this.toggleAndSave('left', false));
|
2020-02-06 05:08:45 +08:00
|
|
|
|
|
|
|
return this.$widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleSidebar(side, show) {
|
|
|
|
$(`#${side}-pane`).toggle(show);
|
2020-02-06 05:46:20 +08:00
|
|
|
this.$widget.find(`.show-${side}-pane-button`).toggle(!show);
|
|
|
|
this.$widget.find(`.hide-${side}-pane-button`).toggle(show);
|
2020-02-06 05:08:45 +08:00
|
|
|
|
|
|
|
this.paneVisible[side] = show;
|
|
|
|
}
|
|
|
|
|
|
|
|
async toggleAndSave(side, show) {
|
|
|
|
this.toggleSidebar(side, show);
|
|
|
|
|
|
|
|
await options.save(`${side}PaneVisible`, show.toString());
|
|
|
|
|
|
|
|
splitService.setupSplit(this.paneVisible.left, this.paneVisible.right);
|
|
|
|
|
|
|
|
this.trigger('sidebarVisibilityChanged', {side, show});
|
|
|
|
}
|
2020-02-07 04:16:02 +08:00
|
|
|
|
|
|
|
initialRenderCompleteListener() {
|
|
|
|
splitService.setupSplit(this.paneVisible.left, this.paneVisible.right);
|
|
|
|
}
|
2020-02-06 05:08:45 +08:00
|
|
|
}
|