How I ca开发者_JAVA百科n detect that there was a change in the rich text editor in the Edit Post page?
What I want is to execute a function when the user typed something in the rich text editor (HTML and Visual panes).
EDIT: I accomplished that in the HTML pane associating a jQuery keyup event in the hidden textarea that tinyMCE create, but still I've not been able to detect user input in the Visual tab.
I'm using Wordpress 3.2.1 and I know that they are using tinyMCE for the rich text editor functionality.
Seems that tinyMCE uses an iframe
to build the Visual tab in the rich text editor, so I tried the examples pointed here without any results.
Any help appreciated.
Finally I was able to solve this issue by adding this code snippet:
<script type="text/javascript">
jQuery(function ($) {
// Was needed a timeout since RTE is not initialized when this code run.
setTimeout(function () {
for (var i = 0; i < tinymce.editors.length; i++) {
tinymce.editors[i].onChange.add(function (ed, e) {
// Update HTML view textarea (that is the one used to send the data to server).
ed.save();
});
}
}, 1000);
});
</script>
Thannks to @HarkályGergő for his prompting to solve this question :)
Not sure how to add this to WordPress, but from a TinyMCE perspective the isDirty() method on the editor should help.
So you could simply use
if (tinyMCE.activeEditor.isDirty()) {
//Do something
}
to check the currently active editor. WordPress may give you alternative ways to access the editor instance.
精彩评论