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

61 lines
1.7 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 setupSplit(left, right) {
2019-12-23 23:48:34 +08:00
if (instance) {
instance.destroy();
instance = null;
2019-12-23 23:48:34 +08:00
}
if (!left && !right) {
$("#center-pane").css('width', '100%');
2019-12-23 23:48:34 +08:00
return;
2019-12-23 23:48:34 +08:00
}
const {leftPaneWidth, rightPaneWidth} = await getPaneWidths();
if (left && right) {
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]));
}
});
}
else if (left) {
instance = Split(['#left-pane', '#center-pane'], {
sizes: [leftPaneWidth, 100 - leftPaneWidth],
gutterSize: 5,
onDragEnd: sizes => {
server.put('options/leftPaneWidth/' + Math.round(sizes[0]));
}
});
}
else if (right) {
instance = Split(['#center-pane', '#right-pane'], {
sizes: [100 - rightPaneWidth, rightPaneWidth],
gutterSize: 5,
onDragEnd: sizes => {
server.put('options/rightPaneWidth/' + Math.round(sizes[1]));
}
});
}
2019-12-23 23:48:34 +08:00
}
export default {
setupSplit
2019-12-23 23:48:34 +08:00
};