admin管理员组文章数量:1321057
Is it possible to create a drop down style menu consisting of toolbar buttons?
I want to have a button on the toolbar which groups the alignment buttons (and possibly others) into a drop down menu.
Thanks
Is it possible to create a drop down style menu consisting of toolbar buttons?
I want to have a button on the toolbar which groups the alignment buttons (and possibly others) into a drop down menu.
Thanks
Share Improve this question edited Mar 25, 2014 at 13:10 Jeroen Heijmans 4,5462 gold badges19 silver badges16 bronze badges asked Mar 25, 2014 at 8:37 Michael BatesMichael Bates 1,9342 gold badges30 silver badges43 bronze badges2 Answers
Reset to default 7The problem is not that hard but still you got to write a couple lines of code. The following logic inside pluginsLoaded
can (should) be defined in init
of a totally new plugin (which could be called "groupped-justify"). Otherwise, if executed too late, e.g. after toolbar was generated, the whole code makes no sense.
See the official plugin development guide to know more.
Also see the jsFiddle with a working example.
CKEDITOR.replace( 'editor', {
plugins: 'wysiwygarea,sourcearea,basicstyles,toolbar,menu,menubutton,justify',
on: {
pluginsLoaded: function() {
var editor = this,
items = {};
editor.addMenuGroup( 'some_group' );
items.justifyleft = {
label: editor.lang.justify.left,
group: 'some_group',
mand: 'justifyleft',
order: 1
};
items.justifyright = {
label: editor.lang.justify.right,
group: 'some_group',
mand: 'justifyright',
order: 2
};
editor.addMenuItems( items );
editor.ui.add( 'Groupped', CKEDITOR.UI_MENUBUTTON, {
label: 'Groupped justify',
// Disable in source mode.
modes: {
wysiwyg: 1
},
icon: 'JustifyLeft',
onMenu: function() {
var active = {};
// Make all items active.
for ( var p in items )
active[ p ] = CKEDITOR.TRISTATE_OFF;
return active;
}
} );
}
}
} );
I had the same code that @oleq has suggested. In my case i needed them on plugin init and so could'nt display menu items because of an error caused by "mand" in items object. I don't know why exactly this was happening but i managed to fix it by removing mand and adding onClick event to each item
items.flleft = {
label: "Add and align left",
group: 'some_group',
icon: this.path + 'icons/imgtemplate_left.png',
order: 1,
onClick: function(){
// Do stuff on menu item clicked
}
};
Hope this helps
本文标签: javascriptDropdown toolbar button for CKEditor 4Stack Overflow
版权声明:本文标题:javascript - Dropdown toolbar button for CKEditor 4 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742081499a2419726.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论