4
votes

I'm using tinymce jquery plugin and trying to access the api after initializing an instance of tinymce over a textarea.

In this example, I have a hide button, which when clicked on is supposed to hide the tinymce editor, but instead I get an error.

<html>
<head>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
    <script type="text/javascript" src="js/tinymce/jquery.tinymce.js"></script>
    <script type="text/javascript" src="js/test.js"></script>
</head>

<body>
    <div><textarea id="textEditor" class="tinymce" disabled="disabled"></textarea></div>
    <input type ="button" id="hide" value="Hide tinymce">
</body>
</html>
$(document).ready(function(){

//textEditor
$("#textEditor")
.tinymce({
    // Location of TinyMCE script
    script_url : 'js/tinymce/tiny_mce.js',
    theme : "advanced",
    theme_advanced_buttons1 : "bold,italic,underline,",
    theme_advanced_resizing : false
})

//... see below ...//

});

Update: I have 2 versions now, one that works by wrapping the $("#textEditor").tinymce().hide(); line in a click function, and one that gives me tinyMCE not defined with just the line itself.

Works:

$("#hide").click(function(){
    $("#textEditor").tinymce().hide(); 
})

Doesn't work:

    $("#textEditor").tinymce().hide(); //error tinyMCE is not defined
2

2 Answers

4
votes

You could try

tinymce.get("textEditor").hide();

To verify if you are useing the correct tinymce id can alert all tinymce ids present at your page using

for (var i = 0; i < tinymce.editors.length; i++) {
   alert(tinymce.editors[i].id);
}

EDIT:

This:

/** Option Block A error **/    
 // $("#textEditor").tinymce().hide(); //error tinyMCE is not defined
/** Option Block A error **/ 

does not work because it will get called before the tinymce editor is initialized. At this point there is no tinymce.get("textEditor").

1
votes

I think that the path to your jquery plugin is not correct, because, the $.tinymce() method is provided there. If the file is not to be found, so is this method.

Also you should ensure that the path specified inside the *script_url* field is valid, as the plugin will try to load it on the fly.