def fckeditor_textarea_tag(name, content = nil, options = {})
id = options[:id].blank? ? name : options[:id]
cols = options[:cols].nil? ? '' : "cols='" + options[:cols] + "'"
rows = options[:rows].nil? ? '' : "rows='" + options[:rows] + "'"
width = options[:width].nil? ? '100%' : options[:width]
height = options[:height].nil? ? '100%' : options[:height]
toolbarSet = options[:toolbarSet].nil? ? 'Default' : options[:toolbarSet]
if options[:ajax]
inputs = "<input type='hidden' id='#{id}_hidden' name='#{name}'>\n" +
"<textarea id='#{id}' #{cols} #{rows} name='#{id}'>#{content}</textarea>\n"
else
inputs = "<textarea id='#{id}' #{cols} #{rows} name='#{name}'>#{content}</textarea>\n"
end
base_path = request.relative_url_root.to_s + '/javascripts/fckeditor/'
inputs +
javascript_tag( "var oFCKeditor = new FCKeditor('#{id}', '#{width}', '#{height}', '#{toolbarSet}');\n" +
"oFCKeditor.BasePath = \"#{base_path}\"\n" +
"oFCKeditor.Config['CustomConfigurationsPath'] = '../../fckcustom.js';\n" +
"oFCKeditor.ReplaceTextarea();\n")
end
I’ve based this on the fckeditor_textarea helper code so there is some duplication that could be removed if the tag helper was added to the plugin.
All you need to do is put the above code in your application helper and it can then be used in templates much like the Rails text_area_tag helper:
fckeditor_textarea_tag 'text_area_name', h('text_area_content'), :id => 'text_area_id', :cols => '55', :rows => '15'
If you’re using an Ajax based form then you won’t be able to use the fckeditor_before_js helper. You should be able to use this JavaScript, passed as the :before option to form_remote_tag, instead:
var oEditor = FCKeditorAPI.GetInstance('text_area_id');
$('text_area_id_hidden').value = oEditor.GetXHTML();"
Where text_area_id is the ID you used in the fckeditor_textarea_tag call.


11 comments
Comment on FCKEditor tag helper by Scott
November 23rd, 2007 @ 21:05 – permalink
Comment on FCKEditor tag helper by Rob
November 25th, 2007 @ 16:00 – permalink
Comment on FCKEditor tag helper by jimmy
November 26th, 2007 @ 21:23 – permalink
Comment on FCKEditor tag helper by Rob
November 27th, 2007 @ 18:42 – permalink
Comment on FCKEditor tag helper by jimmy
November 28th, 2007 @ 20:26 – permalink
Comment on FCKEditor tag helper by Rob
December 1st, 2007 @ 19:07 – permalink
Comment on FCKEditor tag helper by Jimmy
December 3rd, 2007 @ 20:30 – permalink
Comment on FCKEditor tag helper by Rob
December 4th, 2007 @ 08:30 – permalink
Comment on FCKEditor tag helper by Jon
May 15th, 2008 @ 08:25 – permalink
Comment on FCKEditor tag helper by Rob Anderton
May 17th, 2008 @ 18:39 – permalink
Comment on FCKEditor tag helper by abhishek
September 22nd, 2008 @ 11:31 – permalink
Leave a reply
You can use Markdown in your comment as well as plain HTML. You can use
<filter:jscode lang="ruby">and</filter:jscode>tags to surround code blocks (supported languages are css, html, javascript and ruby). Your email address will not be published.If your comment doesn’t appear immediately after posting it could have been marked as spam. Don’t worry: we regularly check for and approve incorrectly filtered comments so you shouldn’t have to wait too long for it to be shown.