Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modals width variations (large/small/medium) not working?!?! #728

Closed
coppolaf opened this issue Apr 18, 2014 · 3 comments
Closed

modals width variations (large/small/medium) not working?!?! #728

coppolaf opened this issue Apr 18, 2014 · 3 comments

Comments

@coppolaf
Copy link

having issue with modals width variations...
seems the helper is not setting class correctly??
javascript will process the class settings accordingly with the width set??
available to try helping in solving this issue (i think related to latest 3.x bootstrap framework).....

waiting your comments/suggestions

@coppolaf coppolaf changed the title modals variations (large/small/medium) not working?!?! modals width variations (large/small/medium) not working?!?! Apr 18, 2014
@coppolaf
Copy link
Author

i've investigated the issue...

here is my implementation:
i've modified the code that defines the modal-dialog element, making it add to the object's class the option passed as parm 'size' (see below)

modal_helper.rb -->
......
#modals have a header, a body, a footer for options.
def modal_dialog(options = {}, &block)
content_tag :div, :id => options[:id], :class => "modal fade" do
content_tag :div, :class => "modal-dialog " + options[:size] do
content_tag :div, :class => "modal-content" do
modal_header(options[:header]) +
modal_body(options[:body]) +
modal_footer(options[:footer])
end
end
end
end
.......

using this modded helper,
when i declare the modal within my view:

<%= modal_dialog :id => "modal", :size => "modal-lg",
:header => { :show_close => true, :dismiss => 'modal', :title => 'Modal header' },
:body => 'This is the body',
:footer => content_tag(:button, 'Save', :class => 'btn') %>

the optional param ":size" correctly assigns the modal-lg or modal-sm class to the object and resizes the modal window accordingly to bootstrap 3 specs!!

hoping to be helpful,
regards....

francesco

@coppolaf
Copy link
Author

ok....
i think my situation may be strange?!?!
well',
i'm using some modals, for my needings i use inject the content of the modals divs using javascript, so i need to use the divs ids too....
i've revised the modal_helper.rb.... (actually it performs like previous version with some functions added)
you may define the modal as follows:

    <%= modal_dialog :id => "my_modal_id", :size => "modal-lg" 
      :header => { :show_close => true, :dismiss => 'modal', :title => 'Modal Title' },    
      :body   => { :content =>'', :style => 'height:180px;'},
      :footer => { :content =>''} %>

as you see: we can now set a modal ":id", the the header will have id equal to ":id"with the suffix "-header", the body will have suffix "-body" and the foot part "-footer";
we can specify a modal width according with bootstrap 3 specs (using "modal-sm", "modal-md" or "modal-lg" keywords);
we can pass a style to the modal body to force its height and appearance of scrolls.....

hoping to be helpful....
sure some gurus may refine my coding, cleaning it up and making it more efficient!!

here is my version of modal_helper.rb:

module ModalHelper

  #modals have a header, a body, a footer for options.
  def modal_dialog(options = {}, &block)
    content_tag :div, :id => options[:id], :class => "modal fade" do
      content_tag :div, :class => "modal-dialog " + (!options[:size].nil? ? options[:size] : '') do
        content_tag :div, :class => "modal-content" do
          modal_header(options[:header].merge(:id => options[:id])) +
          modal_body(options[:body].merge(:id => options[:id])) +
          modal_footer(options[:footer].merge(:id => options[:id]))
        end
      end
    end
  end

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

  def modal_body(options = {}, &block)
    content_tag :div, options[:content], :class => 'modal-body', :id => options[:id]+"-body", :style => options[:style], &block
  end

  def modal_footer(options = {}, &block)
    content_tag :div, options[:content], :class => 'modal-footer', :id => options[:id]+"-footer", &block
  end

  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

  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)

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

  def modal_cancel_button content, options = {}
    default_options = { :class => "btn bootstrap-modal-cancel-button" }

    content_tag_string "a", content, default_options.merge(options)
  end

end

regards,
francesco

@toadkicker
Copy link
Contributor

FWIW I updated the readme on the 3.1.1 branch as this will require people to add a content: attribute

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants