Skip to content
Browse files

Add configuration options for wysihtml5 text editor.

  • Loading branch information...
1 parent f20879f commit c9fcdb241fb98b4e0483d27d4876275cd044d248 @ahhrrr committed
View
9 app/assets/javascripts/rails_admin/ra.widgets.coffee
@@ -191,19 +191,20 @@ $(document).live 'rails_admin.dom_ready', ->
# bootstrap_wysihtml5
- goBootstrapWysihtml5s = (array) =>
+ goBootstrapWysihtml5s = (array, config_options) =>
array.each ->
$(@).addClass('bootstrap-wysihtml5ed')
$(@).closest('.controls').addClass('well')
- $(@).wysihtml5()
+ $(@).wysihtml5(config_options)
array = $('form [data-richtext=bootstrap-wysihtml5]').not('.bootstrap-wysihtml5ed')
if array.length
@array = array
if not window.wysihtml5
options = $(array[0]).data('options')
+ config_options = $.parseJSON(options['config_options'])
$('head').append('<link href="' + options['csspath'] + '" rel="stylesheet" media="all" type="text\/css">')
$.getScript options['jspath'], (script, textStatus, jqXHR) =>
- goBootstrapWysihtml5s(@array)
+ goBootstrapWysihtml5s(@array, config_options)
else
- goBootstrapWysihtml5s(@array)
+ goBootstrapWysihtml5s(@array, config_options)
View
3 app/views/rails_admin/main/_form_text.html.haml
@@ -20,7 +20,8 @@
richtext = 'bootstrap-wysihtml5'
js_data = {
:csspath => field.bootstrap_wysihtml5_css_location,
- :jspath => field.bootstrap_wysihtml5_js_location
+ :jspath => field.bootstrap_wysihtml5_js_location,
+ :config_options => field.bootstrap_wysihtml5_config_options.to_json
}
else
richtext = false
View
6 lib/rails_admin/config/fields/types/text.rb
@@ -65,6 +65,12 @@ class Text < RailsAdmin::Config::Fields::Base
false
end
+ # If you want to have a different toolbar configuration for wysihtml5
+ # create your own custom config.js and override this configuration
+ register_instance_option(:bootstrap_wysihtml5_config_options) do
+ nil
+ end
+
register_instance_option(:bootstrap_wysihtml5_css_location) do
'/assets/bootstrap-wysihtml5.css'
end
View
15 spec/integration/config/edit/rails_admin_config_edit_spec.rb
@@ -793,6 +793,21 @@ class HelpTest < Tableless
visit new_path(:model_name => "draft")
should have_selector('textarea#draft_notes[data-richtext="bootstrap-wysihtml5"]')
end
+
+ it "should allow custom wysihtml5 configuration" do
+ RailsAdmin.config Draft do
+ edit do
+ field :notes do
+ bootstrap_wysihtml5 true
+ bootstrap_wysihtml5_config_options :image => false
+ end
+ end
+ end
+
+ visit new_path(:model_name => "draft")
+ should have_selector('a.btn[data-wysihtml5-command="bold"]') #Shown by default
+ should_not have_selector('a.btn[data-wysihtml5-command="insertImage"]')
+ end
end
describe "Paperclip Support" do

0 comments on commit c9fcdb2

Please sign in to comment.
Something went wrong with that request. Please try again.