admin管理员组文章数量:1313599
I am developing a plug-in for CKEditor that needs to make some changes to the editor's content immediately before saving. In FCKeditor, I achieved this using the OnAfterLinkedFieldUpdate
event but I haven't yet been able to find an equivalent way of doing this in CKEditor. I had hoped there would be a suitable event to hook into but there doesn't appear to be. Does anyone know of a way of doing this?
I am developing a plug-in for CKEditor that needs to make some changes to the editor's content immediately before saving. In FCKeditor, I achieved this using the OnAfterLinkedFieldUpdate
event but I haven't yet been able to find an equivalent way of doing this in CKEditor. I had hoped there would be a suitable event to hook into but there doesn't appear to be. Does anyone know of a way of doing this?
-
What
save
event/function are you using? The "save" button? – Pekka Commented Feb 16, 2010 at 13:32 -
Yes. The plug-in will be used by site owners who already have CKEditor set up however they have seen fit, so I would prefer to keep my plug-in as clean as possible, which means not replacing the standard save button if possible. I've looked at the source and my best bet seems to to add a
submit
event handler to the form containing the editor, but this hardly qualifies as clean. – Tim Down Commented Feb 16, 2010 at 14:13
2 Answers
Reset to default 6 +125You could use the getData event, but be careful because it's fired also for internal uses.
I've filed http://dev.fckeditor/ticket/5254 to recreate the previous event
As the link above doesn't really have the solution on substitude OnAfterLinkedFieldUpdate event I have writen a short post on how to go around it.
Here is the form:
<form id="my_form" action="submit.php" method="post" name="my_form">
<textarea id="my_text" name="my_text"></textarea>
<input id="submitForm" type="submit" name="submitForm" value="Submit" />
</form>
JavaScript:
var formSubmitted = false;
$("#submitForm").live('click', function(event) {
if (formSubmitted === true) {
formSubmitted = false;
return;
}
event.preventDefault();
//put here function to edit content == OnAfterLinkedFieldUpdate
var editor = CKEDITOR.instances.my_text;
var html = editor.getData();
html.replace(searchvalue, newvalue);
editor.setData(html);
formSubmitted = true;
$(this).trigger('click');
});
The code is here
本文标签: javascriptUpdate editor content immediately before save in CKEditor pluginStack Overflow
版权声明:本文标题:javascript - Update editor content immediately before save in CKEditor plug-in - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741944267a2406318.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论