views:

118

answers:

1

The problem occurs when I try to create small plugin to allow me toggle on and off WYSIWYG on all textareas in the website.

//$('form.default textarea').each(function(){
// console.log( $('<a href="#">Enable  WYSIWYG editor</a>').insertAfter('form.default textarea').prev('textarea.wysiwyg').tinymce().hide() );
//});

The full (a bit simplified) code looks like this:

$('textarea.wysiwyg').tinymce({
  skin : 'cirkuit',
  theme : 'advanced',
  plugins : 'pagebreak,style,layer,advlink,inlinepopups,contextmenu,paste,directionality,noneditable,nonbreaking,xhtmlxtras,template',
  // Theme options
  theme_advanced_buttons1 : 'formatselect,fontsizeselect,forecolor,|,bold,italic,strikethrough,|,bullist,numlist,|,justifyleft,justifycenter,justifyright,|,link,unlink,|,image,|,code,paste,pastetext,pasteword,removeformat,|,backcolor,|,underline,justifyfull,sup,|,outdent,indent,|,hr,charmap,|,undo,redo',
  theme_advanced_buttons2 : '',
  theme_advanced_buttons3 : '',
  theme_advanced_toolbar_location : 'top',
  theme_advanced_toolbar_align : 'left',
  theme_advanced_statusbar_location: 'bottom',
  theme_advanced_resizing : true,
  theme_advanced_resize_horizontal : false,
  height : 500,
  theme_advanced_resizing_min_height : 500,
  document_base_url : 'http://static.&lt;?=$settings['system_host']?&gt;/'
 });

 $('textarea.wysiwyg').each(function() {
  $(this).tinymce().hide();
 });

What is the error? FireBug says that tinymce() in undefined; this message occurs in each() loop. Thus, tinymce() is actually initialized.

I am really lost towards, what could be causing this.

A: 

Here is a toggle function like you are looking for from: http://tinymce.moxiecode.com/punbb/viewtopic.php?id=436

var tinyMCEmode = true;
function toogleEditorMode(sEditorID) {
    try {
        if(tinyMCEmode) {
            tinyMCE.removeMCEControl(tinyMCE.getEditorId(sEditorID));
            tinyMCEmode = false;
        } else {
            tinyMCE.addMCEControl(document.getElementById('pagecontent'), sEditorID);
            tinyMCEmode = true;
        }
    } catch(e) {
        //error handling
    }
}

To use:

<a href="#" title="toogle TinyMCE" onclick="toogleEditorMode('pagecontent');">Toogle TinyMCE</a>

I suspect your problem is using jQuery to do this when tinyMCE uses its own JavaScript library. It evidently does not like hide. I would use something like the example given as we know it works.

Todd Moses