Update Bootstrap to v4.1, fix chosen.js and pagedown on multiple sites
This commit is contained in:
42
app/helpers/pagedown_form_builder.rb
Normal file
42
app/helpers/pagedown_form_builder.rb
Normal file
@ -0,0 +1,42 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class PagedownFormBuilder < ActionView::Helpers::FormBuilder
|
||||
def pagedown(method, args)
|
||||
# Adopt simple form builder to work with form_for
|
||||
@attribute_name = method
|
||||
@input_html_options = args[:input_html]
|
||||
|
||||
@template.capture do
|
||||
@template.concat wmd_button_bar
|
||||
@template.concat wmd_textarea
|
||||
@template.concat wmd_preview if show_wmd_preview?
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def wmd_button_bar
|
||||
@template.content_tag :div, nil, id: "wmd-button-bar-#{base_id}"
|
||||
end
|
||||
|
||||
def wmd_textarea
|
||||
@template.text_area @object_name, @attribute_name,
|
||||
**@input_html_options,
|
||||
class: 'form-control wmd-input',
|
||||
id: "wmd-input-#{base_id}"
|
||||
end
|
||||
|
||||
def wmd_preview
|
||||
@template.content_tag :div, nil,
|
||||
class: 'wmd-preview',
|
||||
id: "wmd-preview-#{base_id}"
|
||||
end
|
||||
|
||||
def show_wmd_preview?
|
||||
@input_html_options[:preview].present?
|
||||
end
|
||||
|
||||
def base_id
|
||||
options[:pagedown_id_suffix] || @attribute_name
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user