Hi all,
I’m trying to use a tinyMCE text editor in my Rails app and am having
some problems. I’m trying to load a tinyMCE-enabled form dynamically
as the result of an Ajax call, i.e. I want to insert the form into a
page via Ajax. The Ajax stuff is handled by the Mootools framework.
There’s a few posts about this out there, but none of them seem to
work for me.
The code I have behaves as follows:
Define a function init_mce() to call the tinyMCE.init() function:
function init_mce(){
tinyMCE.idCounter=0;
tinyMCE.init({
mode: “textareas”,
editor_deselector: “no_mce”,
theme: “advanced”,
convert_urls: false,
plugins: “emotions,preview”,
});
}
In the onComplete callback of my ajax request, call init_mce();
The javascript returned from this request does two things:
- Replace the content of a div with a form:
<% remote_form_for :text, :url => some_url, :before =>
“tinyMCE.triggerSave();” do |f| %>
<%= f.text_area :body, :style => “width:100%;height:100%;”, :id =>
“for_mce”, :class => “for_mce” %>
<%= submit_tag “Save” -%>
<% end -%>
- Activate the control and set it to send an ajax request rather than
a normal submit:
$$(’#editor_window form’).each(function(elem)
{elem.addEvent(‘submit’,function(e){e=new
Event(e);tinyMCE.triggerSave();this.send();e.stop();}) });
$$(’#editor_window textarea’).each(function(elem)
{tinyMCE.execCommand(‘mceAddControl’,false,elem.id);});
Sadly, this doesn’t work. Has anyone found a working solution to this?
Many thanks,
Adam