Skip to content

Change the Way Width is Determined #1439

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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions coffee/chosen.jquery.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,9 @@ class Chosen extends AbstractChosen
w = div.width() + 25
div.remove()

f_width = @container.outerWidth()
f_width = @container[0].offsetWidth

if( w > f_width - 10 )
if( f_width && w > f_width - 10 )
w = f_width - 10

@search_field.css({'width': w + 'px'})
4 changes: 2 additions & 2 deletions coffee/chosen.proto.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -492,9 +492,9 @@ class @Chosen extends AbstractChosen
w = Element.measure(div, 'width') + 25
div.remove()

f_width = @container.getWidth()
f_width = @container.offsetWidth

if( w > f_width-10 )
if( f_width && w > f_width-10 )
w = f_width - 10

@search_field.setStyle({'width': w + 'px'})
9 changes: 8 additions & 1 deletion coffee/lib/abstract-chosen.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,14 @@ class AbstractChosen
else this.results_search()

container_width: ->
return if @options.width? then @options.width else "#{@form_field.offsetWidth}px"
return @options.width if @options.width?

if jQuery? and $ is jQuery
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should have jquery-specific code in AbstractChosen. The method should be moved to the different Chosen implementations

return width if width = $(@form_field).css('width')
else
return width if width = @form_field.getStyle('width')

@form_field.offsetWidth

include_option_in_results: (option) ->
return false if @is_multiple and (not @display_selected_options and option.selected)
Expand Down