admin管理员组文章数量:1021938
CKEditor lets you add custom styles to the styles bo box by editing the file styles.js (see What is a good javascript HTML editor for adding custom HTML elements? for details)
I would like to add unique buttons to the toolbar to apply my custom styles, rather than the user having to select them from the styles bo.
How do you add custom buttons to the CKEditor toolbar?
CKEditor lets you add custom styles to the styles bo box by editing the file styles.js (see What is a good javascript HTML editor for adding custom HTML elements? for details)
I would like to add unique buttons to the toolbar to apply my custom styles, rather than the user having to select them from the styles bo.
How do you add custom buttons to the CKEditor toolbar?
Share Improve this question edited May 23, 2017 at 10:25 CommunityBot 11 silver badge asked Aug 5, 2013 at 9:08 JonJon 3791 gold badge7 silver badges18 bronze badges1 Answer
Reset to default 4Go ahead with the following code:
// Your custom style.
var myStyle = new CKEDITOR.style( {
element: 'span',
attributes: {
'data-foo': 'bar',
'class': 'myClass'
},
styles: {
color: 'red'
}
} );
CKEDITOR.replace( 'editor1', {
on: {
// Register mand and button along with other plugins.
pluginsLoaded: function() {
var editor = this;
// Registers a mand that applies the style.
// Note: it automatically adds Advanced Content Filter rules.
this.addCommand( 'myStyle', new CKEDITOR.styleCommand( myStyle ) );
// Add toolbar button for this mand.
this.ui.addButton && this.ui.addButton( 'myStyleButton', {
label: 'My style',
mand: 'myStyle',
toolbar: 'insert,10'
// You may want to set some icon here.
// icon: 'someIcon'
} );
}
}
} );
CKEditor lets you add custom styles to the styles bo box by editing the file styles.js (see What is a good javascript HTML editor for adding custom HTML elements? for details)
I would like to add unique buttons to the toolbar to apply my custom styles, rather than the user having to select them from the styles bo.
How do you add custom buttons to the CKEditor toolbar?
CKEditor lets you add custom styles to the styles bo box by editing the file styles.js (see What is a good javascript HTML editor for adding custom HTML elements? for details)
I would like to add unique buttons to the toolbar to apply my custom styles, rather than the user having to select them from the styles bo.
How do you add custom buttons to the CKEditor toolbar?
Share Improve this question edited May 23, 2017 at 10:25 CommunityBot 11 silver badge asked Aug 5, 2013 at 9:08 JonJon 3791 gold badge7 silver badges18 bronze badges1 Answer
Reset to default 4Go ahead with the following code:
// Your custom style.
var myStyle = new CKEDITOR.style( {
element: 'span',
attributes: {
'data-foo': 'bar',
'class': 'myClass'
},
styles: {
color: 'red'
}
} );
CKEDITOR.replace( 'editor1', {
on: {
// Register mand and button along with other plugins.
pluginsLoaded: function() {
var editor = this;
// Registers a mand that applies the style.
// Note: it automatically adds Advanced Content Filter rules.
this.addCommand( 'myStyle', new CKEDITOR.styleCommand( myStyle ) );
// Add toolbar button for this mand.
this.ui.addButton && this.ui.addButton( 'myStyleButton', {
label: 'My style',
mand: 'myStyle',
toolbar: 'insert,10'
// You may want to set some icon here.
// icon: 'someIcon'
} );
}
}
} );
本文标签: javascriptAdd buttons for custom styles to CKEditorStack Overflow
版权声明:本文标题:javascript - Add buttons for custom styles to CKEditor - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745578792a2157184.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论