此示例在 ESNext/SystemJS 框架中运行良好。
首先,通过jspm安装ckeditor:
jspm install npm:ckeditor
现在,让我们创建一个基于CKEDITOR 的编辑器。我将其命名为editor:
editor.html:
<template>
<textarea change.delegate="updateValue()"></textarea>
<input type="hidden" name.bind="name" value.bind="value" />
</template>
editor.js
import {inject, bindable, bindingMode} from 'aurelia-framework';
import 'ckeditor';
@inject(Element)
export class Editor {
@bindable({ defaultBindingMode: bindingMode.twoWay }) value;
@bindable name;
constructor(element) {
this.element = element;
}
updateValue() {
this.value = this.textArea.value;
}
bind() {
this.textArea = this.element.getElementsByTagName('textarea')[0];
let editor = CKEDITOR.replace(this.textArea);
editor.on('change', (e) => {
this.value = e.editor.getData();
});
}
}
以下部分很奇怪,但由于 ckeditor 的架构,这是必要的
在您的 index.html 中,将此行添加到所有 <script> 标记之前:
<script>var CKEDITOR_BASEPATH = 'jspm_packages/npm/ckeditor@4.5.10/';</script>
它告诉 CKEDITOR 它的资产位于相应的文件夹中。请注意版本。
您的组件现在应该可以工作了,但我们需要做一些额外的配置才能使其在生产中工作。
CKEDITOR 异步加载一些文件。捆绑和导出应用程序时必须导出这些文件。为此,请编辑 build/export.js,现在应该是这样的:
module.exports = {
'list': [
'index.html',
'config.js',
'favicon.ico',
'LICENSE',
'jspm_packages/system.js',
'jspm_packages/system-polyfills.js',
'jspm_packages/system-csp-production.js',
'styles/styles.css'
],
// this section lists any jspm packages that have
// unbundled resources that need to be exported.
// these files are in versioned folders and thus
// must be 'normalized' by jspm to get the proper
// path.
'normalize': [
[
// include font-awesome.css and its fonts files
'font-awesome', [
'/css/font-awesome.min.css',
'/fonts/*'
]
], [
// include bootstrap's font files
'bootstrap', [
'/fonts/*'
]
], [
'bluebird', [
'/js/browser/bluebird.min.js'
]
], [
'ckeditor', [
'/config.js',
'/skins/*',
'/lang/*'
]
]
]
};
现在,gulp export 命令将导出所有必要的文件。
希望这会有所帮助!