Module: Ckeditor::ViewHelper
- Includes:
- ActionView::Helpers
- Defined in:
- lib/ckeditor/view_helper.rb
Instance Method Summary collapse
- #ckeditor_ajax_script(backend = 'jquery') ⇒ Object
-
#ckeditor_textarea(object, field, options = {}) ⇒ Object
Ckeditor helper: <%= ckeditor_textarea(“object”, “field”, :width => ‘100%’, :height => ‘200px’) %>.
Instance Method Details
#ckeditor_ajax_script(backend = 'jquery') ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/ckeditor/view_helper.rb', line 61 def ckeditor_ajax_script(backend = 'jquery') javascript_tag("$(document).ready(function(){ $('form[data-remote]').bind('ajax:before', function(){ for (instance in CKEDITOR.instances){ CKEDITOR.instances[instance].updateElement(); } }); });") end |
#ckeditor_textarea(object, field, options = {}) ⇒ Object
Ckeditor helper: <%= ckeditor_textarea(“object”, “field”, :width => ‘100%’, :height => ‘200px’) %>
Two forms on one page: <%= form_tag “one” %>
<%= ckeditor_textarea("object", "field", :index => "1") %>
<% end %> … <%= form_tag “two” %>
<%= ckeditor_textarea("object", "field", :index => "2") %>
<% end %>
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ckeditor/view_helper.rb', line 17 def ckeditor_textarea(object, field, = {}) = .dup.symbolize_keys var = .delete(:object) if .key?(:object) var ||= @template.instance_variable_get("@#{object}") value = var.send(field.to_sym) if var value ||= .delete(:value) || "" element_id = .delete(:id) || ckeditor_element_id(object, field, .delete(:index)) width = .delete(:width) || '100%' height = .delete(:height) || '100%' = { :id => element_id } [:cols] = (.delete(:cols) || 70).to_i [:rows] = (.delete(:rows) || 20).to_i [:class] = (.delete(:class) || 'editor').to_s [:style] = "width:#{width};height:#{height}" = {:width => width, :height => height } [:language] = (.delete(:language) || I18n.locale).to_s [:toolbar] = .delete(:toolbar) if [:toolbar] [:skin] = .delete(:skin) if [:skin] [:swf_params] = .delete(:swf_params) if [:swf_params] [:filebrowserBrowseUrl] = Ckeditor.file_manager_uri [:filebrowserUploadUrl] = Ckeditor.file_manager_upload_uri [:filebrowserImageBrowseUrl] = Ckeditor.file_manager_image_uri [: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(.merge()) output_buffer << javascript_tag("if (CKEDITOR.instances['#{element_id}']) { CKEDITOR.remove(CKEDITOR.instances['#{element_id}']);} CKEDITOR.replace('#{element_id}', { #{()} });") output_buffer end |