mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
fix global ko references
This commit is contained in:
parent
bbe0e9e425
commit
8e4e0bd543
@ -168,6 +168,4 @@ entrypoints.registerEntrypoints();
|
|||||||
|
|
||||||
noteTooltipService.setupGlobalTooltip();
|
noteTooltipService.setupGlobalTooltip();
|
||||||
|
|
||||||
linkService.init();
|
|
||||||
|
|
||||||
noteAutocompleteService.init();
|
noteAutocompleteService.init();
|
||||||
|
@ -4,7 +4,9 @@ import infoService from "../services/info.js";
|
|||||||
import treeUtils from "../services/tree_utils.js";
|
import treeUtils from "../services/tree_utils.js";
|
||||||
import attributeAutocompleteService from "../services/attribute_autocomplete.js";
|
import attributeAutocompleteService from "../services/attribute_autocomplete.js";
|
||||||
import utils from "../services/utils.js";
|
import utils from "../services/utils.js";
|
||||||
|
import linkService from "../services/link.js";
|
||||||
import libraryLoader from "../services/library_loader.js";
|
import libraryLoader from "../services/library_loader.js";
|
||||||
|
import noteAutocompleteService from "../services/note_autocomplete.js";
|
||||||
|
|
||||||
const $dialog = $("#attributes-dialog");
|
const $dialog = $("#attributes-dialog");
|
||||||
const $saveAttributesButton = $("#save-attributes-button");
|
const $saveAttributesButton = $("#save-attributes-button");
|
||||||
@ -255,15 +257,43 @@ function AttributesModel() {
|
|||||||
|
|
||||||
let 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() {
|
export async function showDialog() {
|
||||||
utils.closeActiveDialog();
|
utils.closeActiveDialog();
|
||||||
|
|
||||||
await libraryLoader.requireLibrary(libraryLoader.KNOCKOUT);
|
await libraryLoader.requireLibrary(libraryLoader.KNOCKOUT);
|
||||||
|
|
||||||
|
// lazily apply bindings on first use
|
||||||
|
if (!attributesModel) {
|
||||||
attributesModel = new AttributesModel();
|
attributesModel = new AttributesModel();
|
||||||
|
|
||||||
// lazily apply bindings on first use
|
initKoPlugins();
|
||||||
if (!ko.dataFor($dialog[0])) {
|
|
||||||
ko.applyBindings(attributesModel, $dialog[0]);
|
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) {
|
function tabContextMenu(e) {
|
||||||
const $link = $(e.target);
|
const $link = $(e.target);
|
||||||
|
|
||||||
@ -175,6 +161,5 @@ export default {
|
|||||||
createNoteLink,
|
createNoteLink,
|
||||||
addLinkToEditor,
|
addLinkToEditor,
|
||||||
addTextToEditor,
|
addTextToEditor,
|
||||||
init,
|
|
||||||
goToLink
|
goToLink
|
||||||
};
|
};
|
@ -132,18 +132,6 @@ function init() {
|
|||||||
.toggleClass("disabled", !path.trim())
|
.toggleClass("disabled", !path.trim())
|
||||||
.attr(SELECTED_PATH_KEY, path); // we also set attr here so tooltip can be displayed
|
.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 {
|
export default {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user