Skip to content

Instantly share code, notes, and snippets.

@3cp
Last active July 8, 2020 22:42
Show Gist options
  • Save 3cp/8957ab6d8c6b4fb04341f6ef228e6070 to your computer and use it in GitHub Desktop.
Save 3cp/8957ab6d8c6b4fb04341f6ef228e6070 to your computer and use it in GitHub Desktop.
au1 ckeditor5
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Dumber Gist</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
<base href="/">
</head>
<!--
Dumber gist uses dumber bundler, the default bundle file
is /dist/entry-bundle.js.
The starting module is pointed to aurelia-bootstrapper
(data-main attribute on script) for Aurelia,
The aurelia bootstrapper then loads up user module "main"
(aurelia-app attribute on <body>) which is your src/main.js.
-->
<body aurelia-app="main">
<script src="/dist/entry-bundle.js" data-main="aurelia-bootstrapper"></script>
</body>
</html>
{
"dependencies": {
"aurelia-bootstrapper": "^2.3.3"
}
}
<template>
<require from="./rich-editor"></require>
<rich-editor value.bind="text"></rich-editor>
<hr>
<h4>The raw edited text:</h4>
<pre>${text}</pre>
</template>
export class App {
text = 'Hello Aurelia!';
}
export function configure(aurelia) {
aurelia.use
.standardConfiguration()
.developmentLogging('info');
aurelia.start().then(() => aurelia.setRoot());
}
<template>
<text-area ref="textArea"></text-area>
</template>
import {bindable, bindingMode} from 'aurelia-framework';
import ClassicEditor from '@ckeditor/ckeditor5-build-classic';
export class RichEditor {
@bindable({defaultBindingMode: bindingMode.twoWay}) value = '';
editor = null;
attached() {
this._clearCKEditor();
ClassicEditor.create(this.textArea, {
removePlugins: ['CKFinderUploadAdapter', 'EasyImage', 'ImageCaption', 'ImgeStyle', 'ImageToolbar', 'ImageUpload', 'MediaEmbed']
})
.then(
editor => {
this.editor = editor;
this.editor.setData(this.value);
this.editor.model.document.on('change', () => {
this.value = this.editor.getData();
});
},
err => this.bcx.showError(err)
);
}
detached() {
this._clearCKEditor();
}
_clearCKEditor() {
if (this.editor) {
this.editor.destroy();
this.editor = null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment