From 14acacf2e9e8c2754b5c4d4dced611afbefa4d19 Mon Sep 17 00:00:00 2001 From: azivner Date: Wed, 11 Oct 2017 21:20:05 -0400 Subject: [PATCH] clicking on links inside tooltip now works too --- static/js/add_link.js | 47 +++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/static/js/add_link.js b/static/js/add_link.js index 479c4d15a..9cb50a171 100644 --- a/static/js/add_link.js +++ b/static/js/add_link.js @@ -10,7 +10,7 @@ $(document).bind('keydown', 'alt+l', () => { width: 500 }); - function setDefaultlinkTitle(noteId) { + function setDefaultLinkTitle(noteId) { const noteTitle = getNoteTitle(noteId); $("#link-title").val(noteTitle); @@ -24,7 +24,7 @@ $(document).bind('keydown', 'alt+l', () => { const noteId = getNodeIdFromLabel(val); if (noteId) { - setDefaultlinkTitle(noteId); + setDefaultLinkTitle(noteId); } }, // this is called when user goes through autocomplete list with keyboard @@ -37,7 +37,7 @@ $(document).bind('keydown', 'alt+l', () => { }); }); -$("#insertLinkForm").submit(() => { +$("#insert-link-form").submit(() => { let val = $("#note-autocomplete").val(); const noteId = getNodeIdFromLabel(val); @@ -51,7 +51,7 @@ $("#insertLinkForm").submit(() => { noteDetail.summernote('editor.restoreRange'); noteDetail.summernote('createLink', { - text: link-title, + text: linkTitle, url: 'app#' + noteId, isNewWindow: true }); @@ -62,14 +62,33 @@ $("#insertLinkForm").submit(() => { // when click on link popup, in case of internal link, just go the the referenced note instead of default behavior // of opening the link in new window/tab -$(document).on('click', 'div.popover-content a', e => { +$(document).on('click', 'div.popover-content a, div.ui-tooltip-content', e => { goToInternalNote(e); }); -$(document).on('dblclick', '.note-editable a', e => { +$(document).on('dblclick', '.note-editable a, div.ui-tooltip-content', e => { goToInternalNote(e); }); +function goToInternalNote(e, callback) { + const targetUrl = $(e.target).attr("href"); + + const noteId = getNoteIdFromLink(targetUrl); + + if (noteId !== null) { + getNodeByKey(noteId).setActive(); + + // this is quite ugly hack, but it seems like we can't close the tooltip otherwise + $("[role='tooltip']").remove(); + + e.preventDefault(); + + if (callback) { + callback(); + } + } +} + function getNoteIdFromLink(url) { const noteIdMatch = /app#([A-Za-z0-9]{22})/.exec(url); @@ -81,22 +100,6 @@ function getNoteIdFromLink(url) { } } -function goToInternalNote(e, callback) { - const targetUrl = $(e.target).attr("href"); - - const noteId = getNoteIdFromLink(targetUrl); - - if (noteId !== null) { - getNodeByKey(noteId).setActive(); - - e.preventDefault(); - - if (callback) { - callback(); - } - } -} - function getNodeIdFromLabel(label) { const noteIdMatch = / \(([A-Za-z0-9]{22})\)/.exec(label);