Support » Plugins and Hacks » How to hook into WYSIWYG/HTML (TinyMCE)

  • digitaldonkey

    (@digitaldonkey)


    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?

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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]);
    }

    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]);
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to hook into WYSIWYG/HTML (TinyMCE)’ is closed to new replies.