Recently, when I was working on a real estate project, I used the text editor tiny mce. Due to JavaScript verification, I began to study tiny mce. I searched du Niang and Google for half a day, I found that tiny mce event processing is very rare, and the official documentation is an api in English. So I posted my solution for reference by friends who encountered the same problem, hope to help you.
I will not introduce the installation of the tiny mce editor too much. I still have a lot of information on the Internet.
Next let's go to the topic.
Tiny mce event processing in Rich Text Editor
First, we need to specify the callback function for event processing when initializing the editor. The Code is as follows:
- tinyMCE.init({
- mode : "exact",
- theme : "mytheme",
- language : "se",
- elements : "elm1,elm2",
- handle_event_callback : 'eventHandle',
- });
Handle_event_callback specifies the callback function for event processing. The called function eventHandle has a parameter, that is, the response event. Next let's take a look at the eventHandle function I wrote in the project.
- Function eventHandle (event)
- {
- If (event. type = 'click' | event. type = 'keyup '){
- Var cur_html = tinyMCE. get ('content'). getContent ();
- If (! Cur_html ){
- Tiny_mce_check.ShowWrong ('# content', "Enter Introduction", "plus_c ");
- Tiny_mce_check.isinfo = false;
- Return false;
- }
- Tiny_mce_check.isinfo = 1;
- Tiny_mce_check.ShowWrong ('# content', '', 'PW _ success ');
- }
- }
From the above function, we can see that the parameter event is an event object. we can judge the current event based on the event object type, that is, event. type. Here, the click event is when we place the mouse focus in the editor, and the keyup event is a keyboard bounce. For specific event object responses, you can use console. log (event) in the Firefox browser console.
The key to front-end js verification combined with tiny mce is the built-in event object in the editor. After finding the key to the problem, you can easily solve the js verification problem!