Files
Trilium/src/public/javascripts/services/note_detail.js

53 lines
1.3 KiB
JavaScript
Raw Normal View History

import server from './server.js';
2019-08-26 20:21:43 +02:00
import ws from "./ws.js";
2018-03-25 23:25:17 -04:00
import treeCache from "./tree_cache.js";
2020-02-01 11:15:58 +01:00
import NoteComplement from "../entities/note_full.js";
2020-01-12 11:15:23 +01:00
import appContext from "./app_context.js";
2019-05-05 10:59:34 +02:00
function getActiveEditor() {
2020-01-12 12:37:44 +01:00
const activeTabContext = appContext.getActiveTabContext();
if (activeTabContext && activeTabContext.note && activeTabContext.note.type === 'text') {
return activeTabContext.getComponent().getEditor();
}
else {
return null;
}
}
2020-02-01 11:15:58 +01:00
async function loadNoteComplement(noteId) {
const row = await server.get('notes/' + noteId);
2020-02-01 11:15:58 +01:00
return new NoteComplement(row);
}
function focusOnTitle() {
2020-01-24 17:54:47 +01:00
appContext.trigger('focusOnTitle');
}
function focusAndSelectTitle() {
2020-01-24 17:54:47 +01:00
appContext.trigger('focusAndSelectTitle');
}
2019-06-12 19:59:52 +02:00
function noteChanged() {
2020-01-12 12:37:44 +01:00
const activeTabContext = appContext.getActiveTabContext();
2019-06-12 19:59:52 +02:00
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
2020-01-19 21:40:23 +01:00
// FIXME
2020-01-19 22:05:45 +01:00
$(window).on('beforeunload', () => {
//saveNotesIfChanged();
});
export default {
2020-02-01 11:15:58 +01:00
loadNoteComplement,
focusOnTitle,
focusAndSelectTitle,
getActiveEditor,
2020-01-24 17:54:47 +01:00
noteChanged
};