129 lines
3.2 KiB
JavaScript
Raw Normal View History

2021-05-28 23:19:11 +02:00
import NoteContextAwareWidget from "../note_context_aware_widget.js";
2021-09-22 22:25:39 +02:00
import NoteMapWidget from "../note_map.js";
2021-05-28 23:19:11 +02:00
const TPL = `
<div class="note-map-ribbon-widget">
2021-05-28 23:52:42 +02:00
<style>
.note-map-ribbon-widget {
2021-05-28 23:52:42 +02:00
position: relative;
}
.note-map-ribbon-widget .note-map-container {
2021-05-30 23:21:34 +02:00
height: 300px;
}
2021-05-28 23:52:42 +02:00
2021-05-31 21:20:30 +02:00
.open-full-button, .collapse-button {
2021-05-28 23:52:42 +02:00
position: absolute;
2021-05-31 21:20:30 +02:00
right: 5px;
bottom: 5px;
font-size: 180%;
2021-05-28 23:52:42 +02:00
z-index: 1000;
}
2021-06-02 21:23:40 +02:00
.style-resolver {
color: var(--muted-text-color);
display: none;
}
2021-05-28 23:52:42 +02:00
</style>
2021-05-31 21:20:30 +02:00
<button class="bx bx-arrow-to-bottom icon-action open-full-button" title="Open full"></button>
<button class="bx bx-arrow-to-top icon-action collapse-button" style="display: none;" title="Collapse to normal size"></button>
2021-05-28 23:52:42 +02:00
<div class="note-map-container"></div>
2021-05-28 23:19:11 +02:00
</div>`;
export default class NoteMapRibbonWidget extends NoteContextAwareWidget {
2021-09-22 22:25:39 +02:00
constructor() {
super();
this.noteMapWidget = new NoteMapWidget('ribbon');
this.child(this.noteMapWidget);
}
2021-06-27 12:53:05 +02:00
get name() {
return "noteMap";
2021-06-27 12:53:05 +02:00
}
get toggleCommand() {
return "toggleRibbonTabNoteMap";
}
2021-05-28 23:19:11 +02:00
isEnabled() {
return this.note;
}
getTitle() {
return {
show: this.isEnabled(),
title: 'Note Map',
icon: 'bx bx-map-alt'
2021-05-28 23:19:11 +02:00
};
}
doRender() {
this.$widget = $(TPL);
2021-06-13 22:55:31 +02:00
this.contentSized();
this.$container = this.$widget.find(".note-map-container");
2021-09-22 22:25:39 +02:00
this.$container.append(this.noteMapWidget.render());
2021-05-31 21:20:30 +02:00
2021-05-31 23:38:47 +02:00
this.openState = 'small';
2021-05-31 21:20:30 +02:00
this.$openFullButton = this.$widget.find('.open-full-button');
this.$openFullButton.on('click', () => {
2021-05-31 23:38:47 +02:00
this.setFullHeight();
2021-05-31 21:20:30 +02:00
this.$openFullButton.hide();
this.$collapseButton.show();
2021-05-31 23:38:47 +02:00
this.openState = 'full';
2021-09-22 22:25:39 +02:00
this.noteMapWidget.setHeight();
2021-05-31 21:20:30 +02:00
});
this.$collapseButton = this.$widget.find('.collapse-button');
this.$collapseButton.on('click', () => {
2021-05-31 23:38:47 +02:00
this.setSmallSize();
2021-05-31 21:20:30 +02:00
this.$openFullButton.show();
this.$collapseButton.hide();
2021-05-31 23:38:47 +02:00
this.openState = 'small';
2021-06-02 21:23:40 +02:00
2021-09-22 22:25:39 +02:00
this.noteMapWidget.setHeight();
});
2021-05-31 23:38:47 +02:00
window.addEventListener('resize', () => {
if (!this.graph) { // no graph has been even rendered
return;
}
if (this.openState === 'full') {
this.setFullHeight();
}
else if (this.openState === 'small') {
this.setSmallSize();
}
}, false);
}
setSmallSize() {
const SMALL_SIZE_HEIGHT = 300;
const width = this.$widget.width();
this.$widget.find('.note-map-container')
2021-05-31 23:38:47 +02:00
.height(SMALL_SIZE_HEIGHT)
.width(width);
}
setFullHeight() {
const {top} = this.$widget[0].getBoundingClientRect();
const height = $(window).height() - top;
const width = this.$widget.width();
this.$widget.find('.note-map-container')
2021-05-31 23:38:47 +02:00
.height(height)
.width(width);
2021-05-28 23:19:11 +02:00
}
}