Skip to content

Commit

Permalink
move shown.bs.select listener outside of click listener
Browse files Browse the repository at this point in the history
fix #1268
  • Loading branch information
caseyjhol committed Jan 29, 2016
1 parent 08d2ceb commit 3acc13a
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions js/bootstrap-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -1060,20 +1060,21 @@

this.$button.on('click', function () {
that.setSize();
that.$element.on('shown.bs.select', function () {
if (!that.options.liveSearch && !that.multiple) {
that.$menuInner.find('.selected a').focus();
} else if (!that.multiple) {
var selectedIndex = that.liObj[that.$element[0].selectedIndex];

if (typeof selectedIndex !== 'number' || that.options.size === false) return;

// scroll to selected option
var offset = that.$lis.eq(selectedIndex)[0].offsetTop - that.$menuInner[0].offsetTop;
offset = offset - that.$menuInner[0].offsetHeight/2 + that.sizeInfo.liHeight/2;
that.$menuInner[0].scrollTop = offset;
}
});
});

this.$element.on('shown.bs.select', function () {
if (!that.options.liveSearch && !that.multiple) {
that.$menuInner.find('.selected a').focus();
} else if (!that.multiple) {
var selectedIndex = that.liObj[that.$element[0].selectedIndex];

if (typeof selectedIndex !== 'number' || that.options.size === false) return;

// scroll to selected option
var offset = that.$lis.eq(selectedIndex)[0].offsetTop - that.$menuInner[0].offsetTop;
offset = offset - that.$menuInner[0].offsetHeight/2 + that.sizeInfo.liHeight/2;
that.$menuInner[0].scrollTop = offset;
}
});

this.$menuInner.on('click', 'li a', function (e) {
Expand Down

0 comments on commit 3acc13a

Please sign in to comment.