|
7 | 7 | *
|
8 | 8 | * https://github.com/marcj/jquery-selectBox
|
9 | 9 | */
|
| 10 | + |
| 11 | + |
10 | 12 | ;(function ($) {
|
11 | 13 |
|
12 | 14 | /**
|
|
984 | 986 | }
|
985 | 987 | };
|
986 | 988 |
|
987 |
| - /** |
988 |
| - * Sets the option elements. |
989 |
| - * |
990 |
| - * @param {String|Object} options |
991 |
| - */ |
992 |
| - SelectBox.prototype.setOptions = function (options) { |
993 |
| - var select = $(this.selectElement) |
994 |
| - , control = select.data('selectBox-control'); |
995 |
| - |
996 |
| - switch (typeof(options)) { |
997 |
| - case 'string': |
998 |
| - select.html(options); |
999 |
| - break; |
1000 |
| - case 'object': |
1001 |
| - select.html(''); |
1002 |
| - for (var i in options) { |
1003 |
| - if (options[i] === null) { |
1004 |
| - continue; |
1005 |
| - } |
1006 |
| - if (typeof(options[i]) === 'object') { |
1007 |
| - var optgroup = $('<optgroup label="' + i + '" />'); |
1008 |
| - for (var j in options[i]) { |
1009 |
| - optgroup.append('<option value="' + j + '">' + options[i][j] + '</option>'); |
1010 |
| - } |
1011 |
| - select.append(optgroup); |
1012 |
| - } else { |
1013 |
| - var option = $('<option value="' + i + '">' + options[i] + '</option>'); |
1014 |
| - select.append(option); |
1015 |
| - } |
1016 |
| - } |
1017 |
| - break; |
1018 |
| - } |
1019 | 989 |
|
1020 |
| - if (control) { |
1021 |
| - // Refresh the control |
1022 |
| - this.refresh(); |
1023 |
| - } |
1024 |
| - }; |
1025 | 990 |
|
1026 | 991 | /**
|
1027 | 992 | * Disables the selection.
|
|
1059 | 1024 | * Extends the jQuery.fn object.
|
1060 | 1025 | */
|
1061 | 1026 | $.extend($.fn, {
|
1062 |
| - selectBox: function (method, options) { |
| 1027 | + |
| 1028 | + /** |
| 1029 | + * Sets the option elements. |
| 1030 | + * |
| 1031 | + * @param {String|Object} options |
| 1032 | + */ |
| 1033 | + setOptions : function (options) { |
| 1034 | + var select = $(this) |
| 1035 | + , control = select.data('selectBox-control'); |
| 1036 | + |
| 1037 | + |
| 1038 | + switch (typeof(options)) { |
| 1039 | + case 'string': |
| 1040 | + select.html(options); |
| 1041 | + break; |
| 1042 | + case 'object': |
| 1043 | + select.html(''); |
| 1044 | + for (var i in options) { |
| 1045 | + if (options[i] === null) { |
| 1046 | + continue; |
| 1047 | + } |
| 1048 | + if (typeof(options[i]) === 'object') { |
| 1049 | + var optgroup = $('<optgroup label="' + i + '" />'); |
| 1050 | + for (var j in options[i]) { |
| 1051 | + optgroup.append('<option value="' + j + '">' + options[i][j] + '</option>'); |
| 1052 | + } |
| 1053 | + select.append(optgroup); |
| 1054 | + } else { |
| 1055 | + var option = $('<option value="' + i + '">' + options[i] + '</option>'); |
| 1056 | + select.append(option); |
| 1057 | + } |
| 1058 | + } |
| 1059 | + break; |
| 1060 | + } |
| 1061 | + |
| 1062 | + if (control) { |
| 1063 | + // Refresh the control |
| 1064 | + $(this).selectBox('refresh'); |
| 1065 | + // Remove old options |
| 1066 | + |
| 1067 | + } |
| 1068 | + }, |
| 1069 | + |
| 1070 | + |
| 1071 | + |
| 1072 | + selectBox: function (method, options) { |
1063 | 1073 | var selectBox;
|
1064 | 1074 |
|
1065 | 1075 | switch (method) {
|
|
1075 | 1085 | break;
|
1076 | 1086 | case 'options':
|
1077 | 1087 | // Getter
|
| 1088 | + |
1078 | 1089 | if (undefined === options) {
|
1079 | 1090 | return $(this).data('selectBox-control').data('selectBox-options');
|
1080 | 1091 | }
|
| 1092 | + |
1081 | 1093 | // Setter
|
1082 | 1094 | $(this).each(function () {
|
1083 |
| - if (selectBox = $(this).data('selectBox')) { |
1084 |
| - selectBox.setOptions(options); |
1085 |
| - } |
| 1095 | + |
| 1096 | + // if (selectBox = $(this).data('selectBox')) { |
| 1097 | + $(this).setOptions(options); |
| 1098 | + // } |
| 1099 | + |
1086 | 1100 | });
|
1087 | 1101 | break;
|
1088 | 1102 | case 'value':
|
|
0 commit comments