Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
api method to detect navigation away from current page
azivner89299f865c1c
diff --git a/src/public/javascripts/services/frontend_script_api.js b/src/public/javascripts/services/frontend_script_api.jsindex df7d331030..ebdfa7ef79 100644--- a/src/public/javascripts/services/frontend_script_api.js+++ b/src/public/javascripts/services/frontend_script_api.js@@ -203,6 +203,19 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null) {*/this.getCurrentNoteContent = noteDetailService.getCurrentNoteContent;+ /**+ * This method checks whether user navigated away from the note from which the scripts has been started.+ * This is necessary because script execution is async and by the time it is finished, the user might have+ * already navigated away from this page - the end result would be that script might return data for the wrong+ * note.+ *+ * @method+ * @return {boolean} returns true if the original note is still loaded, false if user switched to another+ */+ this.isNoteStillLoaded = () => {+ return this.originEntity.noteId === noteDetailService.getCurrentNoteId();+ };+/*** @method* @param {function} func - callback called on note change as user is typing (not necessarily tied to save event)