From 169825abfff5b14f091d539979b39b6c0c5b1c28 Mon Sep 17 00:00:00 2001 From: azivner Date: Sun, 27 Aug 2017 23:45:01 -0400 Subject: [PATCH] initial implementation of link dialog (buggy and feature incomplete) --- src/templates/app.html | 16 ++++++++++++ static/js/init.js | 57 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/src/templates/app.html b/src/templates/app.html index 3171ea999..426c95298 100644 --- a/src/templates/app.html +++ b/src/templates/app.html @@ -84,6 +84,22 @@ + + diff --git a/static/js/init.js b/static/js/init.js index feec14292..404b4a4c9 100644 --- a/static/js/init.js +++ b/static/js/init.js @@ -92,4 +92,61 @@ $(document).on('click', 'div.popover-content a', function(e) { e.preventDefault(); } +}); + +let linkInfo; + +$(document).bind('keydown', 'alt+l', function() { + $("#insertLinkDialog").dialog({ + modal: true + }); + + let autocompleteItems = []; + + for (let noteId in globalNoteNames) { + autocompleteItems.push({ + value: globalNoteNames[noteId] + " (" + noteId + ")", + label: globalNoteNames[noteId] + }); + } + + $("#noteAutocomplete").autocomplete({ + source: autocompleteItems, + change: function(event, ui) { + let val = $("#noteAutocomplete").val(); + + val = val.replace(/ \([A-Za-z0-9]{22}\)/, ""); + + $("#linkTitle").val(val); + } + }); + + //const noteDetail = $('#noteDetail'); + + //linkInfo = noteDetail.summernote('invoke', 'editor.getLinkInfo'); + //noteDetail.summernote('invoke', 'editor.saveRange'); +}); + +$("#addLinkButton").click(function() { + let val = $("#noteAutocomplete").val(); + + const noteIdMatch = / \(([A-Za-z0-9]{22})\)/.exec(val); + + if (noteIdMatch !== null) { + const noteId = noteIdMatch[1]; + const linkTitle = $("#linkTitle").val(); + + const noteDetail = $('#noteDetail'); + + noteDetail.summernote('createLink', { + text: globalNoteNames[noteId], + url: 'app#' + noteId, + isNewWindow: true +// range: linkInfo.range + }); + + //noteDetail.summernote('invoke', 'editor.restoreRange'); + + $("#insertLinkDialog").dialog("close"); + } }); \ No newline at end of file