Tiny mce event processing in Rich Text Editor

Source: Internet
Author: User

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:

 
 
  1. tinyMCE.init({  
  2.     mode : "exact",  
  3.     theme : "mytheme",  
  4.     language : "se",  
  5.     elements : "elm1,elm2",  
  6.     handle_event_callback : 'eventHandle',  
  7. }); 

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.

 
 
  1. Function eventHandle (event)
  2. {
  3. If (event. type = 'click' | event. type = 'keyup '){
  4. Var cur_html = tinyMCE. get ('content'). getContent ();
  5. If (! Cur_html ){
  6. Tiny_mce_check.ShowWrong ('# content', "Enter Introduction", "plus_c ");
  7. Tiny_mce_check.isinfo = false;
  8. Return false;
  9. }
  10. Tiny_mce_check.isinfo = 1;
  11. Tiny_mce_check.ShowWrong ('# content', '', 'PW _ success ');
  12. }
  13. }

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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.