CKeditor保存事件
我按照本主题中编写的步骤进行操作:CKEditor,AJAX Save 如果有人按下 AjaxSave 按钮,我尝试触发自定义“saved.ckeditor”事件。但我没有成功。
ckeditor/plugins/ajaxsave/plugin.js:
(function(){
var saveCmd =
{
modes : { wysiwyg:1, source:1 },
exec : function( editor )
{
editor.fire('saved.ckeditor');
$(editor).trigger('saved.ckeditor', editor.getData());
alert(editor.getData());
}
}
var pluginName = 'ajaxsave';
CKEDITOR.plugins.add( pluginName,
{
init : function( editor )
{
var command = editor.addCommand( pluginName, saveCmd );
command.modes = { wysiwyg : !!( editor.element.$.form ) };
editor.ui.addButton( 'AjaxSave',
{
label : editor.lang.save,
command : pluginName,
className : 'cke_button_save'
});
}
});
})();
如果我在函数中获取或设置编辑器数据,则会自动触发 get 和 set 事件。但我什至无法手动触发“getData.ckeditor”事件。
有什么建议吗?
另一件事:如果编辑器的内容自上次保存以来没有更改(它不是脏的),如何禁用该按钮?
I was following the steps written in this topic: CKEditor, AJAX Save
I tried to fire a custom 'saved.ckeditor' event if anybody press the AjaxSave button. But I did not succeeded.
ckeditor/plugins/ajaxsave/plugin.js:
(function(){
var saveCmd =
{
modes : { wysiwyg:1, source:1 },
exec : function( editor )
{
editor.fire('saved.ckeditor');
$(editor).trigger('saved.ckeditor', editor.getData());
alert(editor.getData());
}
}
var pluginName = 'ajaxsave';
CKEDITOR.plugins.add( pluginName,
{
init : function( editor )
{
var command = editor.addCommand( pluginName, saveCmd );
command.modes = { wysiwyg : !!( editor.element.$.form ) };
editor.ui.addButton( 'AjaxSave',
{
label : editor.lang.save,
command : pluginName,
className : 'cke_button_save'
});
}
});
})();
If I get or set the editor data in the function, the get and set events will automatically be fired. But I could not even fire a 'getData.ckeditor' event manually.
Any tips?
An other thing: how can I disable the button if the editor's content haven't changed since the last save (it is not dirty)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我有一个解决方法。
在外面我可以监听设置事件:
...当按下按钮时,将数据设置为其当前值:
这样至少会触发一个事件...
但当我从外部手动设置内容时我应该小心......
I have a workaround.
Outside I can listen to the set event:
...and when the button is pressed, set the data with its current value:
This way at least an event is fired...
But I shold be careful when I manually set the content from outside...
试试这个,你需要完成 exec() 函数
并且不要忘记在 config.js 中启用插件
try this, you need to finish the exec() function
and don't forget to enable the plugin in config.js
您可以编辑常规保存按钮的功能来执行您想要的操作:
html:
javascript:
You can edit the functionality of the regular save button to do what you want:
html:
javascript: