Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TinyMCE plugin get reference to the original textarea

Tags:

jquery

tinymce

The Setup

Many TinyMCE editors, displayed in jQuery tabs, each editor is for a specific language.

The problem

I need a plugin with a button, that when pressed will retrieve some html (via ajax) based on the language of the textbox. The best ideea I could come up with is to put am attribute on the textarea containing the language and then in the plugin, get the value of the attribute and based on that make the ajax request to the right url.

The question

How do I get a reference to the original textarea from inside the TinyMCE plugin.

Any info/reference is welcomed... I find the TinyMCE API page really hard to follow.

like image 730
Dan F. Avatar asked Oct 04 '11 13:10

Dan F.


People also ask

How do I get content from TinyMCE textarea?

You can do this using the getContent() API method. Let's say you have initialized the editor on a textarea with id=”myTextarea”. This will return the content in the editor marked up as HTML.

What is TinyMCE selector?

Selector engine, enables you to select controls by using CSS like expressions. We currently only support basic CSS expressions to reduce the size of the core and the ones we support should be enough for most cases.

How do I save HTML content of TinyMCE into a file?

Hello, To save the page, you have to insert TinyMCE in a HTML form and add a submit button. Then you'll have to handle the submitted form with a language like PHP. A call to the file_put_contents() function should do it.


1 Answers

Try

tinyMCE.get(editorId).getElement();

This will return the textarea element that got replaced by TinyMCE - see the docs.

For your specific needs, if you need to target a certain editor with your externally fetched data, simply loop through all editor instances and select the right one by id or name attribute.

for (editorId in tinyMCE.editors) {
  var orig_element = $(tinyMCE.get(editorId).getElement());
  var name = orig_element.attr('name');
  if (name === 'my_field_name') {
    // do your stuff here
  }
}
like image 153
András Szepesházi Avatar answered Sep 19 '22 18:09

András Szepesházi