[英]Toggle the State of a CKEditor plugin button
根据选择切换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按钮的实际实现如下所示:
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,
...
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.