[note] CKEditor
在 Rails 中,大多數用來客製化 CKEditor 的設定檔都是放在 ./app/assets/javascripts/ckeditor/config.js
:
// ./app/assets/javascripts/ckeditor/config.js
CKEDITOR.editorConfig = function (config) {
// 把 config 寫在這 ...
};
客制化 style 到下拉清單中
在 config 中加上:
config.stylesSet = 'passer_styles:/styles.js';
把設定檔存在 style.js
中:
// ./ckeditor/style.js
CKEDITOR.stylesSet.add('passer_styles', [
// Block-level styles
{ name: 'Blue Title', element: 'h2', styles: { color: 'Blue' } },
{ name: 'Red Title', element: 'h3', styles: { color: 'Red' } },
// Inline styles
{ name: 'CSS Style', element: 'span', attributes: { class: 'my_style' } },
{ name: 'Marker: Yellow', element: 'span', styles: { 'background-color': 'Yellow' } },
]);
- Applying Styles to Editor Content @ guide
- CKEDITOR.stylesSet @ API
讓 CKEditor 載入外部 CSS 樣式
設定檔加上:
config.bodyClass = 'ckeditor-body';