mirror of
https://github.com/zadam/trilium.git
synced 2024-11-11 09:46:25 +08:00
fix global ko references
This commit is contained in:
parent
bbe0e9e425
commit
8e4e0bd543
4 changed files with 33 additions and 32 deletions
|
@ -168,6 +168,4 @@ entrypoints.registerEntrypoints();
|
|||
|
||||
noteTooltipService.setupGlobalTooltip();
|
||||
|
||||
linkService.init();
|
||||
|
||||
noteAutocompleteService.init();
|
||||
|
|
|
@ -4,7 +4,9 @@ import infoService from "../services/info.js";
|
|||
import treeUtils from "../services/tree_utils.js";
|
||||
import attributeAutocompleteService from "../services/attribute_autocomplete.js";
|
||||
import utils from "../services/utils.js";
|
||||
import linkService from "../services/link.js";
|
||||
import libraryLoader from "../services/library_loader.js";
|
||||
import noteAutocompleteService from "../services/note_autocomplete.js";
|
||||
|
||||
const $dialog = $("#attributes-dialog");
|
||||
const $saveAttributesButton = $("#save-attributes-button");
|
||||
|
@ -255,15 +257,43 @@ function AttributesModel() {
|
|||
|
||||
let attributesModel;
|
||||
|
||||
function initKoPlugins() {
|
||||
ko.bindingHandlers.noteLink = {
|
||||
init: async function (element, valueAccessor, allBindings, viewModel, bindingContext) {
|
||||
const noteId = ko.unwrap(valueAccessor());
|
||||
|
||||
if (noteId) {
|
||||
const link = await linkService.createNoteLink(noteId);
|
||||
|
||||
$(element).append(link);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ko.bindingHandlers.noteAutocomplete = {
|
||||
init: function (element, valueAccessor, allBindings, viewModel, bindingContext) {
|
||||
noteAutocompleteService.initNoteAutocomplete($(element));
|
||||
|
||||
$(element).setSelectedPath(bindingContext.$data.selectedPath);
|
||||
|
||||
$(element).on('autocomplete:selected', function (event, suggestion, dataset) {
|
||||
bindingContext.$data.selectedPath = $(element).val().trim() ? suggestion.path : '';
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export async function showDialog() {
|
||||
utils.closeActiveDialog();
|
||||
|
||||
await libraryLoader.requireLibrary(libraryLoader.KNOCKOUT);
|
||||
|
||||
attributesModel = new AttributesModel();
|
||||
|
||||
// lazily apply bindings on first use
|
||||
if (!ko.dataFor($dialog[0])) {
|
||||
if (!attributesModel) {
|
||||
attributesModel = new AttributesModel();
|
||||
|
||||
initKoPlugins();
|
||||
|
||||
ko.applyBindings(attributesModel, $dialog[0]);
|
||||
}
|
||||
|
||||
|
|
|
@ -94,20 +94,6 @@ function addTextToEditor(text) {
|
|||
}
|
||||
}
|
||||
|
||||
function init() {
|
||||
ko.bindingHandlers.noteLink = {
|
||||
init: async function(element, valueAccessor, allBindings, viewModel, bindingContext) {
|
||||
const noteId = ko.unwrap(valueAccessor());
|
||||
|
||||
if (noteId) {
|
||||
const link = await createNoteLink(noteId);
|
||||
|
||||
$(element).append(link);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function tabContextMenu(e) {
|
||||
const $link = $(e.target);
|
||||
|
||||
|
@ -175,6 +161,5 @@ export default {
|
|||
createNoteLink,
|
||||
addLinkToEditor,
|
||||
addTextToEditor,
|
||||
init,
|
||||
goToLink
|
||||
};
|
|
@ -132,18 +132,6 @@ function init() {
|
|||
.toggleClass("disabled", !path.trim())
|
||||
.attr(SELECTED_PATH_KEY, path); // we also set attr here so tooltip can be displayed
|
||||
};
|
||||
|
||||
ko.bindingHandlers.noteAutocomplete = {
|
||||
init: function (element, valueAccessor, allBindings, viewModel, bindingContext) {
|
||||
initNoteAutocomplete($(element));
|
||||
|
||||
$(element).setSelectedPath(bindingContext.$data.selectedPath);
|
||||
|
||||
$(element).on('autocomplete:selected', function (event, suggestion, dataset) {
|
||||
bindingContext.$data.selectedPath = $(element).val().trim() ? suggestion.path : '';
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export default {
|
||||
|
|
Loading…
Reference in a new issue