Skip to content

Commit

Permalink
Merge pull request #1326 from ahhrrr/wysihtml5-config
Browse files Browse the repository at this point in the history
Add configuration to wysihtml5 widget

Conflicts:
	app/assets/javascripts/rails_admin/ra.widgets.coffee
  • Loading branch information
bbenezech committed Oct 12, 2012
2 parents f51ca98 + d883601 commit 991ed59
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
9 changes: 5 additions & 4 deletions app/assets/javascripts/rails_admin/ra.widgets.coffee
Expand Up @@ -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 { stylesheets: false }
$(@).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)
3 changes: 2 additions & 1 deletion app/views/rails_admin/main/_form_text.html.haml
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions lib/rails_admin/config/fields/types/text.rb
Expand Up @@ -65,6 +65,13 @@ class Text < RailsAdmin::Config::Fields::Base
false
end

# If you want to have a different toolbar configuration for wysihtml5
# you can use a Ruby hash to configure these options:
# https://github.com/jhollingworth/bootstrap-wysihtml5/#advanced
register_instance_option(:bootstrap_wysihtml5_config_options) do
nil
end

register_instance_option(:bootstrap_wysihtml5_css_location) do
'/assets/bootstrap-wysihtml5.css'
end
Expand Down
16 changes: 16 additions & 0 deletions spec/integration/config/edit/rails_admin_config_edit_spec.rb
Expand Up @@ -793,6 +793,22 @@ class HelpTest < Tableless
visit new_path(:model_name => "draft")
should have_selector('textarea#draft_notes[data-richtext="bootstrap-wysihtml5"]')
end

it "should include custom wysihtml5 configuration" do
RailsAdmin.config Draft do
edit do
field :notes do
bootstrap_wysihtml5 true
bootstrap_wysihtml5_config_options :image => false
bootstrap_wysihtml5_css_location 'stub_css.css'
bootstrap_wysihtml5_js_location 'stub_js.js'
end
end
end

visit new_path(:model_name => "draft")
should have_selector("textarea#draft_notes[data-richtext=\"bootstrap-wysihtml5\"][data-options]")
end
end

describe "Paperclip Support" do
Expand Down

0 comments on commit 991ed59

Please sign in to comment.