您可以使用mce_external_plugins
滤器并将其链接到js文件。然后,您可以在该文件中进行处理。
function tinymce_init() {
// Hook to tinymce plugins filter
add_filter( \'mce_external_plugins\', \'tinymce_plugin\' );
}
add_filter(\'init\', \'tinymce_init\');
function tinymce_plugin($init) {
// We create a new plugin... linked to a js file.
// Mine was created from a plugin... but you can change this to link to a file in your plugin
$init[\'keyup_event\'] = plugins_url() . \'/test/keyup_event.js\';
return $init;
}
因此,这些函数将创建必要的挂钩,以便将js文件加载到tinymce编辑器中。
现在我们可以使用js文件获取每个keyup事件的编辑器内容。。然后从那里开始处理。
jQuery(document).ready(function($) {
// Create \'keyup_event\' tinymce plugin
tinymce.PluginManager.add(\'keyup_event\', function(editor, url) {
// Create keyup event
editor.on(\'keyup\', function(e) {
// Get the editor content (html)
get_ed_content = tinymce.activeEditor.getContent();
// Do stuff here... (run do_stuff_here() function)
do_stuff_here(get_ed_content);
});
});
// This is needed for running the keyup event in the text (HTML) view of the editor
$(\'#content\').on(\'keyup\', function(e) {
// Get the editor content (html)
get_ed_content = tinymce.activeEditor.getContent();
// Do stuff here... (run do_stuff_here() function)
do_stuff_here(get_ed_content);
});
// This function allows the script to run from both locations (visual and text)
function do_stuff_here(content) {
// Now, you can further process the data in a single function
alert(content);
}
});
现在。。。每次在编辑器中键入时。。javascript文件将处理其内容。