我正在尝试为 ckeditor 编写一个插件,例如 CKEditor Custom Plugins Button下面的链接
问题是,我希望按钮在单击后更改,然后更改回来,以便用户知道发生了什么事。添加按钮后如何更改图标的路径?有没有像 editor.ui.editButton 这样的东西?
谢谢!
我正在尝试为 ckeditor 编写一个插件,例如 CKEditor Custom Plugins Button下面的链接
问题是,我希望按钮在单击后更改,然后更改回来,以便用户知道发生了什么事。添加按钮后如何更改图标的路径?有没有像 editor.ui.editButton 这样的东西?
谢谢!
$('.cke_button__BUTTONNAME_icon').css('background-position', '0 0').css('background-image', 'url(pathtoimage)').css('background-repeat','no-repeat');
其中BUTTONNAME都是小写字母,pathtoimage是相对于 html 文件的。
使用this.path来获得相对于 plugin.js 的图像路径。重要的事情 this.path 应该在功能范围之外,如下所示:
var _p = this.path;
editor.addCommand('toggleAutocorrect',
{
exec : function()
{
$('.cke_button__toggleautocorrect_icon').css('background-position', '0 0').css('background-image', 'url("' + _p + '/images/autocorrectOff.png")').css('background-repeat','no-repeat');
}
}
});
editor.ui.addButton('ToggleAutocorrect',
{
label: 'Toggle Autocorrect',
command: 'toggleAutocorrect',
icon: this.path + 'images/toggleAutocorrect.png'
});
我有一个肮脏的黑客:(使用jQuery)
$('.cke_button_COMMANDNAME.cke_icon').css('backgroundImage', 'url('+thisPath+'imageOff.gif)');
Commandname 按钮的名称在哪里,这个路径是我在插件中启动的 var
var thisPath = this.path;