Jump to Navigation

Making a promiscuous TinyMCE abstain

Here’s a quick one if you are in need of a noon-time distraction. If you’ve ever used the WYSIWYG editor TinyMCE, called “tiny mice” by some, then you know that it likes to hook() up with every <textarea> that it sees.

The results of this promiscuity range from annoying (I don’t need a HTML editor for a log message!) to the disastrous (?*$! That HTML editor just stripped the newlines from my list of pages in “Page specific visibility settings!” Oh, the humanity!)

The fix for this is hinted at in the docs of TinyMCE. You can specify a list of named textareas for TinyMCE to ignore from inside the theme function, phptempate_tinymce_theme(). For each named <textarea>, you can unset the TinyMCE $init. Which is somewhat useful, but everytime you add a new module, you’ll find a new list of <textarea>s that get screwed up.

However, to really control TinyMCE, we can turn that logic on its head. If we use that theme function to specify a list of named <textarea>s that will pass untouched through the function (meaning TinyMCE will hook up with them) and unset the TinyMCE init for all other <textarea>s. Here’s the code:

<?php
/**
 * Theme the TinyMCE module (an implementation of theme_tinymce_theme())
 *
 * @param $init
 * @param $textarea_name
 * @param $theme_name
 * @param $is_running
 * @return
 *   Initialization array.
 */
function phptemplate_tinymce_theme($init, $textarea_name, $theme_name, $is_running) {
  switch (
$textarea_name) {
   
// Enable tinymce for these textareas
   
case 'body':
    case
'comment':
      break;
   
// Disable by default
   
default:
      unset(
$init);
      break;
  }

 
// Always return $init
 
return $init;
}
?>

And voila! TinyMCE will now only hook up with node bodies, block bodies and comments.

Comments

Anonymous's picture

Something similar

Hey I've done something similar, and I notice your code removes the logic in the default theme_tinymce_theme(). You might be better off calling it instead of simply using $init untouched. Here's what I've used...

<?php
/**
* Override theme_tinymce_theme.  This control which textareas have
* the tinymce editor applied to them.  See tinymce module README.TXT
* for more information.
*/
function phptemplate_tinymce_theme($init, $textarea_name, $theme_name, $is_running) {
 
// default theme_tinymce_theme enables tinymce by default, and
  // supresses on certain textareas.  Our implementation disables by
  // default, and allows only on the following textareas.
 
if (in_array($textarea_name, array('body',
                                    
'formnode-data-submit-body',
                                    
'mn-data-header',
                                    
'mn-data-footer',
                                    
'signature',
                                    
'site_mission',
                                    
'site_footer',
                                    
'site_offline_message',
                                    
'page_help',
                                    
'user_registration_help',
                                    
'user_picture_guidelines',
                                     ))) {
   
// Prevent tinymce from mucking up our paths
   
$init['convert_urls'] = 'false';
   
$returnMe = theme_tinymce_theme($init, $textarea_name, $theme_name, $is_running);
    return
$returnMe;
  }
  else
   
// disable tinymce
   
return NULL;
}
?>

I've used tinymce on only one project and don't plan to ever use it again. It has nasty habits like inserting silly <br type="_moz" /> tags.

John's picture

By design

The only logic that theme_tinymce_theme() performs is “Force the 'simple' theme for some of the smaller textareas.” But my function only enables TinyMCE for 3 textareas, and none of them are in that list of “smaller textareas” so its totally unnecessary to call it.

But if anyone is thinking of using the technique I outlined, they should, of course, review the theme_tinymce_theme() code in the tinymce.module file.

Anonymous's picture

Even usually don't use

Even usually don't use tinymce, this could be really nice trick.
Thanks.

Anonymous's picture

Online phoenix student university

Hey. Nice site - pity you have to go to such lengths to moderate it. Help me! Can not find sites on the: Online phoenix student university. I found only this - http://webbgemenskapen.se/Members/OnlineUniversity/acadia-university-acc.... In 2009, the nothing internet period did the online school degree, online university. While associate degrees are a different tuition to ensure, getting your bachelors protects up advantageous degrees to serious commercials, online university. Waiting for a reply :o, Bohdana from Saudi.

Anonymous's picture

Discounted paxil no rx

Excuse me. Oh, I don't blame Congress. If I had $600 billion at my disposal, I'd be irresponsible, too.
I am from United and learning to speak English, please tell me right I wrote the following sentence: "It helps to me including you are on the retention of an sitting year, paxil."

Thanks ;). Quinn.

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account, used to display your avatar.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <code> <del> <ins> <blockquote> <q> <sub> <sup> <ul> <ol> <li> <dl> <dt> <dd>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Lines and paragraphs break automatically.

More information about formatting options