Skip to content

Commit

Permalink
Merge branch 'elkelk-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
meltingice committed Dec 15, 2012
2 parents 006324e + 8ffd452 commit f9b80a3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
12 changes: 8 additions & 4 deletions lib/ajax-chosen.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/ajax-chosen.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions src/ajax-chosen.coffee
Expand Up @@ -78,14 +78,14 @@ do ($ = jQuery) ->
# ones that have not been selected by the user. For those selected
# by the user, add them to a list to filter from the results later.
selected_values = []
select.find('optgroup').each ->
$(@).remove()

select.find('option').each ->
if not $(@).is(":selected")
$(@).remove()
$(@).remove()
else
selected_values.push $(@).val() + "-" + $(@).text()
select.find('optgroup:empty').each ->
$(@).remove()


# Send the ajax results to the user callback so we can get an object of
# value => text pairs to inject as <option> elements.
Expand All @@ -95,8 +95,10 @@ do ($ = jQuery) ->
# the DOM if it doesn't exist in the selector already
$.each items, (value, element) ->
if element.group
group = $("<optgroup />")
.attr('label', element.text)
group = select.find("optgroup[label='#{element.text}']")
group = $("<optgroup />") unless group.size()

group.attr('label', element.text)
.appendTo(select)
$.each element.items, (value, text) ->
if $.inArray(value + "-" + text, selected_values) == -1
Expand Down

0 comments on commit f9b80a3

Please sign in to comment.