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

40 lines
1.2 KiB
JavaScript
Raw Normal View History

import bundleService from "./bundle.js";
import server from "./server.js";
import noteDetailService from "./note_detail.js";
2018-11-08 17:30:35 +08:00
const $component = $('#note-detail-render');
const $noteDetailRenderHelp = $('#note-detail-render-help');
const $noteDetailRenderContent = $('#note-detail-render-content');
const $renderButton = $('#render-button');
async function render() {
const attributes = await noteDetailService.getAttributes();
const renderNotes = attributes.filter(attr =>
attr.type === 'relation'
&& attr.name === 'renderNote'
&& !!attr.value);
2018-11-08 17:30:35 +08:00
$component.show();
$noteDetailRenderContent.empty();
$noteDetailRenderContent.toggle(renderNotes.length > 0);
$noteDetailRenderHelp.toggle(renderNotes.length === 0);
for (const renderNote of renderNotes) {
const bundle = await server.get('script/bundle/' + renderNote.value);
$noteDetailRenderContent.append(bundle.html);
2018-05-27 07:58:08 +08:00
2018-08-29 05:08:56 +08:00
await bundleService.executeBundle(bundle, noteDetailService.getCurrentNote());
}
2018-05-27 07:58:08 +08:00
}
$renderButton.click(render);
export default {
show: render,
getContent: () => "",
focus: () => null,
onNoteChange: () => null,
cleanup: () => $noteDetailRenderContent.empty()
}