2019-12-24 03:34:29 +08:00
|
|
|
import server from "./server.js";
|
|
|
|
import optionService from "./options.js";
|
|
|
|
|
2019-12-23 23:48:34 +08:00
|
|
|
let instance;
|
|
|
|
|
2019-12-24 03:34:29 +08:00
|
|
|
async function getPaneWidths() {
|
|
|
|
const options = await optionService.waitForOptions();
|
|
|
|
|
|
|
|
return {
|
|
|
|
leftPaneWidth: options.getInt('leftPaneWidth'),
|
|
|
|
rightPaneWidth: options.getInt('rightPaneWidth')
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-02-05 03:42:40 +08:00
|
|
|
async function setupSplit(left, right) {
|
2019-12-23 23:48:34 +08:00
|
|
|
if (instance) {
|
|
|
|
instance.destroy();
|
2020-02-05 03:42:40 +08:00
|
|
|
instance = null;
|
2019-12-23 23:48:34 +08:00
|
|
|
}
|
|
|
|
|
2020-02-05 03:42:40 +08:00
|
|
|
if (!left && !right) {
|
|
|
|
$("#center-pane").css('width', '100%');
|
2019-12-23 23:48:34 +08:00
|
|
|
|
2020-02-05 03:42:40 +08:00
|
|
|
return;
|
2019-12-23 23:48:34 +08:00
|
|
|
}
|
|
|
|
|
2020-02-05 03:42:40 +08:00
|
|
|
const {leftPaneWidth, rightPaneWidth} = await getPaneWidths();
|
2019-12-24 03:34:29 +08:00
|
|
|
|
2020-02-05 03:42:40 +08:00
|
|
|
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 {
|
2020-02-05 03:42:40 +08:00
|
|
|
setupSplit
|
2019-12-23 23:48:34 +08:00
|
|
|
};
|