Skip to content

Build your personal knowledge base with Trilium Notes

fix global ko references

zadam8e4e0bd543cb
diff --git a/src/public/javascripts/desktop.js b/src/public/javascripts/desktop.js
index 0748bf2c0e..f17740ca91 100644
--- a/src/public/javascripts/desktop.js
+++ b/src/public/javascripts/desktop.js
@@ -168,6 +168,4 @@ entrypoints.registerEntrypoints();
noteTooltipService.setupGlobalTooltip();
-linkService.init();
-
noteAutocompleteService.init();
diff --git a/src/public/javascripts/dialogs/attributes.js b/src/public/javascripts/dialogs/attributes.js
index 51246041ce..ee52f3ea6a 100644
--- a/src/public/javascripts/dialogs/attributes.js
+++ b/src/public/javascripts/dialogs/attributes.js
@@ -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]);
}
diff --git a/src/public/javascripts/services/link.js b/src/public/javascripts/services/link.js
index 25422f33dc..20a9048123 100644
--- a/src/public/javascripts/services/link.js
+++ b/src/public/javascripts/services/link.js
@@ -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
};
\ No newline at end of file
diff --git a/src/public/javascripts/services/note_autocomplete.js b/src/public/javascripts/services/note_autocomplete.js
index 7dced1bf43..2d5c9536e6 100644
--- a/src/public/javascripts/services/note_autocomplete.js
+++ b/src/public/javascripts/services/note_autocomplete.js
@@ -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 {