@@ -135,7 +135,7 @@ $.fn.fancySelect = (opts = {}) ->
135
135
136
136
# Handle item selection, and
137
137
# Add class selected to selected item
138
- options .on ' click' , ' li' , (e ) ->
138
+ options .on ' click' , ' li.option ' , (e ) ->
139
139
sel .val ($ (this ).data (' value' ))
140
140
141
141
sel .trigger (' blur' ).trigger (' focus' ) unless isiOS
@@ -144,37 +144,32 @@ $.fn.fancySelect = (opts = {}) ->
144
144
$ (e .currentTarget ).addClass ' selected'
145
145
return sel .val ($ (this ).data (' value' )).trigger (' change' ).trigger (' blur' ).trigger (' focus' )
146
146
147
- # handle mouse selection
148
- options .on ' mouseenter' , ' li' , ->
149
- nowHovered = $ (this )
150
- hovered = options .find (' .hover' )
151
- hovered .removeClass ' hover'
152
-
153
- nowHovered .addClass ' hover'
154
-
155
- options .on ' mouseleave' , ' li' , ->
156
- options .find (' .hover' ).removeClass (' hover' )
157
-
158
147
copyOptionsToList = ->
159
148
# update our trigger to reflect the select (it really already should, this is just a safety)
160
149
updateTriggerText ()
161
150
162
151
return if isiOS && ! settings .forceiOS
163
152
164
- # snag current options before we add a default one
165
- selOpts = sel .find ' option'
166
-
167
- # generate list of options for the fancySelect
168
-
169
- sel .find (' option' ).each (i, opt) ->
153
+ sel .children ().each (i, opt) ->
170
154
opt = $ (opt)
155
+ if opt .is (' option' )
156
+ createLiFromOption opt, options
157
+ else if opt .is (' optgroup' )
158
+ optgroup = opt
159
+ options .append " <li class='optgroup'><span class='optgroup-label'>#{ optgroup .prop ' label' } </span><ul id=optgroup_#{ i} >"
160
+ ul = $ (" #optgroup_#{ i} " )
161
+ optgroup .children ().each (i, nested_opt) ->
162
+ nested_opt = $ (nested_opt)
163
+ createLiFromOption nested_opt, ul
164
+
165
+ createLiFromOption = (opt , parent ) ->
166
+ if ! opt .prop (' disabled' ) && (opt .val () || settings .includeBlank )
167
+ # Is there a select option on page load?
168
+ if opt .prop (' selected' )
169
+ parent .append " <li data-value='#{ opt .val ()} ' class='option selected'>#{ opt .text ()} </li>"
170
+ else
171
+ parent .append " <li data-value='#{ opt .val ()} ' class='option'>#{ opt .text ()} </li>"
171
172
172
- if ! opt .prop (' disabled' ) && (opt .val () || settings .includeBlank )
173
- # Is there a select option on page load?
174
- if opt .prop (' selected' )
175
- options .append " <li data-value=\" #{ opt .val ()} \" class=\" selected\" >#{ opt .text ()} </li>"
176
- else
177
- options .append " <li data-value=\" #{ opt .val ()} \" >#{ opt .text ()} </li>"
178
173
179
174
# for updating the list of options after initialization
180
175
sel .on ' update' , ->
0 commit comments