FeatherWikiExamples/SunEditorExtension.js

51 lines
1.8 KiB
JavaScript

(function sunEditorextension () {
if (!window.FW._loaded) return setTimeout(sunEditorextension , 1); // wait until FW is mounted
const { state, emitter } = window.FW;
const { ONLOAD, RENDER } = state.events;
console.log('running sunEditorextension ');
const css = document.createElement('link');
css.rel="stylesheet";
css.href="https://cdn.jsdelivr.net/npm/suneditor@latest/dist/css/suneditor.min.css";
document.head.appendChild(css);
const script = document.createElement('script');
script.onload = () => { emitter.emit(RENDER) }
script.type="text/javascript";
script.src="https://cdn.jsdelivr.net/npm/suneditor@latest/dist/suneditor.min.js";
document.head.appendChild(script);
[RENDER].forEach(ev => {
emitter.on(ev, () => {
setTimeout(() => {
!document.querySelector('main > section > form > div.sun-editor') ? sunEditor() : '';
}, 50);
});
});
emitter.emit('DOMContentLoaded');
function sunEditor() {
if (state.edits) {
if (!state.edits.useMd) {
const editor = SUNEDITOR.create((document.getElementById('e') || 'e'),{ value: state.edits.content,
buttonList: [
['undo', 'redo'],
['font', 'fontSize', 'formatBlock'],
['paragraphStyle', 'blockquote'],
['bold', 'underline', 'italic', 'strike', 'subscript', 'superscript'],
['fontColor', 'hiliteColor', 'textStyle','lineHeight'],
['removeFormat'],
['outdent', 'indent'],
['align', 'horizontalRule', 'list'],
['table', 'link'],
['fullScreen', 'showBlocks', 'codeView']]
});
editor.onChange = function (contents, core) { state.edits.content = contents; }
editor.setDefaultStyle('font-family: Arial; font-size: 14px;');
}
}
}
})();