|
25 | 25 | hideDropdownOnEmptyInput: false,
|
26 | 26 | selectedClass: "flexselect_selected",
|
27 | 27 | dropdownClass: "flexselect_dropdown",
|
| 28 | + showDisabledOptions: false, |
28 | 29 | inputIdTransform: function(id) { return id + "_flexselect"; },
|
29 | 30 | inputNameTransform: function(name) { return; },
|
30 | 31 | dropdownIdTransform: function(id) { return id + "_flexselect_dropdown"; }
|
|
52 | 53 | },
|
53 | 54 |
|
54 | 55 | preloadCache: function() {
|
55 |
| - var name, group, text; |
| 56 | + var name, group, text, disabled; |
56 | 57 | var indexGroup = this.settings.indexOptgroupLabels;
|
57 | 58 | this.cache = this.select.find("option").map(function() {
|
58 | 59 | name = $(this).text();
|
59 | 60 | group = $(this).parent("optgroup").attr("label");
|
60 | 61 | text = indexGroup ? [name, group].join(" ") : name;
|
61 |
| - return { text: $.trim(text), name: $.trim(name), value: $(this).val(), score: 0.0 }; |
| 62 | + disabled = $(this).parent('optgroup[disabled]').size() != 0 || typeof $(this).attr('disabled') != 'undefined'; |
| 63 | + return { text: $.trim(text), name: $.trim(name), value: $(this).val(), disabled: disabled, score: 0.0 }; |
62 | 64 | });
|
63 | 65 | },
|
64 | 66 |
|
|
206 | 208 | },
|
207 | 209 |
|
208 | 210 | filterResults: function() {
|
| 211 | + var showDisabled = this.settings.showDisabledOptions; |
209 | 212 | var abbreviation = this.input.val();
|
210 | 213 | if (abbreviation == this.lastAbbreviation) return;
|
211 | 214 |
|
212 | 215 | var results = [];
|
213 | 216 | $.each(this.cache, function() {
|
| 217 | + if (this.disabled && !showDisabled) return; |
214 | 218 | this.score = LiquidMetal.score(this.text, abbreviation);
|
215 | 219 | if (this.score > 0.0) results.push(this);
|
216 | 220 | });
|
|
237 | 241 | },
|
238 | 242 |
|
239 | 243 | renderDropdown: function() {
|
| 244 | + var showDisabled = this.settings.showDisabledOptions; |
240 | 245 | var dropdownBorderWidth = this.dropdown.outerWidth() - this.dropdown.innerWidth();
|
241 | 246 | var inputOffset = this.input.offset();
|
242 | 247 | this.dropdown.css({
|
|
249 | 254 | var html = '';
|
250 | 255 | $.each(this.results, function() {
|
251 | 256 | //html += '<li>' + this.name + ' <small>[' + Math.round(this.score*100)/100 + ']</small></li>';
|
252 |
| - html += '<li>' + this.name + '</li>'; |
| 257 | + if (this.disabled && !showDisabled) return; |
| 258 | + else if (this.disabled && showDisabled) { |
| 259 | + html += '<li class="disabled">' + this.name + '</li>'; |
| 260 | + } else { |
| 261 | + html += '<li>' + this.name + '</li>'; |
| 262 | + } |
253 | 263 | });
|
254 | 264 | this.dropdownList.html(html);
|
255 | 265 | this.adjustMaxHeight();
|
|
267 | 277 |
|
268 | 278 | var rows = this.dropdown.find("li");
|
269 | 279 | rows.removeClass(this.settings.selectedClass);
|
270 |
| - this.selectedIndex = n; |
271 | 280 |
|
272 |
| - var row = $(rows[n]).addClass(this.settings.selectedClass); |
| 281 | + var row = $(rows[n]); |
| 282 | + if (row.hasClass('disabled')) { |
| 283 | + this.selectedIndex = null; |
| 284 | + return; |
| 285 | + } |
| 286 | + |
| 287 | + this.selectedIndex = n; |
| 288 | + row.addClass(this.settings.selectedClass); |
273 | 289 | var top = row.position().top;
|
274 | 290 | var delta = top + row.outerHeight() - this.dropdown.height();
|
275 | 291 | if (delta > 0) {
|
|
283 | 299 |
|
284 | 300 | pickSelected: function() {
|
285 | 301 | var selected = this.results[this.selectedIndex];
|
286 |
| - if (selected) { |
| 302 | + if (selected && !selected.disabled) { |
287 | 303 | this.input.val(selected.name);
|
288 | 304 | this.setValue(selected.value);
|
289 | 305 | this.picked = true;
|
|
0 commit comments