mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
more generic handling of links to note
This commit is contained in:
parent
c723bfc3ac
commit
819ae7c4c0
@ -6,6 +6,8 @@ const addLink = (function() {
|
|||||||
const linkTitleEl = $("#link-title");
|
const linkTitleEl = $("#link-title");
|
||||||
|
|
||||||
function showDialog() {
|
function showDialog() {
|
||||||
|
glob.activeDialog = dialogEl;
|
||||||
|
|
||||||
noteDetailEl.summernote('editor.saveRange');
|
noteDetailEl.summernote('editor.saveRange');
|
||||||
|
|
||||||
dialogEl.dialog({
|
dialogEl.dialog({
|
||||||
@ -65,51 +67,6 @@ const addLink = (function() {
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
// 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, div.ui-tooltip-content', goToInternalNote);
|
|
||||||
$(document).on('dblclick', '.note-editable a, div.ui-tooltip-content', goToInternalNote);
|
|
||||||
|
|
||||||
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]{12})/.exec(url);
|
|
||||||
|
|
||||||
if (noteIdMatch === null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return noteIdMatch[1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getNodeIdFromLabel(label) {
|
|
||||||
const noteIdMatch = / \(([A-Za-z0-9]{12})\)/.exec(label);
|
|
||||||
|
|
||||||
if (noteIdMatch !== null) {
|
|
||||||
return noteIdMatch[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$(document).bind('keydown', 'alt+l', showDialog);
|
$(document).bind('keydown', 'alt+l', showDialog);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -3,6 +3,8 @@ const eventLog = (function() {
|
|||||||
const listEl = $("#event-log-list");
|
const listEl = $("#event-log-list");
|
||||||
|
|
||||||
async function showDialog() {
|
async function showDialog() {
|
||||||
|
glob.activeDialog = dialogEl;
|
||||||
|
|
||||||
dialogEl.dialog({
|
dialogEl.dialog({
|
||||||
modal: true,
|
modal: true,
|
||||||
width: 800,
|
width: 800,
|
||||||
@ -21,10 +23,7 @@ const eventLog = (function() {
|
|||||||
const dateTime = formatDateTime(getDateFromTS(event.date_added));
|
const dateTime = formatDateTime(getDateFromTS(event.date_added));
|
||||||
|
|
||||||
if (event.note_id) {
|
if (event.note_id) {
|
||||||
const noteLink = $("<a>", {
|
const noteLink = createNoteLink(event.note_id).prop('outerHTML');
|
||||||
href: 'app#' + event.note_id,
|
|
||||||
text: getFullName(event.note_id)
|
|
||||||
}).prop('outerHTML');
|
|
||||||
|
|
||||||
event.comment = event.comment.replace('<note>', noteLink);
|
event.comment = event.comment.replace('<note>', noteLink);
|
||||||
}
|
}
|
||||||
@ -35,12 +34,6 @@ const eventLog = (function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$(document).on('click', '#event-log-dialog a', e => {
|
|
||||||
goToInternalNote(e, () => {
|
|
||||||
dialogEl.dialog('close');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
showDialog
|
showDialog
|
||||||
};
|
};
|
||||||
|
@ -4,6 +4,8 @@ const jumpToNote = (function() {
|
|||||||
const formEl = $("#jump-to-note-form");
|
const formEl = $("#jump-to-note-form");
|
||||||
|
|
||||||
function showDialog() {
|
function showDialog() {
|
||||||
|
glob.activeDialog = dialogEl;
|
||||||
|
|
||||||
autoCompleteEl.val('');
|
autoCompleteEl.val('');
|
||||||
|
|
||||||
dialogEl.dialog({
|
dialogEl.dialog({
|
||||||
|
@ -10,12 +10,9 @@ const noteHistory = (function() {
|
|||||||
await showNoteHistoryDialog(glob.currentNote.detail.note_id);
|
await showNoteHistoryDialog(glob.currentNote.detail.note_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// weird hack because browser doesn't like we're returning promise and displays promise page
|
|
||||||
function showNoteHistoryDialogNotAsync(noteId, noteHistoryId) {
|
|
||||||
showNoteHistoryDialog(noteId, noteHistoryId);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function showNoteHistoryDialog(noteId, noteHistoryId) {
|
async function showNoteHistoryDialog(noteId, noteHistoryId) {
|
||||||
|
glob.activeDialog = dialogEl;
|
||||||
|
|
||||||
dialogEl.dialog({
|
dialogEl.dialog({
|
||||||
modal: true,
|
modal: true,
|
||||||
width: 800,
|
width: 800,
|
||||||
@ -68,9 +65,17 @@ const noteHistory = (function() {
|
|||||||
contentEl.html(noteText);
|
contentEl.html(noteText);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$(document).on('click', "a[action='note-history']", event => {
|
||||||
|
const linkEl = $(event.target);
|
||||||
|
const noteId = linkEl.attr('note-id');
|
||||||
|
const noteHistoryId = linkEl.attr('note-history-id');
|
||||||
|
|
||||||
|
showNoteHistoryDialog(noteId, noteHistoryId);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
showCurrentNoteHistory,
|
showCurrentNoteHistory
|
||||||
showNoteHistoryDialog,
|
|
||||||
showNoteHistoryDialogNotAsync
|
|
||||||
};
|
};
|
||||||
})();
|
})();
|
@ -1,8 +1,10 @@
|
|||||||
const recentChanges = (function() {
|
const recentChanges = (function() {
|
||||||
const dialog = $("#recent-changes-dialog");
|
const dialogEl = $("#recent-changes-dialog");
|
||||||
|
|
||||||
async function showDialog() {
|
async function showDialog() {
|
||||||
dialog.dialog({
|
glob.activeDialog = dialogEl;
|
||||||
|
|
||||||
|
dialogEl.dialog({
|
||||||
modal: true,
|
modal: true,
|
||||||
width: 800,
|
width: 800,
|
||||||
height: 700
|
height: 700
|
||||||
@ -14,7 +16,7 @@ const recentChanges = (function() {
|
|||||||
error: () => error("Error getting recent changes.")
|
error: () => error("Error getting recent changes.")
|
||||||
});
|
});
|
||||||
|
|
||||||
dialog.html('');
|
dialogEl.html('');
|
||||||
|
|
||||||
const groupedByDate = groupByDate(result);
|
const groupedByDate = groupByDate(result);
|
||||||
|
|
||||||
@ -26,23 +28,20 @@ const recentChanges = (function() {
|
|||||||
for (const change of dayChanges) {
|
for (const change of dayChanges) {
|
||||||
const formattedTime = formatTime(getDateFromTS(change.date_modified_to));
|
const formattedTime = formatTime(getDateFromTS(change.date_modified_to));
|
||||||
|
|
||||||
const noteLink = $("<a>", {
|
|
||||||
href: 'app#' + change.note_id,
|
|
||||||
text: change.note_title
|
|
||||||
});
|
|
||||||
|
|
||||||
const revLink = $("<a>", {
|
const revLink = $("<a>", {
|
||||||
href: "javascript: noteHistory.showNoteHistoryDialogNotAsync('" + change.note_id + "', '" + change.note_history_id + "');",
|
href: 'javascript:',
|
||||||
text: 'rev'
|
text: 'rev'
|
||||||
});
|
}).attr('action', 'note-history')
|
||||||
|
.attr('note-id', change.note_id)
|
||||||
|
.attr('note-history-id', change.note_history_id);
|
||||||
|
|
||||||
changesListEl.append($('<li>')
|
changesListEl.append($('<li>')
|
||||||
.append(formattedTime + ' - ')
|
.append(formattedTime + ' - ')
|
||||||
.append(noteLink)
|
.append(createNoteLink(change.note_id))
|
||||||
.append(' (').append(revLink).append(')'));
|
.append(' (').append(revLink).append(')'));
|
||||||
}
|
}
|
||||||
|
|
||||||
dialog.append(dayEl);
|
dialogEl.append(dayEl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,8 +50,6 @@ const recentChanges = (function() {
|
|||||||
const dayCache = {};
|
const dayCache = {};
|
||||||
|
|
||||||
for (const row of result) {
|
for (const row of result) {
|
||||||
row.note_title = getFullName(row.note_id);
|
|
||||||
|
|
||||||
let dateDay = getDateFromTS(row.date_modified_to);
|
let dateDay = getDateFromTS(row.date_modified_to);
|
||||||
dateDay.setHours(0);
|
dateDay.setHours(0);
|
||||||
dateDay.setMinutes(0);
|
dateDay.setMinutes(0);
|
||||||
@ -77,15 +74,8 @@ const recentChanges = (function() {
|
|||||||
return groupedByDate;
|
return groupedByDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$(document).bind('keydown', 'alt+r', showDialog);
|
$(document).bind('keydown', 'alt+r', showDialog);
|
||||||
|
|
||||||
$(document).on('click', '#recent-changes-dialog a', e => {
|
|
||||||
goToInternalNote(e, () => {
|
|
||||||
dialog.dialog('close');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
showDialog
|
showDialog
|
||||||
};
|
};
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
const recentNotes = (function() {
|
const recentNotes = (function() {
|
||||||
const dialog = $("#recent-notes-dialog");
|
const dialogEl = $("#recent-notes-dialog");
|
||||||
const selectBox = $('#recent-notes-select-box');
|
const selectBoxEl = $('#recent-notes-select-box');
|
||||||
const jumpToButton = $('#recentNotesJumpTo');
|
const jumpToButtonEl = $('#recentNotesJumpTo');
|
||||||
const addLinkButton = $('#recentNotesAddLink');
|
const addLinkButtonEl = $('#recentNotesAddLink');
|
||||||
const noteDetail = $('#note-detail');
|
const noteDetailEl = $('#note-detail');
|
||||||
let list = [];
|
let list = [];
|
||||||
|
|
||||||
function addRecentNote(noteTreeId, noteContentId) {
|
function addRecentNote(noteTreeId, noteContentId) {
|
||||||
@ -23,14 +23,16 @@ const recentNotes = (function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function showDialog() {
|
function showDialog() {
|
||||||
noteDetail.summernote('editor.saveRange');
|
glob.activeDialog = dialogEl;
|
||||||
|
|
||||||
dialog.dialog({
|
noteDetailEl.summernote('editor.saveRange');
|
||||||
|
|
||||||
|
dialogEl.dialog({
|
||||||
modal: true,
|
modal: true,
|
||||||
width: 800
|
width: 800
|
||||||
});
|
});
|
||||||
|
|
||||||
selectBox.find('option').remove();
|
selectBoxEl.find('option').remove();
|
||||||
|
|
||||||
// remove the current note
|
// remove the current note
|
||||||
const recNotes = list.filter(note => note !== glob.currentNote.detail.note_id);
|
const recNotes = list.filter(note => note !== glob.currentNote.detail.note_id);
|
||||||
@ -51,12 +53,12 @@ const recentNotes = (function() {
|
|||||||
option.attr("selected", "selected");
|
option.attr("selected", "selected");
|
||||||
}
|
}
|
||||||
|
|
||||||
selectBox.append(option);
|
selectBoxEl.append(option);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSelectedNoteIdFromRecentNotes() {
|
function getSelectedNoteIdFromRecentNotes() {
|
||||||
return selectBox.find("option:selected").val();
|
return selectBoxEl.find("option:selected").val();
|
||||||
}
|
}
|
||||||
|
|
||||||
function setActiveNoteBasedOnRecentNotes() {
|
function setActiveNoteBasedOnRecentNotes() {
|
||||||
@ -64,7 +66,7 @@ const recentNotes = (function() {
|
|||||||
|
|
||||||
getNodeByKey(noteId).setActive();
|
getNodeByKey(noteId).setActive();
|
||||||
|
|
||||||
dialog.dialog('close');
|
dialogEl.dialog('close');
|
||||||
}
|
}
|
||||||
|
|
||||||
function addLinkBasedOnRecentNotes() {
|
function addLinkBasedOnRecentNotes() {
|
||||||
@ -72,18 +74,18 @@ const recentNotes = (function() {
|
|||||||
|
|
||||||
const linkTitle = getNoteTitle(noteId);
|
const linkTitle = getNoteTitle(noteId);
|
||||||
|
|
||||||
dialog.dialog("close");
|
dialogEl.dialog("close");
|
||||||
|
|
||||||
noteDetail.summernote('editor.restoreRange');
|
noteDetailEl.summernote('editor.restoreRange');
|
||||||
|
|
||||||
noteDetail.summernote('createLink', {
|
noteDetailEl.summernote('createLink', {
|
||||||
text: linkTitle,
|
text: linkTitle,
|
||||||
url: 'app#' + noteId,
|
url: 'app#' + noteId,
|
||||||
isNewWindow: true
|
isNewWindow: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
selectBox.keydown(e => {
|
selectBoxEl.keydown(e => {
|
||||||
const key = e.which;
|
const key = e.which;
|
||||||
|
|
||||||
if (key === 13)// the enter key code
|
if (key === 13)// the enter key code
|
||||||
@ -102,12 +104,12 @@ const recentNotes = (function() {
|
|||||||
|
|
||||||
$(document).bind('keydown', 'alt+q', showDialog);
|
$(document).bind('keydown', 'alt+q', showDialog);
|
||||||
|
|
||||||
selectBox.dblclick(e => {
|
selectBoxEl.dblclick(e => {
|
||||||
setActiveNoteBasedOnRecentNotes();
|
setActiveNoteBasedOnRecentNotes();
|
||||||
});
|
});
|
||||||
|
|
||||||
jumpToButton.click(setActiveNoteBasedOnRecentNotes);
|
jumpToButtonEl.click(setActiveNoteBasedOnRecentNotes);
|
||||||
addLinkButton.click(addLinkBasedOnRecentNotes);
|
addLinkButtonEl.click(addLinkBasedOnRecentNotes);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
showDialog,
|
showDialog,
|
||||||
|
@ -9,6 +9,8 @@ const settings = (function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function showDialog() {
|
async function showDialog() {
|
||||||
|
glob.activeDialog = dialogEl;
|
||||||
|
|
||||||
const settings = await $.ajax({
|
const settings = await $.ajax({
|
||||||
url: baseApiUrl + 'settings',
|
url: baseApiUrl + 'settings',
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
glob = {};
|
glob = {
|
||||||
|
activeDialog: null
|
||||||
|
};
|
||||||
|
|
||||||
// hot keys are active also inside inputs and content editables
|
// hot keys are active also inside inputs and content editables
|
||||||
jQuery.hotkeys.options.filterInputAcceptingElements = true;
|
jQuery.hotkeys.options.filterInputAcceptingElements = true;
|
||||||
@ -85,3 +87,65 @@ $(document).tooltip({
|
|||||||
function isElectron() {
|
function isElectron() {
|
||||||
return window && window.process && window.process.type;
|
return window && window.process && window.process.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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', "a[action='note']", goToInternalNote);
|
||||||
|
$(document).on('click', 'div.popover-content a, div.ui-tooltip-content', goToInternalNote);
|
||||||
|
$(document).on('dblclick', '.note-editable a, div.ui-tooltip-content', goToInternalNote);
|
||||||
|
|
||||||
|
function goToInternalNote(e) {
|
||||||
|
const linkEl = $(e.target);
|
||||||
|
let noteId = linkEl.attr("note-id");
|
||||||
|
|
||||||
|
if (!noteId) {
|
||||||
|
noteId = getNoteIdFromLink(linkEl.attr('href'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (noteId) {
|
||||||
|
getNodeByKey(noteId).setActive();
|
||||||
|
|
||||||
|
// this is quite ugly hack, but it seems like we can't close the tooltip otherwise
|
||||||
|
$("[role='tooltip']").remove();
|
||||||
|
|
||||||
|
if (glob.activeDialog) {
|
||||||
|
try {
|
||||||
|
glob.activeDialog.dialog('close');
|
||||||
|
}
|
||||||
|
catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getNoteIdFromLink(url) {
|
||||||
|
const noteIdMatch = /app#([A-Za-z0-9]{12})/.exec(url);
|
||||||
|
|
||||||
|
if (noteIdMatch === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return noteIdMatch[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getNodeIdFromLabel(label) {
|
||||||
|
const noteIdMatch = / \(([A-Za-z0-9]{12})\)/.exec(label);
|
||||||
|
|
||||||
|
if (noteIdMatch !== null) {
|
||||||
|
return noteIdMatch[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createNoteLink(noteId) {
|
||||||
|
const noteLink = $("<a>", {
|
||||||
|
href: 'javascript:',
|
||||||
|
text: getFullName(noteId)
|
||||||
|
}).attr('action', 'note')
|
||||||
|
.attr('note-id', noteId);
|
||||||
|
|
||||||
|
return noteLink;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user