Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes Bootstrap3 formatting #60

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
5 changes: 4 additions & 1 deletion dist/bootstrap-suggest.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* bootstra-suggest - v2.0.1 (https://github.com/lodev09/bootstrap-suggest#readme)
* bootstra-suggest - v2.0.3 (https://github.com/lodev09/bootstrap-suggest#readme)
* Copyright 2013-2019 Jovanni Lo ([email protected])
* Licensed under MIT (https://github.com/lodev09/bootstrap-suggest/blob/master/LICENSE)
*/
Expand All @@ -14,6 +14,8 @@
.suggest > .dropdown-menu {
margin-top: 15px;
position: absolute;
height: 200px;
overflow-y: scroll
}

.suggest > .dropdown-menu > a.dropdown-item {
Expand All @@ -24,3 +26,4 @@
.suggest > .dropdown-menu > a.dropdown-item:first-child {
border-top: 0;
}

43 changes: 22 additions & 21 deletions dist/bootstrap-suggest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* ===================================================
* bootstrap-suggest.js
* bootstrap-suggest.js v2.0.3
* http://github.com/lodev09/bootstrap-suggest
* ===================================================
* Copyright 2019 Jovanni Lo @lodev09
Expand Down Expand Up @@ -35,7 +35,7 @@

this.$dropdown = $('<div />', {
'class': 'dropdown suggest ' + this.options.dropdownClass,
'html': $('<div />', {'class': 'dropdown-menu', role: 'menu'}),
'html': $('<ul />', {'class': 'dropdown-menu', role: 'menu'}),
'data-key': this.key
});

Expand Down Expand Up @@ -208,13 +208,16 @@
that.hide();
}

$dropdown.on('click', 'a.dropdown-item', function(e) {
$dropdown
.on('click', 'li:has(a)', function(e) {
e.preventDefault();
that.__select($(this).index());
that.$element.focus();
}).on('mouseover', 'a.dropdown-item', function(e) {
})
.on('mouseover', 'li:has(a)', function(e) {
that.$element.off('blur', blur);
}).on('mouseout', 'a.dropdown-item', function(e) {
})
.on('mouseout', 'li:has(a)', function(e) {
that.$element.on('blur', blur);
});

Expand All @@ -241,7 +244,7 @@
//if (!$next.length) return false;

if ($this.is('.active')) {
if (!$next.is('.d-none')) {
if (!$next.is('.hidden')) {
$this.removeClass('active');
$next.addClass('active');
}
Expand All @@ -259,7 +262,7 @@
//if (!$prev.length) return false;

if ($this.is('.active')) {
if (!$prev.is('.d-none')) {
if (!$prev.is('.hidden')) {
$this.removeClass('active');
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this may need to be !$prev.is('.hidden') || !$prev.is('.d-none')

$prev.addClass('active');
}
Expand Down Expand Up @@ -293,12 +296,10 @@
_item.value = dataItem;
}

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

__select: function(index) {
Expand All @@ -308,7 +309,7 @@
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 + this.options.endKey + val.slice(this.__getSelection(el).start));

if (el.setSelectionRange) {
el.setSelectionRange(setCaretPos, setCaretPos);
Expand Down Expand Up @@ -347,8 +348,7 @@
}
}
}

return $dropdownMenu.find('a.dropdown-item');
return $dropdownMenu.find('li:has(a)');
},

__lookup: function(q, $resultItems) {
Expand All @@ -364,21 +364,21 @@

__filterData: function(q, data) {
var options = this.options;

this.$items.addClass('d-none');
this.$items.addClass('hidden');
this.$items.filter(function (index) {

// return the limit if q is empty
if (q === '') return index < options.filter.limit;

var value = $(this).text();
var $this = $(this),
value = $this.find('a:first').text();

if (!options.filter.casesensitive) {
value = value.toLowerCase();
q = q.toLowerCase();
}
return value.indexOf(q) != -1;
}).slice(0, options.filter.limit).removeClass('d-none active');
}).slice(0, options.filter.limit).removeClass('hidden active');
return this.__getVisibleItems();
},

Expand All @@ -387,7 +387,7 @@

var $item = this.$items.eq(index);
return {
text: $item.text(),
text: $item.children('a:first').text(),
value: $item.attr('data-value'),
index: index,
$element: $item
Expand Down Expand Up @@ -430,7 +430,7 @@
},

hide: function() {
this.$dropdown.find('.dropdown-menu').removeClass('show');
this.$dropdown.removeClass('open show');
this.isShown = false;
if(this.$items) {
this.$items.removeClass('active');
Expand All @@ -453,7 +453,7 @@

if (!this.isShown) {

$dropdownMenu.addClass('show');
this.$dropdown.addClass('open show');
if (options.position !== false) {

caretPos = this.__getCaretPos(this._keyPos);
Expand Down Expand Up @@ -572,6 +572,7 @@
casesensitive: false,
limit: 5
},
endKey: ' ',
dropdownClass: '',
position: 'caret',
// events hook
Expand Down
Loading