|
31 | 31 | this.$target = this.$container.find('input[type=hidden]'); |
32 | 32 | this.$button = this.$container.find('.dropdown-toggle'); |
33 | 33 | this.$menu = $(this.options.menu).appendTo('body'); |
| 34 | + this.template = this.options.template || this.template |
34 | 35 | this.matcher = this.options.matcher || this.matcher; |
35 | 36 | this.sorter = this.options.sorter || this.sorter; |
36 | 37 | this.highlighter = this.options.highlighter || this.highlighter; |
|
46 | 47 | constructor: Combobox |
47 | 48 |
|
48 | 49 | , setup: function () { |
49 | | - var combobox = $(this.options.template(this.options.bsVersion)); |
| 50 | + var combobox = $(this.template()); |
50 | 51 | this.$source.before(combobox); |
51 | 52 | this.$source.hide(); |
52 | 53 | return combobox; |
|
153 | 154 | return this.render(items.slice(0, this.options.items)).show(); |
154 | 155 | } |
155 | 156 |
|
| 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 | + |
156 | 165 | , matcher: function (item) { |
157 | 166 | return ~item.toLowerCase().indexOf(this.query.toLowerCase()); |
158 | 167 | } |
|
395 | 404 |
|
396 | 405 | $.fn.combobox.defaults = { |
397 | 406 | 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 | | - } |
405 | 407 | , menu: '<ul class="typeahead typeahead-long dropdown-menu"></ul>' |
406 | 408 | , item: '<li><a href="#"></a></li>' |
407 | 409 | }; |
|
0 commit comments