Skip to content

Commit

Permalink
Add events (#699). Fix #799.
Browse files Browse the repository at this point in the history
Adds:
rendered.bs.select,
refreshed.bs.select,
change.bs.select,
hide.bs.select,
hidden.bs.select,
show.bs.select,
shown.bs.select

hide.bs.select, hidden.bs.select, show.bs.select, and shown.bs.select
all have a relatedTarget property, whose value is the toggling anchor
element.

changed.bs.select passes through event, clickedIndex, newValue,
oldValue. true if selected and false if not selected.
  • Loading branch information
caseyjhol committed Apr 29, 2015
1 parent 16d4b6d commit 541d9a0
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
24 changes: 23 additions & 1 deletion dist/js/bootstrap-select.js
Expand Up @@ -561,6 +561,8 @@
//strip all html-tags and trim the result
this.$button.attr('title', $.trim(title.replace(/<[^>]*>?/g, '')));
this.$button.children('.filter-option').html(title);

this.$element.trigger('rendered.bs.select');
},

/**
Expand Down Expand Up @@ -677,7 +679,7 @@
menuHeight = liHeight * this.options.size + divLength * divHeight + menuPadding;
if (that.options.dropupAuto) {
//noinspection JSUnusedAssignment
this.$newElement.toggleClass('dropup', selectOffsetTop > selectOffsetBot && menuHeight < $menu.height());
this.$newElement.toggleClass('dropup', selectOffsetTop > selectOffsetBot && (menuHeight - menuExtras) < $menu.height());
}
$menu.css({
'max-height': menuHeight + headerHeight + searchHeight + actionsHeight + doneButtonHeight + 'px',
Expand Down Expand Up @@ -811,6 +813,22 @@
});

$document.data('spaceSelect', false);

this.$newElement.on('hide.bs.dropdown', function(e) {
that.$element.trigger('hide.bs.select', e);
});

this.$newElement.on('hidden.bs.dropdown', function(e) {
that.$element.trigger('hidden.bs.select', e);
});

this.$newElement.on('show.bs.dropdown', function(e) {
that.$element.trigger('show.bs.select', e);
});

this.$newElement.on('shown.bs.dropdown', function(e) {
that.$element.trigger('shown.bs.select', e);
});

this.$button.on('keyup', function(e) {
if (/(32)/.test(e.keyCode.toString(10)) && $document.data('spaceSelect')) {
Expand Down Expand Up @@ -924,6 +942,8 @@
// Trigger select 'change'
if ((prevValue != that.$element.val() && that.multiple) || (prevIndex != that.$element.prop('selectedIndex') && !that.multiple)) {
that.$element.change();
// $option.prop('selected') is current option state (selected/unselected). state is previous option state.
that.$element.trigger('changed.bs.select', [clickedIndex, $option.prop('selected'), state]);
}
}
});
Expand Down Expand Up @@ -1321,6 +1341,8 @@
this.setStyle();
this.checkDisabled();
this.liHeight();

this.$element.trigger('refreshed.bs.select');
},

hide: function () {
Expand Down

0 comments on commit 541d9a0

Please sign in to comment.