porting autocomplete to algolia, WIP, #203

This commit is contained in:
azivner
2018-11-07 00:23:50 +01:00
parent 57e9850ca6
commit 3c23d7085e
5 changed files with 92 additions and 20 deletions

View File

@@ -8,6 +8,8 @@ const $autoComplete = $("#jump-to-note-autocomplete");
const $showInFullTextButton = $("#show-in-full-text-button");
const $showRecentNotesButton = $dialog.find(".show-recent-notes-button");
$dialog.on("shown.bs.modal", e => $autoComplete.focus());
async function showDialog() {
glob.activeDialog = $dialog;
@@ -15,25 +17,55 @@ async function showDialog() {
$dialog.modal();
await $autoComplete.autocomplete({
source: noteautocompleteService.autocompleteSource,
focus: event => event.preventDefault(),
minLength: 0,
autoFocus: true,
select: function (event, ui) {
if (ui.item.value === 'No results') {
return false;
$autoComplete.autocomplete({
appendTo: document.querySelector('body'),
hint: false,
autoselect: true,
openOnFocus: true
}, [
{
source: noteautocompleteService.autocompleteSource,
displayKey: 'label',
templates: {
suggestion: function(suggestion) {
return suggestion.label;
}
}
const notePath = linkService.getNotePathFromLabel(ui.item.value);
treeService.activateNote(notePath);
$dialog.modal('hide');
}
]).on('autocomplete:selected', function(event, suggestion, dataset) {
console.log("selected: ", event, suggestion, dataset);
return;
if (ui.item.value === 'No results') {
return false;
}
const notePath = linkService.getNotePathFromLabel(ui.item.value);
treeService.activateNote(notePath);
$dialog.modal('hide');
});
showRecentNotes();
// await $autoComplete.autocomplete({
// source: noteautocompleteService.autocompleteSource,
// focus: event => event.preventDefault(),
// minLength: 0,
// autoFocus: true,
// select: function (event, ui) {
// if (ui.item.value === 'No results') {
// return false;
// }
//
// const notePath = linkService.getNotePathFromLabel(ui.item.value);
//
// treeService.activateNote(notePath);
//
// $dialog.modal('hide');
// }
// });
//showRecentNotes();
}
function showInFullText(e) {