vendor/assets/javascripts/bootstrap-select.js in bootstrap-select-wrapper-rails-1.9.4 vs vendor/assets/javascripts/bootstrap-select.js in bootstrap-select-wrapper-rails-1.10.0
- old
+ new
@@ -1,7 +1,7 @@
/*!
- * Bootstrap-select v1.9.4 (http://silviomoreto.github.io/bootstrap-select)
+ * Bootstrap-select v1.10.0 (http://silviomoreto.github.io/bootstrap-select)
*
* Copyright 2013-2016 bootstrap-select
* Licensed under MIT (https://github.com/silviomoreto/bootstrap-select/blob/master/LICENSE)
*/
@@ -285,11 +285,11 @@
this.hide = Selectpicker.prototype.hide;
this.init();
};
- Selectpicker.VERSION = '1.9.4';
+ Selectpicker.VERSION = '1.10.0';
// part of this is duplicated in i18n/defaults-en_US.js. Make sure to update both.
Selectpicker.DEFAULTS = {
noneSelectedText: 'Nothing selected',
noneResultsText: 'No results matched {0}',
@@ -325,10 +325,11 @@
liveSearchNormalize: false,
liveSearchStyle: 'contains',
actionsBox: false,
iconBase: 'glyphicon',
tickIcon: 'glyphicon-ok',
+ showTick: false,
template: {
caret: '<span class="caret"></span>'
},
maxOptions: false,
mobile: false,
@@ -342,10 +343,12 @@
init: function () {
var that = this,
id = this.$element.attr('id');
+ this.$element.addClass('bs-select-hidden');
+
// store originalIndex (key) and newIndex (value) in this.liObj for fast accessibility
// allows us to do this.$lis.eq(that.liObj[index]) instead of this.$lis.filter('[data-original-index="' + index + '"]')
this.liObj = {};
this.multiple = this.$element.prop('multiple');
this.autofocus = this.$element.prop('autofocus');
@@ -356,10 +359,12 @@
this.$button = this.$newElement.children('button');
this.$menu = this.$newElement.children('.dropdown-menu');
this.$menuInner = this.$menu.children('.inner');
this.$searchbox = this.$menu.find('input');
+ this.$element.removeClass('bs-select-hidden');
+
if (this.options.dropdownAlignRight)
this.$menu.addClass('dropdown-menu-right');
if (typeof id !== 'undefined') {
this.$button.attr('data-id', id);
@@ -426,12 +431,12 @@
});
},
createDropdown: function () {
// Options
- // If we are multiple, then add the show-tick class by default
- var multiple = this.multiple ? ' show-tick' : '',
+ // If we are multiple or showTick option is set, then add the show-tick class
+ var showTick = (this.multiple || this.options.showTick) ? ' show-tick' : '',
inputGroup = this.$element.parent().hasClass('input-group') ? ' input-group-btn' : '',
autofocus = this.autofocus ? ' autofocus' : '';
// Elements
var header = this.options.header ? '<div class="popover-title"><button type="button" class="close" aria-hidden="true">×</button>' + this.options.header + '</div>' : '';
var searchbox = this.options.liveSearch ?
@@ -460,11 +465,11 @@
'</button>' +
'</div>' +
'</div>'
: '';
var drop =
- '<div class="btn-group bootstrap-select' + multiple + inputGroup + '">' +
+ '<div class="btn-group bootstrap-select' + showTick + inputGroup + '">' +
'<button type="button" class="' + this.options.styleBase + ' dropdown-toggle" data-toggle="dropdown"' + autofocus + '>' +
'<span class="filter-option pull-left"></span> ' +
'<span class="bs-caret">' +
this.options.template.caret +
'</span>' +
@@ -1080,24 +1085,25 @@
}
});
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;
+ 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];
- // 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;
- }
- });
+ 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) {
var $this = $(this),
clickedIndex = $this.parent().data('originalIndex'),
@@ -1191,13 +1197,14 @@
that.$searchbox.focus();
}
// Trigger select 'change'
if ((prevValue != that.$element.val() && that.multiple) || (prevIndex != that.$element.prop('selectedIndex') && !that.multiple)) {
- that.$element.triggerNative('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]);
+ that.$element
+ .trigger('changed.bs.select', [clickedIndex, $option.prop('selected'), state])
+ .triggerNative('change');
}
}
});
this.$menu.on('click', 'li.disabled a, .popover-title, .popover-title :not(.close)', function (e) {
@@ -1243,11 +1250,10 @@
if ($(this).hasClass('bs-select-all')) {
that.selectAll();
} else {
that.deselectAll();
}
- that.$element.triggerNative('change');
});
this.$element.change(function () {
that.render(false);
});
@@ -1366,17 +1372,29 @@
}
$(selectedOptions).prop('selected', status);
this.render(false);
+
+ this.$element
+ .trigger('changed.bs.select')
+ .triggerNative('change');
},
selectAll: function () {
return this.changeAll(true);
},
deselectAll: function () {
return this.changeAll(false);
+ },
+
+ toggle: function (e) {
+ e = e || window.event;
+
+ if (e) e.stopPropagation();
+
+ this.$button.trigger('click');
},
keydown: function (e) {
var $this = $(this),
$parent = $this.is('input') ? $this.parent().parent() : $this.parent(),