根据选择切换ckeditor插件菜单按钮状态的正确方法是什么?
例如,在链接/取消链接插件中,我只想在光标位于链接中时启用取消链接.
editor.addCommand("unlink",{
exec: function (editor) {
//do something here
},refresh: function (editor,path) {
// never seems to get fired. Is this even the right hook?
}
});
editor.ui.addButton("Unlink",{
label: "Unlink",command: "unlink"
});
谢谢您的帮助!
解决方法
有一个
CKEDITOR.commandDefinition#contextSensitive属性可以控制特定上下文中的命令状态.
例如,Unlink按钮的actual implementation看起来像:
CKEDITOR.unlinkCommand.prototype = {
exec: function( editor ) {
...
},refresh: function( editor,path ) {
var element = path.lastElement && path.lastElement.getAscendant( 'a',true );
if ( element && element.getName() == 'a' && element.getAttribute( 'href' ) && element.getChildCount() )
this.setState( CKEDITOR.TRISTATE_OFF );
else
this.setState( CKEDITOR.TRISTATE_disABLED );
},contextSensitive: 1,...
};