initial implementation of link dialog (buggy and feature incomplete)

This commit is contained in:
azivner 2017-08-27 23:45:01 -04:00
parent 9259db9f87
commit 169825abff
2 changed files with 73 additions and 0 deletions

View file

@ -84,6 +84,22 @@
</select>
</div>
<div id="insertLinkDialog" title="Recent notes" style="display: none;">
<form>
<div class="form-group">
<label for="noteAutocomplete">Link to note</label>
<input id="noteAutocomplete" style="width: 100%;">
</div>
<div class="form-group">
<label for="linkTitle">Link title</label>
<input id="linkTitle" style="width: 100%;">
</div>
<button id="addLinkButton" class="btn btn-sm">Add link</button>
</form>
</div>
<script type="text/javascript">
const baseUrl = '';
</script>

View file

@ -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");
}
});