Skip to content

Commit 2fb999c

Browse files
Cleaned up graceful degradation options
1 parent b0a943e commit 2fb999c

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

js/bootstrap-combobox.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
this.$target = this.$container.find('input[type=hidden]');
3232
this.$button = this.$container.find('.dropdown-toggle');
3333
this.$menu = $(this.options.menu).appendTo('body');
34+
this.template = this.options.template || this.template
3435
this.matcher = this.options.matcher || this.matcher;
3536
this.sorter = this.options.sorter || this.sorter;
3637
this.highlighter = this.options.highlighter || this.highlighter;
@@ -46,7 +47,7 @@
4647
constructor: Combobox
4748

4849
, setup: function () {
49-
var combobox = $(this.options.template(this.options.bsVersion));
50+
var combobox = $(this.template());
5051
this.$source.before(combobox);
5152
this.$source.hide();
5253
return combobox;
@@ -153,6 +154,14 @@
153154
return this.render(items.slice(0, this.options.items)).show();
154155
}
155156

157+
, template: function() {
158+
if (this.options.bsVersion == '2') {
159+
return '<div class="combobox-container"><input type="hidden" /> <div class="input-append"> <input type="text" autocomplete="off" /> <span class="add-on dropdown-toggle" data-dropdown="dropdown"> <span class="caret"/> <i class="icon-remove"/> </span> </div> </div>'
160+
} else {
161+
return '<div class="combobox-container"> <input type="hidden" /> <div class="input-group"> <input type="text" autocomplete="off" /> <span class="input-group-addon dropdown-toggle" data-dropdown="dropdown"> <span class="caret" /> <span class="glyphicon glyphicon-remove" /> </span> </div> </div>'
162+
}
163+
}
164+
156165
, matcher: function (item) {
157166
return ~item.toLowerCase().indexOf(this.query.toLowerCase());
158167
}
@@ -395,13 +404,6 @@
395404

396405
$.fn.combobox.defaults = {
397406
bsVersion: '3'
398-
, template: function(bsVersion) {
399-
if (bsVersion == '2') {
400-
return '<div class="combobox-container"><input type="hidden" /> <div class="input-append"> <input type="text" autocomplete="off" /> <span class="add-on dropdown-toggle" data-dropdown="dropdown"> <span class="caret"/> <i class="icon-remove"/> </span> </div> </div>'
401-
} else {
402-
return '<div class="combobox-container"> <input type="hidden" /> <div class="input-group"> <input type="text" autocomplete="off" /> <span class="input-group-addon dropdown-toggle" data-dropdown="dropdown"> <span class="caret" /> <span class="glyphicon glyphicon-remove" /> </span> </div> </div>'
403-
}
404-
}
405407
, menu: '<ul class="typeahead typeahead-long dropdown-menu"></ul>'
406408
, item: '<li><a href="#"></a></li>'
407409
};

0 commit comments

Comments
 (0)