This repository has been archived by the owner on Sep 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrilium-remember-right-pane.js
166 lines (146 loc) · 6.82 KB
/
trilium-remember-right-pane.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
trilium-remember-right-pane.js version:0.1 for trilium:>0.58.4
https://github.com/SiriusXT/trilium-remember-right-pane
*/
var currentNoteThis;
var isBound = false;
function setTocLabel(value) {
api.runOnBackend((currentNoteID, value) => {
api.getNote(currentNoteID).setLabel("toc", value);
}, [currentNoteThis.noteId, value]);
}
function delTocLabel() {
api.runOnBackend((currentNoteID, value) => {
api.getNote(currentNoteID).removeLabel("toc");
}, [currentNoteThis.noteId, 1]);
}
function setHllLabel(value = false) {
api.runOnBackend((currentNoteID, value) => {
api.getNote(currentNoteID).setLabel("hideHighlightWidget", value);
}, [currentNoteThis.noteId, value]);
}
function delHllLabel(noteId) {
api.runOnBackend((currentNoteID) => {
api.getNote(currentNoteID).removeLabel("hideHighlightWidget");
}, [currentNoteThis.noteId]);
}
class RememberRightPane extends api.NoteContextAwareWidget {
get position() {
return 100;
}
get parentWidget() {
return 'center-pane';
}
isEnabled() {
return super.isEnabled();
}
doRender() {
this.$widget = $(`<style type="text/css">{
.unfold-toc{
display:none;
}
.unfold-hll{
display:none;
}
}</style>`);//
return this.$widget;
}
async toogleTocLabel() {
var note = currentNoteThis.note
if (currentNoteThis.noteContext.viewScope.tocTemporarilyHidden == true || (note.hasLabel("toc") && note.getLabel("toc").value == "hide")) {//when already hidden
currentNoteThis.noteContext.viewScope.tocTemporarilyHidden = false
setTocLabel("hide");
delTocLabel();
}
else {
setTocLabel("hide");
}
}
async toogleHllLabel() {
var note = currentNoteThis.note
if (currentNoteThis.noteContext.viewScope.highlightsListTemporarilyHidden == true || (note.hasLabel("hideHighlightWidget") && (note.getLabel("hideHighlightWidget").value == "" || note.getLabel("hideHighlightWidget").value != false))) {//when already hidden
currentNoteThis.noteContext.viewScope.highlightsListTemporarilyHidden = false
setHllLabel(false);
delHllLabel();
}
else {
setHllLabel(true);
}
}
async refreshWithNote(note) {
//console.log("trilium-remember-right-pane");
if (this.note.type == 'text') {
if (this.noteContext.viewScope.tocPreviousVisible == true || this.noteContext.viewScope.tocPreviousVisible == undefined) {
if (this.noteContext.viewScope.tocTemporarilyHidden == true || (note.hasLabel("toc") && note.getLabel("toc").value == "hide")) {//when already hidden
$(".note-split.type-text:not(.hidden-ext) .ribbon-button-container .unfold-toc").css("display", "block");
} else {
$(".note-split.type-text:not(.hidden-ext) .ribbon-button-container .unfold-toc").css("display", "none");
}
}
else {
$(".ribbon-button-container .unfold-toc").css("display", "none");
}
if (this.noteContext.viewScope.highlightsListPreviousVisible == true || this.noteContext.viewScope.highlightsListPreviousVisible == undefined) {
if (this.noteContext.viewScope.highlightsListTemporarilyHidden == true || (note.hasLabel("hideHighlightWidget") && (note.getLabel("hideHighlightWidget").value == "" || note.getLabel("hideHighlightWidget").value != false))) {//when already hidden
$(".note-split.type-text:not(.hidden-ext) .ribbon-button-container .unfold-hll").css("display", "block");
} else {
$(".note-split.type-text:not(.hidden-ext) .ribbon-button-container .unfold-hll").css("display", "none");
}
} else {
$(".note-split.type-text:not(.hidden-ext) .ribbon-button-container .unfold-hll").css("display", "none");
}
} else {
$(".note-split.type-text:not(.hidden-ext) .ribbon-button-container .unfold-toc").css("display", "none");
$(".note-split.type-text:not(.hidden-ext) .ribbon-button-container .unfold-hll").css("display", "none");
return;
}
currentNoteThis = this;
var toogleTocLabel = this.toogleTocLabel;
var toogleHllLabel = this.toogleHllLabel;
if ($('.note-split.type-text:not(.hidden-ext) .ribbon-button-container .unfold-toc').length == 0) {
var tocB = $('<button class="button-widget bx component icon-action bx-objects-horizontal-left unfold-toc" data-toggle="tooltip" title="Unfold Toc" data-placement="bottom"></button>').on('click', function (event) {
toogleTocLabel();
});
$('.note-split.type-text:not(.hidden-ext) .ribbon-button-container').append(tocB);
// currentNoteThis.refresh(); //I can't remember why this line is there.
}
if ($('.note-split.type-text:not(.hidden-ext) .ribbon-button-container .unfold-hll').length == 0) {
var hllB = $('<button class="button-widget bx component icon-action bx-highlight unfold-hll" data-toggle="tooltip" title="Unfold Highlightslist" data-placement="bottom"></button>').on('click', function (event) {
toogleHllLabel();
});
$('.note-split.type-text:not(.hidden-ext) .ribbon-button-container').append(hllB);
// currentNoteThis.refresh(); //I can't remember why this line is there.
}
// Listen for close button
$(document).ready(function () {
var maxRetries = 5;
var retryInterval = 500;
function tryToGetElement(retries) {
var targetElements = $('#right-pane .button-widget.bx.component.icon-action.bx-x');
if (targetElements.length > 0) {
if (!isBound) {
// currentNoteThis.refresh(); //I can't remember why this line is there.
$(targetElements[0]).on('click', function () {
setTocLabel("hide");
});
$(targetElements[1]).on('click', function () {
setHllLabel(true);
});
isBound = true;
}
} else {
if (retries > 0) {
setTimeout(function () {
tryToGetElement(retries - 1);
}, retryInterval);
}
}
}
tryToGetElement(maxRetries);
});
}
async entitiesReloadedEvent({ loadResults }) {
this.refresh();
}
}
module.exports = new RememberRightPane();