Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
hover tooltip for internal links
azivnerc4ed01128b9e
diff --git a/src/templates/app.html b/src/templates/app.htmlindex ed3bdf2c2c..cfc3b29aff 100644--- a/src/templates/app.html+++ b/src/templates/app.html@@ -211,6 +211,8 @@<div id="recent-changes-dialog" title="Recent changes" style="display: none; padding: 20px;"></div>+ <div id="tooltip" style="display: none;"></div>+<script type="text/javascript">const baseApiUrl = 'api/';</script>diff --git a/static/js/add_link.js b/static/js/add_link.jsindex 0b92d4e755..479c4d15a4 100644--- a/static/js/add_link.js+++ b/static/js/add_link.js@@ -70,14 +70,23 @@ $(document).on('dblclick', '.note-editable a', e => {goToInternalNote(e);});+function getNoteIdFromLink(url) {+ const noteIdMatch = /app#([A-Za-z0-9]{22})/.exec(url);++ if (noteIdMatch === null) {+ return null;+ }+ else {+ return noteIdMatch[1];+ }+}+function goToInternalNote(e, callback) {const targetUrl = $(e.target).attr("href");- const noteIdMatch = /app#([A-Za-z0-9]{22})/.exec(targetUrl);-- if (noteIdMatch !== null) {- const noteId = noteIdMatch[1];+ const noteId = getNoteIdFromLink(targetUrl);+ if (noteId !== null) {getNodeByKey(noteId).setActive();e.preventDefault();diff --git a/static/js/encryption.js b/static/js/encryption.jsindex e8eefb4f7e..6ddbc22784 100644--- a/static/js/encryption.js+++ b/static/js/encryption.js@@ -106,7 +106,7 @@ function resetEncryptionSession() {globalDataKey = null;if (globalCurrentNote.detail.encryption > 0) {- loadNote(globalCurrentNote.detail.note_id);+ loadNoteToEditor(globalCurrentNote.detail.note_id);for (const noteId of globalAllNoteIds) {const note = getNodeByKey(noteId);@@ -280,7 +280,7 @@ function encryptSubTree(noteId) {},note => {if (note.detail.note_id === globalCurrentNote.detail.note_id) {- loadNote(note.detail.note_id);+ loadNoteToEditor(note.detail.note_id);}else {setTreeBasedOnEncryption(note);@@ -307,7 +307,7 @@ function decryptSubTree(noteId) {},note => {if (note.detail.note_id === globalCurrentNote.detail.note_id) {- loadNote(note.detail.note_id);+ loadNoteToEditor(note.detail.note_id);}else {setTreeBasedOnEncryption(note);diff --git a/static/js/init.js b/static/js/init.jsindex 2781f2f02d..03ff969768 100644--- a/static/js/init.js+++ b/static/js/init.js@@ -53,4 +53,31 @@ $.ui.autocomplete.filter = (array, terms) => {console.log("Search took " + (new Date().getTime() - startDate.getTime()) + "ms");return results;-};\ No newline at end of file+};++$(document).tooltip({+ items: ".note-editable a",+ content: function(callback) {+ const noteId = getNoteIdFromLink($(this).attr("href"));++ if (noteId !== null) {+ loadNote(noteId, note => {+ callback(note.detail.note_text);+ });+ }+ },+ close: function(event, ui)+ {+ ui.tooltip.hover(function()+ {+ $(this).stop(true).fadeTo(400, 1);+ },+ function()+ {+ $(this).fadeOut('400', function()+ {+ $(this).remove();+ });+ });+ }+});\ No newline at end of filediff --git a/static/js/note.js b/static/js/note.jsindex 30acf7e2f9..bb75994a7e 100644--- a/static/js/note.js+++ b/static/js/note.js@@ -191,7 +191,7 @@ function setNoteBackgroundIfEncrypted(note) {setTreeBasedOnEncryption(note);}-function loadNote(noteId) {+function loadNoteToEditor(noteId) {$.get(baseApiUrl + 'notes/' + noteId).then(note => {globalCurrentNote = note;@@ -225,8 +225,6 @@ function loadNote(noteId) {document.location.hash = noteId;- $(window).resize(); // to trigger resizing of editor-addRecentNote(noteId, note.detail.note_id);noteChangeDisabled = false;@@ -234,4 +232,16 @@ function loadNote(noteId) {setNoteBackgroundIfEncrypted(note);});});+}++function loadNote(noteId, callback) {+ $.get(baseApiUrl + 'notes/' + noteId).then(note => {+ if (note.detail.encryption > 0 && !isEncryptionAvailable()) {+ return;+ }++ decryptNoteIfNecessary(note);++ callback(note);+ });}\ No newline at end of filediff --git a/static/js/tree.js b/static/js/tree.jsindex 4e50b8d7c8..8fcee19df1 100644--- a/static/js/tree.js+++ b/static/js/tree.js@@ -135,7 +135,7 @@ $(() => {activate: (event, data) => {const node = data.node.data;- saveNoteIfChanged(() => loadNote(node.note_id));+ saveNoteIfChanged(() => loadNoteToEditor(node.note_id));},expand: (event, data) => {setExpandedToServer(data.node.key, true);diff --git a/static/style.css b/static/style.cssindex d310848ef6..a744bfceb0 100644--- a/static/style.css+++ b/static/style.css@@ -102,4 +102,10 @@ span.fancytree-node.encrypted.fancytree-folder > span.fancytree-icon {#header .btn-xs {margin-bottom: 2px;margin-right: 8px;+}++div.ui-tooltip {+ max-width: 600px;+ max-height: 600px;+ overflow: auto;}\ No newline at end of file