|
1 | 1 | /*
|
2 | 2 |
|
3 |
| - jQuery selectBox (version 1.0.3) |
| 3 | + jQuery selectBox (version 1.0.4) |
4 | 4 |
|
5 | 5 | A cosmetic, styleable replacement for SELECT elements.
|
6 | 6 |
|
|
87 | 87 | for setting the width
|
88 | 88 | - Added 'control' method for working directly with the selectBox control
|
89 | 89 | v1.0.3 (2011-04-22) - Fixed bug in value method that errored if the control didn't exist
|
| 90 | + v1.0.4 (2011-04-22) - Fixed bug where controls without any options would render with incorrect heights |
90 | 91 |
|
91 | 92 |
|
92 | 93 | Known Issues:
|
@@ -169,24 +170,21 @@ if(jQuery) (function($) {
|
169 | 170 | // Auto-height based on size attribute
|
170 | 171 | if( !select[0].style.height ) {
|
171 | 172 |
|
172 |
| - var size = select.attr('size') ? parseInt(select.attr('size')) : 5, |
173 |
| - optionHeight = parseInt(control.find('.selectBox-options A:first').outerHeight()); |
174 |
| - |
175 |
| - // If the control is invisible, we have to draw a dummy control |
176 |
| - // off-screen, measure the option, and remove it |
177 |
| - if( !select.is(':visible') ) { |
178 |
| - var tmp = control |
179 |
| - .clone() |
180 |
| - .removeAttr('id') |
181 |
| - .css({ |
182 |
| - position: 'absolute', |
183 |
| - top: '-9999em' |
184 |
| - }) |
185 |
| - .show() |
186 |
| - .appendTo('body'); |
187 |
| - optionHeight = parseInt(tmp.find('.selectBox-options A:first').html(' ').outerHeight()); |
188 |
| - tmp.remove(); |
189 |
| - } |
| 173 | + var size = select.attr('size') ? parseInt(select.attr('size')) : 5; |
| 174 | + |
| 175 | + // Draw a dummy control off-screen, measure, and remove it |
| 176 | + var tmp = control |
| 177 | + .clone() |
| 178 | + .removeAttr('id') |
| 179 | + .css({ |
| 180 | + position: 'absolute', |
| 181 | + top: '-9999em' |
| 182 | + }) |
| 183 | + .show() |
| 184 | + .appendTo('body'); |
| 185 | + tmp.find('.selectBox-options').html('<li><a>\u00A0</a></li>'); |
| 186 | + optionHeight = parseInt(tmp.find('.selectBox-options A:first').html(' ').outerHeight()); |
| 187 | + tmp.remove(); |
190 | 188 |
|
191 | 189 | control.height(optionHeight * size);
|
192 | 190 |
|
@@ -343,16 +341,20 @@ if(jQuery) (function($) {
|
343 | 341 |
|
344 | 342 | } else {
|
345 | 343 |
|
346 |
| - select.find('OPTION').each( function() { |
347 |
| - var li = $('<li />'), |
348 |
| - a = $('<a />'); |
349 |
| - li.addClass( $(this).attr('class') ); |
350 |
| - a.attr('rel', $(this).val()).text( $(this).text() ); |
351 |
| - li.append(a); |
352 |
| - if( $(this).attr('disabled') ) li.addClass('selectBox-disabled'); |
353 |
| - if( $(this).attr('selected') ) li.addClass('selectBox-selected'); |
354 |
| - options.append(li); |
355 |
| - }); |
| 344 | + if( select.find('OPTION').length > 0 ) { |
| 345 | + select.find('OPTION').each( function() { |
| 346 | + var li = $('<li />'), |
| 347 | + a = $('<a />'); |
| 348 | + li.addClass( $(this).attr('class') ); |
| 349 | + a.attr('rel', $(this).val()).text( $(this).text() ); |
| 350 | + li.append(a); |
| 351 | + if( $(this).attr('disabled') ) li.addClass('selectBox-disabled'); |
| 352 | + if( $(this).attr('selected') ) li.addClass('selectBox-selected'); |
| 353 | + options.append(li); |
| 354 | + }); |
| 355 | + } else { |
| 356 | + options.append('<li>\u00A0</li>'); |
| 357 | + } |
356 | 358 |
|
357 | 359 | }
|
358 | 360 |
|
|
0 commit comments