12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/flash_notifier/flash_helper.rb', line 12
def build_bootstrap_flash *args
options = args
dismissible = options.has_key?(:dismiss) && options[:dismiss]
timeout = options.has_key?(:timeout) ? options[:timeout] : 5000
alert_klasses = {
success: 'alert-success',
error: 'alert-danger',
alert: 'alert-warning',
notice: 'alert-info'
}
html = ''
flash.each do |type, message|
html += content_tag :div, class: "alert #{alert_klasses[type.to_sym] || type.to_s} alert-dismissible fade in show #{options[:wrapper_class]}", role: 'alert', data: {flash_notifier: 'bootstrap'} do
inner_html = link_to 'x', '#', class: 'close', data: {dismiss: 'alert'}, aria_label: 'close', title: 'close'
inner_html += content_tag :div, message, class: 'text'
inner_html.html_safe
end
end
dismiss_alert_script = javascript_tag " setTimeout(function(){\n $.each($(\"[data-flash-notifier='bootstrap']\"), function(index, alert){\n $(alert).alert('close');\n })\n }, \#{timeout});\n JS\n html += dismiss_alert_script if dismissible\n html.html_safe\nend\n"
|