trilium/src/public/javascripts/services/note_detail_text.js

48 lines
1.1 KiB
JavaScript
Raw Normal View History

2018-03-28 10:42:46 +08:00
import libraryLoader from "./library_loader.js";
import noteDetailService from './note_detail.js';
const $noteDetailText = $('#note-detail-text');
let textEditor = null;
2018-03-28 09:46:38 +08:00
async function show() {
if (!textEditor) {
2018-03-28 10:42:46 +08:00
await libraryLoader.requireLibrary(libraryLoader.CKEDITOR);
textEditor = await BalloonEditor.create($noteDetailText[0], {});
textEditor.document.on('change', noteDetailService.noteChanged);
}
// temporary workaround for https://github.com/ckeditor/ckeditor5-enter/issues/49
textEditor.setData(noteDetailService.getCurrentNote().content || "<p></p>");
$noteDetailText.show();
}
function getContent() {
let content = textEditor.getData();
// if content is only tags/whitespace (typically <p>&nbsp;</p>), then just make it empty
// this is important when setting new note to code
if (jQuery(content).text().trim() === '' && !content.includes("<img")) {
content = '';
}
return content;
}
function focus() {
$noteDetailText.focus();
}
function getEditor() {
return textEditor;
}
export default {
2018-03-28 09:46:38 +08:00
show,
getEditor,
getContent,
focus
}