trilium/src/public/javascripts/services/split.js

51 lines
1.3 KiB
JavaScript
Raw Normal View History

import server from "./server.js";
import optionService from "./options.js";
2019-12-23 23:48:34 +08:00
let instance;
async function getPaneWidths() {
const options = await optionService.waitForOptions();
return {
leftPaneWidth: options.getInt('leftPaneWidth'),
rightPaneWidth: options.getInt('rightPaneWidth')
};
}
async function setupSplitWithSidebar() {
2019-12-23 23:48:34 +08:00
if (instance) {
instance.destroy();
}
const {leftPaneWidth, rightPaneWidth} = await getPaneWidths();
2019-12-23 23:48:34 +08:00
instance = Split(['#left-pane', '#center-pane', '#right-pane'], {
sizes: [leftPaneWidth, 100 - leftPaneWidth - rightPaneWidth, rightPaneWidth],
gutterSize: 5,
onDragEnd: sizes => {
server.put('options/leftPaneWidth/' + Math.round(sizes[0]));
server.put('options/rightPaneWidth/' + Math.round(sizes[2]));
}
2019-12-23 23:48:34 +08:00
});
}
async function setupSplitWithoutSidebar() {
2019-12-23 23:48:34 +08:00
if (instance) {
instance.destroy();
}
const {leftPaneWidth} = await getPaneWidths();
2019-12-23 23:48:34 +08:00
instance = Split(['#left-pane', '#center-pane'], {
sizes: [leftPaneWidth, 100 - leftPaneWidth],
gutterSize: 5,
onDragEnd: sizes => {
server.put('options/leftPaneWidth/' + Math.round(sizes[0]));
}
2019-12-23 23:48:34 +08:00
});
}
export default {
setupSplitWithSidebar,
setupSplitWithoutSidebar
};