Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dist/bootstrap-suggest.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* bootstra-suggest - v2.0.1 (https://github.com/lodev09/bootstrap-suggest#readme)
* Copyright 2013-2019 Jovanni Lo (lodev09@gmail.com)
* bootstra-suggest - v2.1.0 (https://github.com/lodev09/bootstrap-suggest#readme)
* Copyright 2013-2020 Jovanni Lo (lodev09@gmail.com)
* Licensed under MIT (https://github.com/lodev09/bootstrap-suggest/blob/master/LICENSE)
*/

Expand Down
24 changes: 17 additions & 7 deletions dist/bootstrap-suggest.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,13 @@

for (var i = currentPos; i >= 0; i--) {
var subChar = $.trim(val.substring(i-1, i));
if (!subChar) {
if (!subChar && this.options.respectWhitespace) {
this.hide();
break;
}

if (subChar === this.key && $.trim(val.substring(i-2, i-1)) == '') {
var isSpaceBefore = $.trim(val.substring(i - 2, i - 1)) == '';
if (subChar === this.key && (isSpaceBefore || !this.options.respectWhitespace)) {
this.query = val.substring(i, currentPos);
this._queryPos = [i, currentPos];
this._keyPos = i;
Expand Down Expand Up @@ -223,6 +224,7 @@
if (that.isShown) {
switch (e.keyCode) {
case 13: // enter key
case 9: // tab key
$visibleItems = that.__getVisibleItems();
$visibleItems.each(function(index) {
if ($(this).is('.active'))
Expand Down Expand Up @@ -277,7 +279,8 @@
var itemHtml, that = this,
_item = {
text: '',
value: ''
value: '',
class: ''
};

if (this.options.map) {
Expand All @@ -288,27 +291,30 @@
if (dataItem instanceof Object) {
_item.text = dataItem.text || '';
_item.value = dataItem.value || '';
_item.class = dataItem.class || '';
} else {
_item.text = dataItem;
_item.value = dataItem;
}

return $('<a />', {
'class': 'dropdown-item',
'class': 'dropdown-item' + ' ' + _item.class,
'data-value': _item.value,
href: '#',
html: _item.text
});
},

__select: function(index) {
var endKey = this.options.endKey || '';
var $el = this.$element,
el = $el.get(0),
val = $el.val(),
item = this.get(index),
setCaretPos = this._keyPos + item.value.length + 1;

$el.val(val.slice(0, this._keyPos) + item.value + ' ' + val.slice(this.__getSelection(el).start));
$el.val(val.slice(0, this._keyPos) + item.value + endKey + ' ' + val.slice(this.__getSelection(el).start));
$el.blur();

if (el.setSelectionRange) {
el.setSelectionRange(setCaretPos, setCaretPos);
Expand Down Expand Up @@ -372,12 +378,14 @@
if (q === '') return index < options.filter.limit;

var value = $(this).text();
var selectorValue = $(this).data().value;

if (!options.filter.casesensitive) {
value = value.toLowerCase();
q = q.toLowerCase();
selectorValue = selectorValue.toLowerCase();
}
return value.indexOf(q) != -1;
return value.indexOf(q) != -1 || selectorValue.indexOf(q) != -1;
}).slice(0, options.filter.limit).removeClass('d-none active');
return this.__getVisibleItems();
},
Expand Down Expand Up @@ -574,6 +582,8 @@
},
dropdownClass: '',
position: 'caret',
endKey: '',
respectWhitespace: true,
// events hook
onshow: function(e) {},
onselect: function(e, item) {},
Expand All @@ -588,4 +598,4 @@
return this;
}

}( jQuery ));
}( jQuery ));
6 changes: 3 additions & 3 deletions dist/bootstrap-suggest.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading