|
401 | 401 | * Refreshes the option elements.
|
402 | 402 | */
|
403 | 403 | SelectBox.prototype.refresh = function () {
|
404 |
| - var select = $(this.selectElement), |
405 |
| - control = select.data('selectBox-control'), |
406 |
| - dropdown = control.hasClass('selectBox-dropdown'), |
407 |
| - menuOpened = control.hasClass('selectBox-menuShowing'); |
408 |
| - select.selectBox('options', select.html()); |
| 404 | + var select = $(this.selectElement) |
| 405 | + , control = select.data('selectBox-control') |
| 406 | + , type = control.hasClass('selectBox-dropdown') ? 'dropdown' : 'inline' |
| 407 | + , options; |
| 408 | + |
| 409 | + // Remove old options |
| 410 | + control.data('selectBox-options').remove(); |
| 411 | + |
| 412 | + // Generate new options |
| 413 | + options = this.getOptions(type); |
| 414 | + control.data('selectBox-options', options); |
| 415 | + |
| 416 | + switch (type) { |
| 417 | + case 'inline': |
| 418 | + control.append(options); |
| 419 | + break; |
| 420 | + case 'dropdown': |
| 421 | + // Update label |
| 422 | + this.setLabel(); |
| 423 | + $("BODY").append(options); |
| 424 | + break; |
| 425 | + } |
| 426 | + |
409 | 427 | // Restore opened dropdown state (original menu was trashed)
|
410 |
| - if (dropdown && menuOpened) { |
| 428 | + if ('dropdown' === type && control.hasClass('selectBox-menuShowing')) { |
411 | 429 | this.showMenu();
|
412 | 430 | }
|
413 | 431 | };
|
|
922 | 940 | */
|
923 | 941 | SelectBox.prototype.setOptions = function (options) {
|
924 | 942 | var select = $(this.selectElement)
|
925 |
| - , control = select.data('selectBox-control') |
926 |
| - , settings = select.data('selectBox-settings') |
927 |
| - , type; |
| 943 | + , control = select.data('selectBox-control'); |
928 | 944 |
|
929 | 945 | switch (typeof(options)) {
|
930 | 946 | case 'string':
|
|
950 | 966 | break;
|
951 | 967 | }
|
952 | 968 |
|
953 |
| - if (!control) { |
954 |
| - return; |
955 |
| - } |
956 |
| - |
957 |
| - // Remove old options |
958 |
| - control.data('selectBox-options').remove(); |
959 |
| - |
960 |
| - // Generate new options |
961 |
| - type = control.hasClass('selectBox-dropdown') ? 'dropdown' : 'inline'; |
962 |
| - options = this.getOptions(type); |
963 |
| - control.data('selectBox-options', options); |
964 |
| - |
965 |
| - switch (type) { |
966 |
| - case 'inline': |
967 |
| - control.append(options); |
968 |
| - break; |
969 |
| - case 'dropdown': |
970 |
| - // Update label |
971 |
| - this.setLabel(); |
972 |
| - $("BODY").append(options); |
973 |
| - break; |
| 969 | + if (control) { |
| 970 | + // Refresh the control |
| 971 | + this.refresh(); |
974 | 972 | }
|
975 | 973 | };
|
976 | 974 |
|
|
0 commit comments