diff --git a/public/javascripts/dialogs/add_link.js b/public/javascripts/dialogs/add_link.js index 649cb14d5..fa9b57ce1 100644 --- a/public/javascripts/dialogs/add_link.js +++ b/public/javascripts/dialogs/add_link.js @@ -10,8 +10,6 @@ const addLink = (function() { function showDialog() { glob.activeDialog = dialogEl; - noteDetailEl.summernote('editor.saveRange'); - dialogEl.dialog({ modal: true, width: 500 @@ -21,7 +19,7 @@ const addLink = (function() { linkTitleEl.val(''); function setDefaultLinkTitle(noteId) { - const noteTitle = treeUtils.getNoteTitle(noteId); + const noteTitle = noteTree.getNoteTitle(noteId); linkTitleEl.val(noteTitle); } @@ -31,7 +29,8 @@ const addLink = (function() { minLength: 0, change: () => { const val = autoCompleteEl.val(); - const noteId = link.getNodePathFromLabel(val); + const notePath = link.getNodePathFromLabel(val); + const noteId = treeUtils.getNoteIdFromNotePath(notePath); if (noteId) { setDefaultLinkTitle(noteId); @@ -40,7 +39,8 @@ const addLink = (function() { // this is called when user goes through autocomplete list with keyboard // at this point the item isn't selected yet so we use supplied ui.item to see WHERE the cursor is focus: (event, ui) => { - const noteId = link.getNodePathFromLabel(ui.item.value); + const notePath = link.getNodePathFromLabel(ui.item.value); + const noteId = treeUtils.getNoteIdFromNotePath(notePath); setDefaultLinkTitle(noteId); } @@ -57,13 +57,22 @@ const addLink = (function() { dialogEl.dialog("close"); - noteDetailEl.summernote('editor.restoreRange'); + const editor = noteEditor.getEditor(); + const doc = editor.document; - noteDetailEl.summernote('createLink', { - text: linkTitle, - url: 'app#' + notePath, - isNewWindow: true - }); +// doc.enqueueChanges( () => { +// // const link = '' + linkTitle + ''; +// +// editor.data.insertContent({ +// linkHref: '#' + notePath +// }, doc.selection); +// } ); + + // noteDetailEl.summernote('createLink', { + // text: linkTitle, + // url: 'app#' + notePath, + // isNewWindow: true + // }); } return false; diff --git a/public/javascripts/init.js b/public/javascripts/init.js index da5d72052..d90efd4e2 100644 --- a/public/javascripts/init.js +++ b/public/javascripts/init.js @@ -82,7 +82,7 @@ $.ui.autocomplete.filter = (array, terms) => { }; $(document).tooltip({ - items: ".note-editable a", + items: "#note-detail a", content: function(callback) { const noteId = link.getNotePathFromLink($(this).attr("href")); diff --git a/public/javascripts/link.js b/public/javascripts/link.js index 27e2c5fd1..61e157135 100644 --- a/public/javascripts/link.js +++ b/public/javascripts/link.js @@ -67,7 +67,7 @@ const link = (function() { // 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); + $(document).on('dblclick', '#note-detail a, div.ui-tooltip-content', goToInternalNote); return { getNodePathFromLabel, diff --git a/public/javascripts/note_editor.js b/public/javascripts/note_editor.js index 12898b38c..ac84e0779 100644 --- a/public/javascripts/note_editor.js +++ b/public/javascripts/note_editor.js @@ -82,12 +82,12 @@ const noteEditor = (function() { function setNoteBackgroundIfProtected(note) { if (note.detail.is_protected) { - $(".note-editable").addClass("protected"); + $("#note-detail").addClass("protected"); protectButton.hide(); unprotectButton.show(); } else { - $(".note-editable").removeClass("protected"); + $("#note-detail").removeClass("protected"); protectButton.show(); unprotectButton.hide(); } @@ -126,9 +126,6 @@ const noteEditor = (function() { noteTitleEl.val(currentNote.detail.note_title); - // Clear contents and remove all stored history. This is to prevent undo from going across notes - //noteDetailEl.summernote('reset'); - editor.setData(currentNote.detail.note_text); noteChangeDisabled = false; @@ -142,6 +139,10 @@ const noteEditor = (function() { return await server.get('notes/' + noteId); } + function getEditor() { + return editor; + } + $(document).ready(() => { noteTitleEl.on('input', () => { noteChanged(); @@ -179,6 +180,7 @@ const noteEditor = (function() { loadNote, getCurrentNote, getCurrentNoteId, - newNoteCreated + newNoteCreated, + getEditor }; })(); \ No newline at end of file