クラス名で作成されたエディタでは、異なる設定を行うことはできません。そのような場合は、グローバルCKEDITOR.config
のみが考慮されます。
この問題にはまだ簡単な回避策があります。まず、文書の先頭にこのスクリプトを置く:あなたはこのように交換したい各<textarea>
について(config.customConfigとして)
<script>
CKEDITOR.replaceClass = null; // Disable replacing by class
</script>
は今data-custom-config
プロパティを定義します。
<textarea class="ckeditor" data-custom-config="myCustomConfig.js">
Moo
</textarea>
は最後に次のコードを使用しますクラス名で編集者を手動で置き換える(クラスがckeditor
であると仮定します)。このコードは、data-custom-config
属性で定義された設定で駆動CKEditorバージョンのインスタンスを持つクラスckeditor
のすべてのテキストエリアを置き換えます:
var textareas = Array.prototype.slice.call(document.getElementsByClassName('ckeditor')),
textarea, cfg, customCfg;
while ((textarea = textareas.pop())) {
textarea = new CKEDITOR.dom.element(textarea);
cfg = {};
if ((customCfg = textarea.getAttribute('data-custom-config')))
cfg[ 'customConfig' ] = customCfg;
CKEDITOR.replace(textarea.getId(), cfg)
}
そして今は上に桜を付属しています。 myCustomConfig.js
でカスタムツールバーの設定を入れて:あなたは簡単に要素の選択のためのjQueryを必要とするためにこのコードを変更することができますもちろん
CKEDITOR.editorConfig = function(config) {
config.toolbar = [
{ name: 'basicstyles', items: [ 'Bold', 'Italic' ] }
];
};
は、リテラルの代わりに、config.customConfig
など、いくつかのオブジェクトを使用します。これは、問題をどのように解決できるかを示す単なるショーケースです。