mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
add link converted to module
This commit is contained in:
parent
979acc8b4a
commit
c723bfc3ac
@ -1,26 +1,32 @@
|
||||
$(document).bind('keydown', 'alt+l', () => {
|
||||
$("#note-autocomplete").val('');
|
||||
$("#link-title").val('');
|
||||
const addLink = (function() {
|
||||
const dialogEl = $("#insert-link-dialog");
|
||||
const formEl = $("#insert-link-form");
|
||||
const autoCompleteEl = $("#note-autocomplete");
|
||||
const noteDetailEl = $('#note-detail');
|
||||
const linkTitleEl = $("#link-title");
|
||||
|
||||
const noteDetail = $('#note-detail');
|
||||
noteDetail.summernote('editor.saveRange');
|
||||
function showDialog() {
|
||||
noteDetailEl.summernote('editor.saveRange');
|
||||
|
||||
$("#insert-link-dialog").dialog({
|
||||
dialogEl.dialog({
|
||||
modal: true,
|
||||
width: 500
|
||||
});
|
||||
|
||||
autoCompleteEl.val('').focus();
|
||||
linkTitleEl.val('');
|
||||
|
||||
function setDefaultLinkTitle(noteId) {
|
||||
const noteTitle = getNoteTitle(noteId);
|
||||
|
||||
$("#link-title").val(noteTitle);
|
||||
linkTitleEl.val(noteTitle);
|
||||
}
|
||||
|
||||
$("#note-autocomplete").autocomplete({
|
||||
autoCompleteEl.autocomplete({
|
||||
source: getAutocompleteItems(glob.allNoteIds),
|
||||
minLength: 0,
|
||||
change: () => {
|
||||
const val = $("#note-autocomplete").val();
|
||||
const val = autoCompleteEl.val();
|
||||
const noteId = getNodeIdFromLabel(val);
|
||||
|
||||
if (noteId) {
|
||||
@ -35,22 +41,21 @@ $(document).bind('keydown', 'alt+l', () => {
|
||||
setDefaultLinkTitle(noteId);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
$("#insert-link-form").submit(() => {
|
||||
let val = $("#note-autocomplete").val();
|
||||
formEl.submit(() => {
|
||||
let val = autoCompleteEl.val();
|
||||
|
||||
const noteId = getNodeIdFromLabel(val);
|
||||
|
||||
if (noteId) {
|
||||
const linkTitle = $("#link-title").val();
|
||||
const noteDetail = $('#note-detail');
|
||||
const linkTitle = linkTitleEl.val();
|
||||
|
||||
$("#insert-link-dialog").dialog("close");
|
||||
dialogEl.dialog("close");
|
||||
|
||||
noteDetail.summernote('editor.restoreRange');
|
||||
noteDetailEl.summernote('editor.restoreRange');
|
||||
|
||||
noteDetail.summernote('createLink', {
|
||||
noteDetailEl.summernote('createLink', {
|
||||
text: linkTitle,
|
||||
url: 'app#' + noteId,
|
||||
isNewWindow: true
|
||||
@ -104,3 +109,10 @@ function getNodeIdFromLabel(label) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$(document).bind('keydown', 'alt+l', showDialog);
|
||||
|
||||
return {
|
||||
showDialog
|
||||
};
|
||||
})();
|
Loading…
x
Reference in New Issue
Block a user