Module: Railsstrap::ModalHelper

Defined in:
app/helpers/railsstrap/modal_helper.rb

Instance Method Summary collapse

Instance Method Details

#close_button(dismiss) ⇒ Object



41
42
43
44
# File 'app/helpers/railsstrap/modal_helper.rb', line 41

def close_button(dismiss)
  #It doesn't seem to like content_tag, so we do this instead.
  raw("<button class=\"close\" data-dismiss=\"#{dismiss}\" aria-hidden=\"true\">&times;</button>")
end

#default_optionsObject



4
5
6
# File 'app/helpers/railsstrap/modal_helper.rb', line 4

def default_options
  return {:id => 'modal', :size => '', :show_close => true, :dismiss => true}
end


33
34
35
# File 'app/helpers/railsstrap/modal_helper.rb', line 33

def modal_body(options, &block)
   :div, options[:content], :class => 'modal-body', :style => options[:style], &block
end


58
59
60
61
62
# File 'app/helpers/railsstrap/modal_helper.rb', line 58

def modal_cancel_button(content, options)
  default_opts = { :class => "btn railsstrap-modal-cancel-button" }

   "a", content, default_opts.merge(options)
end

modals have a header, a body, a footer for options.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/helpers/railsstrap/modal_helper.rb', line 9

def modal_dialog(options = {}, &block)
  opts = default_options.merge(options)
   :div, :id => options[:id], :class => "railsstrap-modal modal fade" do
     :div, :class => "modal-dialog #{opts['size']}" do
       :div, :class => "modal-content" do
        modal_header(options[:header], &block) +
        modal_body(options[:body], &block) +
        modal_footer(options[:footer], &block)
      end
    end
  end
end


37
38
39
# File 'app/helpers/railsstrap/modal_helper.rb', line 37

def modal_footer(options, &block)
   :div, options[:content], :class => 'modal-footer', &block
end


22
23
24
25
26
27
28
29
30
31
# File 'app/helpers/railsstrap/modal_helper.rb', line 22

def modal_header(options, &block)
   :div, :class => 'modal-header' do
    if options[:show_close]
      close_button(options[:dismiss]) +
      (:h4, options[:title], :class => 'modal-title', &block)
    else
      (:h4, options[:title], :class => 'modal-title', &block)
    end
  end
end


46
47
48
49
50
51
52
53
54
55
56
# File 'app/helpers/railsstrap/modal_helper.rb', line 46

def modal_toggle(content_or_options = nil, options, &block)
  if block_given?
    options = content_or_options if content_or_options.is_a?(Hash)
    default_options = { :class => 'btn btn-default', "data-toggle" => "modal", "href" => options[:dialog] }.merge(options)

     :a, nil, default_options, true, &block
  else
    default_options = { :class => 'btn btn-default', "data-toggle" => "modal", "href" => options[:dialog] }.merge(options)
     :a, content_or_options, default_options, true
  end
end