Skip to content

Instantly share code, notes, and snippets.

@valakirka
Created February 24, 2012 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save valakirka/1901998 to your computer and use it in GitHub Desktop.
Save valakirka/1901998 to your computer and use it in GitHub Desktop.
CKEDITOR re-configuration from view
def ckeditor_textarea(object, field, options = {})
options = options.dup.symbolize_keys
var = options.delete(:object) if options.key?(:object)
var ||= @template.instance_variable_get("@#{object}")
value = var.send(field.to_sym) if var
value ||= options.delete(:value) || ""
element_id = options.delete(:id) || ckeditor_element_id(object, field, options.delete(:index))
width = options.delete(:width) || '100%'
height = options.delete(:height) || '100%'
textarea_options = { :id => element_id }
textarea_options[:cols] = (options.delete(:cols) || 70).to_i
textarea_options[:rows] = (options.delete(:rows) || 20).to_i
textarea_options[:class] = (options.delete(:class) || 'editor').to_s
textarea_options[:style] = "width:#{width};height:#{height}"
ckeditor_options = {:width => width, :height => height }
ckeditor_options[:language] = (options.delete(:language) || I18n.locale).to_s
ckeditor_options[:toolbar] = options.delete(:toolbar) if options[:toolbar]
ckeditor_options[:skin] = options.delete(:skin) if options[:skin]
ckeditor_options[:swf_params] = options.delete(:swf_params) if options[:swf_params]
ckeditor_options[:filebrowserBrowseUrl] = Ckeditor.file_manager_uri
ckeditor_options[:filebrowserUploadUrl] = Ckeditor.file_manager_upload_uri
ckeditor_options[:filebrowserImageBrowseUrl] = Ckeditor.file_manager_image_uri
ckeditor_options[:filebrowserImageUploadUrl] = Ckeditor.file_manager_image_upload_uri
output_buffer = ActiveSupport::SafeBuffer.new
output_buffer << ActionView::Base::InstanceTag.new(object, field, self, var).to_text_area_tag(textarea_options.merge(options))
output_buffer << javascript_tag("if (CKEDITOR.instances['#{element_id}']) {
CKEDITOR.remove(CKEDITOR.instances['#{element_id}']);}
CKEDITOR.replace('#{element_id}', { #{ckeditor_applay_options(ckeditor_options)} });")
output_buffer
end
<script type="text/javascript">
//<![CDATA[
CKEDITOR.replace( 'editorWadus', { fullPage : true });
//]]>
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment