@@ -182,29 +182,41 @@ if(jQuery) (function($) {
182
182
var getOptions = function ( select , type ) {
183
183
var options ;
184
184
185
+ // Private function to handle recursion in the getOptions function.
186
+ var _getOptions = function ( select , options ) {
187
+ // Loop through the set in order of element children.
188
+ select . children ( 'OPTION, OPTGROUP' ) . each ( function ( ) {
189
+ // If the element is an option, add it to the list.
190
+ if ( $ ( this ) . is ( 'OPTION' ) ) {
191
+ // Check for a value in the option found.
192
+ if ( $ ( this ) . length > 0 ) {
193
+ // Create an option form the found element.
194
+ generateOptions ( $ ( this ) , options ) ;
195
+ }
196
+ else {
197
+ // No option information found, so add an empty.
198
+ options . append ( '<li>\u00A0</li>' ) ;
199
+ }
200
+ }
201
+ else {
202
+ // If the element is an option group, add the group and call this function on it.
203
+ var optgroup = $ ( '<li class="selectBox-optgroup" />' ) ;
204
+ optgroup . text ( $ ( this ) . attr ( 'label' ) ) ;
205
+ options . append ( optgroup ) ;
206
+ options = _getOptions ( $ ( this ) , options ) ;
207
+ }
208
+ } ) ;
209
+ // Return the built string.
210
+ return options ;
211
+ }
212
+
185
213
switch ( type ) {
186
214
187
215
case 'inline' :
188
216
189
-
190
217
options = $ ( '<ul class="selectBox-options" />' ) ;
191
-
192
- if ( select . find ( 'OPTGROUP' ) . length ) {
193
-
194
- select . find ( 'OPTGROUP' ) . each ( function ( ) {
195
-
196
- var optgroup = $ ( '<li class="selectBox-optgroup" />' ) ;
197
- optgroup . text ( $ ( this ) . attr ( 'label' ) ) ;
198
- options . append ( optgroup ) ;
199
-
200
- generateOptions ( $ ( this ) . find ( 'OPTION' ) , options ) ;
201
-
202
- } ) ;
203
-
204
- } else {
205
- generateOptions ( select . find ( 'OPTION' ) , options ) ;
206
- }
207
-
218
+ options = _getOptions ( select , options ) ;
219
+
208
220
options
209
221
. find ( 'A' )
210
222
. bind ( 'mouseover.selectBox' , function ( event ) {
@@ -228,27 +240,7 @@ if(jQuery) (function($) {
228
240
229
241
case 'dropdown' :
230
242
options = $ ( '<ul class="selectBox-dropdown-menu selectBox-options" />' ) ;
231
-
232
- if ( select . find ( 'OPTGROUP' ) . length ) {
233
-
234
- select . find ( 'OPTGROUP' ) . each ( function ( ) {
235
-
236
- var optgroup = $ ( '<li class="selectBox-optgroup" />' ) ;
237
- optgroup . text ( $ ( this ) . attr ( 'label' ) ) ;
238
- options . append ( optgroup ) ;
239
- generateOptions ( $ ( this ) . find ( 'OPTION' ) , options ) ;
240
-
241
- } ) ;
242
-
243
- } else {
244
-
245
- if ( select . find ( 'OPTION' ) . length > 0 ) {
246
- generateOptions ( select . find ( 'OPTION' ) , options ) ;
247
- } else {
248
- options . append ( '<li>\u00A0</li>' ) ;
249
- }
250
-
251
- }
243
+ options = _getOptions ( select , options ) ;
252
244
253
245
options
254
246
. data ( 'selectBox-select' , select )
@@ -816,19 +808,16 @@ if(jQuery) (function($) {
816
808
} ) ;
817
809
} ;
818
810
819
- var generateOptions = function ( originalOptions , options ) {
820
- originalOptions . each ( function ( ) {
821
- var self = $ ( this ) ;
822
- var li = $ ( '<li />' ) ,
823
- a = $ ( '<a />' ) ;
824
- li . addClass ( self . attr ( 'class' ) ) ;
825
- li . data ( self . data ( ) ) ;
826
- a . attr ( 'rel' , self . val ( ) ) . text ( self . text ( ) ) ;
827
- li . append ( a ) ;
828
- if ( self . attr ( 'disabled' ) ) li . addClass ( 'selectBox-disabled' ) ;
829
- if ( self . attr ( 'selected' ) ) li . addClass ( 'selectBox-selected' ) ;
830
- options . append ( li ) ;
831
- } ) ;
811
+ var generateOptions = function ( self , options ) {
812
+ var li = $ ( '<li />' ) ,
813
+ a = $ ( '<a />' ) ;
814
+ li . addClass ( self . attr ( 'class' ) ) ;
815
+ li . data ( self . data ( ) ) ;
816
+ a . attr ( 'rel' , self . val ( ) ) . text ( self . text ( ) ) ;
817
+ li . append ( a ) ;
818
+ if ( self . attr ( 'disabled' ) ) li . addClass ( 'selectBox-disabled' ) ;
819
+ if ( self . attr ( 'selected' ) ) li . addClass ( 'selectBox-selected' ) ;
820
+ options . append ( li ) ;
832
821
} ;
833
822
834
823
//
0 commit comments