Files
Trilium/src/public/javascripts/services/note_detail.js
2020-02-01 11:15:58 +01:00

53 lines
1.3 KiB
JavaScript

import server from './server.js';
import ws from "./ws.js";
import treeCache from "./tree_cache.js";
import NoteComplement from "../entities/note_full.js";
import appContext from "./app_context.js";
function getActiveEditor() {
const activeTabContext = appContext.getActiveTabContext();
if (activeTabContext && activeTabContext.note && activeTabContext.note.type === 'text') {
return activeTabContext.getComponent().getEditor();
}
else {
return null;
}
}
async function loadNoteComplement(noteId) {
const row = await server.get('notes/' + noteId);
return new NoteComplement(row);
}
function focusOnTitle() {
appContext.trigger('focusOnTitle');
}
function focusAndSelectTitle() {
appContext.trigger('focusAndSelectTitle');
}
function noteChanged() {
const activeTabContext = appContext.getActiveTabContext();
if (activeTabContext) {
activeTabContext.noteChanged();
}
}
// this makes sure that when user e.g. reloads the page or navigates away from the page, the note's content is saved
// this sends the request asynchronously and doesn't wait for result
// FIXME
$(window).on('beforeunload', () => {
//saveNotesIfChanged();
});
export default {
loadNoteComplement,
focusOnTitle,
focusAndSelectTitle,
getActiveEditor,
noteChanged
};