开发者

TinyMCE plugin get reference to the original textarea

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 retrie开发者_运维技巧ve 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.


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
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜