WordPress.org

Ready to get started?Download WordPress

Forums

How to hook into WYSIWYG/HTML (TinyMCE) (3 posts)

  1. digitaldonkey
    Member
    Posted 3 years ago #

    I order to do some tag/image processing I need to parse the TinyMCE Editor content.

    One javascript function should run switching WYSIWYG->HTML view the second HTML->WYSIWYG.

    BUT: Also on loading the content (start editing/opening the backend) into WYSIWYG or HTML the right function needs to be called.

    I'm really despaired on this issue playing around with the onBeforeSetContent, onPostProcess ... hooks of TinyMce.

    Anyone know how TinyMCE is organized in te backend?

  2. kitchin
    Member
    Posted 2 years ago #

    Try doing it outside of TinyMCE. The HTML view is a normal textarea, while the TinyMCE editor is within an iframe. This code is working for me (only tested in Firefox so far). It inserts a shortcode when editing a post (the surrounding code uses add_meta_box()). I am assuming jQuery is always loaded.

    var chtml= jQuery('#content-html');
    var ctmce= jQuery('#content-tmce');
    var htmlmode= chtml.hasClass('html-active');
    if (!htmlmode) {
    	switchEditors.switchto(chtml[0]); // [0] to get DOM element out of jQuery object
    }
    var c= jQuery('#content'); // textarea
    var ctext= '[newshortcode] ' + c.val();
    c.val(ctext);
    if (!htmlmode) {
    	switchEditors.switchto(ctmce[0]);
    }
  3. kitchin
    Member
    Posted 2 years ago #

    The test in line 3 is mistaken. Corrected code:

    var chtml= jQuery('#content-html');
    var ctmce= jQuery('#content-tmce');
    var c= jQuery('#content'); // textarea
    var vismode= c.css('display')=='none';
    if (vismode) {
    	switchEditors.switchto(chtml[0]); // [0] to get DOM element out of jQuery object
    }
    var ctext= '[newshortcode] ' + c.val();
    c.val(ctext);
    if (vismode) {
    	switchEditors.switchto(ctmce[0]);
    }

Topic Closed

This topic has been closed to new replies.

About this Topic