|
@@ -1,5 +1,5 @@
|
|
|
/*!
|
|
|
- * Select2 4.0.0-rc.2
|
|
|
+ * Select2 4.0.0
|
|
|
* https://select2.github.io
|
|
|
*
|
|
|
* Released under the MIT license
|
|
@@ -714,6 +714,23 @@ S2.define('select2/utils',[
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+ // Append an array of jQuery nodes to a given element.
|
|
|
+ Utils.appendMany = function ($element, $nodes) {
|
|
|
+ // jQuery 1.7.x does not support $.fn.append() with an array
|
|
|
+ // Fall back to a jQuery object collection using $.fn.add()
|
|
|
+ if ($.fn.jquery.substr(0, 3) === '1.7') {
|
|
|
+ var $jqNodes = $();
|
|
|
+
|
|
|
+ $.map($nodes, function (node) {
|
|
|
+ $jqNodes = $jqNodes.add(node);
|
|
|
+ });
|
|
|
+
|
|
|
+ $nodes = $jqNodes;
|
|
|
+ }
|
|
|
+
|
|
|
+ $element.append($nodes);
|
|
|
+ };
|
|
|
+
|
|
|
return Utils;
|
|
|
});
|
|
|
|
|
@@ -1565,7 +1582,7 @@ S2.define('select2/selection/multiple',[
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- var $selections = $();
|
|
|
+ var $selections = [];
|
|
|
|
|
|
for (var d = 0; d < data.length; d++) {
|
|
|
var selection = data[d];
|
|
@@ -1578,10 +1595,12 @@ S2.define('select2/selection/multiple',[
|
|
|
|
|
|
$selection.data('data', selection);
|
|
|
|
|
|
- $selections = $selections.add($selection);
|
|
|
+ $selections.push($selection);
|
|
|
}
|
|
|
|
|
|
- this.$selection.find('.select2-selection__rendered').append($selections);
|
|
|
+ var $rendered = this.$selection.find('.select2-selection__rendered');
|
|
|
+
|
|
|
+ Utils.appendMany($rendered, $selections);
|
|
|
};
|
|
|
|
|
|
return MultipleSelection;
|
|
@@ -3015,7 +3034,7 @@ S2.define('select2/data/select',[
|
|
|
};
|
|
|
|
|
|
SelectAdapter.prototype.addOptions = function ($options) {
|
|
|
- this.$element.append($options);
|
|
|
+ Utils.appendMany(this.$element, $options);
|
|
|
};
|
|
|
|
|
|
SelectAdapter.prototype.option = function (data) {
|
|
@@ -3185,7 +3204,7 @@ S2.define('select2/data/array',[
|
|
|
return self.item($(this)).id;
|
|
|
}).get();
|
|
|
|
|
|
- var $options = $();
|
|
|
+ var $options = [];
|
|
|
|
|
|
// Filter out all items except for the one passed in the argument
|
|
|
function onlyItem (item) {
|
|
@@ -3216,10 +3235,10 @@ S2.define('select2/data/array',[
|
|
|
if (item.children) {
|
|
|
var $children = this.convertToOptions(item.children);
|
|
|
|
|
|
- $option.append($children);
|
|
|
+ Utils.appendMany($option, $children);
|
|
|
}
|
|
|
|
|
|
- $options = $options.add($option);
|
|
|
+ $options.push($option);
|
|
|
}
|
|
|
|
|
|
return $options;
|
|
@@ -3403,7 +3422,7 @@ S2.define('select2/data/tags',[
|
|
|
var $option = self.option(tag);
|
|
|
$option.attr('data-select2-tag', true);
|
|
|
|
|
|
- self.addOptions($option);
|
|
|
+ self.addOptions([$option]);
|
|
|
|
|
|
self.insertTag(data, tag);
|
|
|
}
|
|
@@ -4079,9 +4098,16 @@ S2.define('select2/dropdown/attachBody',[
|
|
|
AttachBody.prototype._resizeDropdown = function () {
|
|
|
this.$dropdownContainer.width();
|
|
|
|
|
|
- this.$dropdown.css({
|
|
|
+ var css = {
|
|
|
width: this.$container.outerWidth(false) + 'px'
|
|
|
- });
|
|
|
+ };
|
|
|
+
|
|
|
+ if (this.options.get('dropdownAutoWidth')) {
|
|
|
+ css.minWidth = css.width;
|
|
|
+ css.width = 'auto';
|
|
|
+ }
|
|
|
+
|
|
|
+ this.$dropdown.css(css);
|
|
|
};
|
|
|
|
|
|
AttachBody.prototype._showDropdown = function (decorated) {
|
|
@@ -4409,6 +4435,19 @@ S2.define('select2/defaults',[
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ if (
|
|
|
+ options.dropdownCssClass != null ||
|
|
|
+ options.dropdownCss != null ||
|
|
|
+ options.adaptDropdownCssClass != null
|
|
|
+ ) {
|
|
|
+ var DropdownCSS = require(options.amdBase + 'compat/dropdownCss');
|
|
|
+
|
|
|
+ options.dropdownAdapter = Utils.Decorate(
|
|
|
+ options.dropdownAdapter,
|
|
|
+ DropdownCSS
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
options.dropdownAdapter = Utils.Decorate(
|
|
|
options.dropdownAdapter,
|
|
|
AttachBody
|
|
@@ -4444,6 +4483,19 @@ S2.define('select2/defaults',[
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ if (
|
|
|
+ options.containerCssClass != null ||
|
|
|
+ options.containerCss != null ||
|
|
|
+ options.adaptContainerCssClass != null
|
|
|
+ ) {
|
|
|
+ var ContainerCSS = require(options.amdBase + 'compat/containerCss');
|
|
|
+
|
|
|
+ options.selectionAdapter = Utils.Decorate(
|
|
|
+ options.selectionAdapter,
|
|
|
+ ContainerCSS
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
options.selectionAdapter = Utils.Decorate(
|
|
|
options.selectionAdapter,
|
|
|
EventRelay
|
|
@@ -4574,6 +4626,7 @@ S2.define('select2/defaults',[
|
|
|
amdLanguageBase: './i18n/',
|
|
|
closeOnSelect: true,
|
|
|
debug: false,
|
|
|
+ dropdownAutoWidth: false,
|
|
|
escapeMarkup: Utils.escapeMarkup,
|
|
|
language: EnglishTranslation,
|
|
|
matcher: matcher,
|
|
@@ -5264,47 +5317,162 @@ S2.define('select2/core',[
|
|
|
return Select2;
|
|
|
});
|
|
|
|
|
|
-S2.define('select2/compat/matcher',[
|
|
|
+S2.define('select2/compat/utils',[
|
|
|
'jquery'
|
|
|
], function ($) {
|
|
|
- function oldMatcher (matcher) {
|
|
|
- function wrappedMatcher (params, data) {
|
|
|
- var match = $.extend(true, {}, data);
|
|
|
+ function syncCssClasses ($dest, $src, adapter) {
|
|
|
+ var classes, replacements = [], adapted;
|
|
|
|
|
|
- if (params.term == null || $.trim(params.term) === '') {
|
|
|
- return match;
|
|
|
- }
|
|
|
+ classes = $.trim($dest.attr('class'));
|
|
|
|
|
|
- if (data.children) {
|
|
|
- for (var c = data.children.length - 1; c >= 0; c--) {
|
|
|
- var child = data.children[c];
|
|
|
+ if (classes) {
|
|
|
+ classes = '' + classes; // for IE which returns object
|
|
|
|
|
|
- // Check if the child object matches
|
|
|
- // The old matcher returned a boolean true or false
|
|
|
- var doesMatch = matcher(params.term, child.text, child);
|
|
|
+ $(classes.split(/\s+/)).each(function () {
|
|
|
+ // Save all Select2 classes
|
|
|
+ if (this.indexOf('select2-') === 0) {
|
|
|
+ replacements.push(this);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- // If the child didn't match, pop it off
|
|
|
- if (!doesMatch) {
|
|
|
- match.children.splice(c, 1);
|
|
|
+ classes = $.trim($src.attr('class'));
|
|
|
+
|
|
|
+ if (classes) {
|
|
|
+ classes = '' + classes; // for IE which returns object
|
|
|
+
|
|
|
+ $(classes.split(/\s+/)).each(function () {
|
|
|
+ // Only adapt non-Select2 classes
|
|
|
+ if (this.indexOf('select2-') !== 0) {
|
|
|
+ adapted = adapter(this);
|
|
|
+
|
|
|
+ if (adapted != null) {
|
|
|
+ replacements.push(adapted);
|
|
|
}
|
|
|
}
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- if (match.children.length > 0) {
|
|
|
- return match;
|
|
|
+ $dest.attr('class', replacements.join(' '));
|
|
|
+ }
|
|
|
+
|
|
|
+ return {
|
|
|
+ syncCssClasses: syncCssClasses
|
|
|
+ };
|
|
|
+});
|
|
|
+
|
|
|
+S2.define('select2/compat/containerCss',[
|
|
|
+ 'jquery',
|
|
|
+ './utils'
|
|
|
+], function ($, CompatUtils) {
|
|
|
+ // No-op CSS adapter that discards all classes by default
|
|
|
+ function _containerAdapter (clazz) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ function ContainerCSS () { }
|
|
|
+
|
|
|
+ ContainerCSS.prototype.render = function (decorated) {
|
|
|
+ var $container = decorated.call(this);
|
|
|
+
|
|
|
+ var containerCssClass = this.options.get('containerCssClass') || '';
|
|
|
+
|
|
|
+ if ($.isFunction(containerCssClass)) {
|
|
|
+ containerCssClass = containerCssClass(this.$element);
|
|
|
+ }
|
|
|
+
|
|
|
+ var containerCssAdapter = this.options.get('adaptContainerCssClass');
|
|
|
+ containerCssAdapter = containerCssAdapter || _containerAdapter;
|
|
|
+
|
|
|
+ if (containerCssClass.indexOf(':all:') !== -1) {
|
|
|
+ containerCssClass = containerCssClass.replace(':all', '');
|
|
|
+
|
|
|
+ var _cssAdapter = containerCssAdapter;
|
|
|
+
|
|
|
+ containerCssAdapter = function (clazz) {
|
|
|
+ var adapted = _cssAdapter(clazz);
|
|
|
+
|
|
|
+ if (adapted != null) {
|
|
|
+ // Append the old one along with the adapted one
|
|
|
+ return adapted + ' ' + clazz;
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- if (matcher(params.term, data.text, data)) {
|
|
|
- return match;
|
|
|
- }
|
|
|
+ return clazz;
|
|
|
+ };
|
|
|
+ }
|
|
|
|
|
|
- return null;
|
|
|
+ var containerCss = this.options.get('containerCss') || {};
|
|
|
+
|
|
|
+ if ($.isFunction(containerCss)) {
|
|
|
+ containerCss = containerCss(this.$element);
|
|
|
}
|
|
|
|
|
|
- return wrappedMatcher;
|
|
|
+ CompatUtils.syncCssClasses($container, this.$element, containerCssAdapter);
|
|
|
+
|
|
|
+ $container.css(containerCss);
|
|
|
+ $container.addClass(containerCssClass);
|
|
|
+
|
|
|
+ return $container;
|
|
|
+ };
|
|
|
+
|
|
|
+ return ContainerCSS;
|
|
|
+});
|
|
|
+
|
|
|
+S2.define('select2/compat/dropdownCss',[
|
|
|
+ 'jquery',
|
|
|
+ './utils'
|
|
|
+], function ($, CompatUtils) {
|
|
|
+ // No-op CSS adapter that discards all classes by default
|
|
|
+ function _dropdownAdapter (clazz) {
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
- return oldMatcher;
|
|
|
+ function DropdownCSS () { }
|
|
|
+
|
|
|
+ DropdownCSS.prototype.render = function (decorated) {
|
|
|
+ var $dropdown = decorated.call(this);
|
|
|
+
|
|
|
+ var dropdownCssClass = this.options.get('dropdownCssClass') || '';
|
|
|
+
|
|
|
+ if ($.isFunction(dropdownCssClass)) {
|
|
|
+ dropdownCssClass = dropdownCssClass(this.$element);
|
|
|
+ }
|
|
|
+
|
|
|
+ var dropdownCssAdapter = this.options.get('adaptDropdownCssClass');
|
|
|
+ dropdownCssAdapter = dropdownCssAdapter || _dropdownAdapter;
|
|
|
+
|
|
|
+ if (dropdownCssClass.indexOf(':all:') !== -1) {
|
|
|
+ dropdownCssClass = dropdownCssClass.replace(':all', '');
|
|
|
+
|
|
|
+ var _cssAdapter = dropdownCssAdapter;
|
|
|
+
|
|
|
+ dropdownCssAdapter = function (clazz) {
|
|
|
+ var adapted = _cssAdapter(clazz);
|
|
|
+
|
|
|
+ if (adapted != null) {
|
|
|
+ // Append the old one along with the adapted one
|
|
|
+ return adapted + ' ' + clazz;
|
|
|
+ }
|
|
|
+
|
|
|
+ return clazz;
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ var dropdownCss = this.options.get('dropdownCss') || {};
|
|
|
+
|
|
|
+ if ($.isFunction(dropdownCss)) {
|
|
|
+ dropdownCss = dropdownCss(this.$element);
|
|
|
+ }
|
|
|
+
|
|
|
+ CompatUtils.syncCssClasses($dropdown, this.$element, dropdownCssAdapter);
|
|
|
+
|
|
|
+ $dropdown.css(dropdownCss);
|
|
|
+ $dropdown.addClass(dropdownCssClass);
|
|
|
+
|
|
|
+ return $dropdown;
|
|
|
+ };
|
|
|
+
|
|
|
+ return DropdownCSS;
|
|
|
});
|
|
|
|
|
|
S2.define('select2/compat/initSelection',[
|
|
@@ -5468,8 +5636,8 @@ S2.define('select2/compat/inputData',[
|
|
|
};
|
|
|
|
|
|
InputData.prototype.addOptions = function (_, $options) {
|
|
|
- var options = $.map($options, function (option) {
|
|
|
- return $.data(option, 'data');
|
|
|
+ var options = $.map($options, function ($option) {
|
|
|
+ return $.data($option[0], 'data');
|
|
|
});
|
|
|
|
|
|
this._currentData.push.apply(this._currentData, options);
|
|
@@ -5478,6 +5646,49 @@ S2.define('select2/compat/inputData',[
|
|
|
return InputData;
|
|
|
});
|
|
|
|
|
|
+S2.define('select2/compat/matcher',[
|
|
|
+ 'jquery'
|
|
|
+], function ($) {
|
|
|
+ function oldMatcher (matcher) {
|
|
|
+ function wrappedMatcher (params, data) {
|
|
|
+ var match = $.extend(true, {}, data);
|
|
|
+
|
|
|
+ if (params.term == null || $.trim(params.term) === '') {
|
|
|
+ return match;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (data.children) {
|
|
|
+ for (var c = data.children.length - 1; c >= 0; c--) {
|
|
|
+ var child = data.children[c];
|
|
|
+
|
|
|
+ // Check if the child object matches
|
|
|
+ // The old matcher returned a boolean true or false
|
|
|
+ var doesMatch = matcher(params.term, child.text, child);
|
|
|
+
|
|
|
+ // If the child didn't match, pop it off
|
|
|
+ if (!doesMatch) {
|
|
|
+ match.children.splice(c, 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (match.children.length > 0) {
|
|
|
+ return match;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (matcher(params.term, data.text, data)) {
|
|
|
+ return match;
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ return wrappedMatcher;
|
|
|
+ }
|
|
|
+
|
|
|
+ return oldMatcher;
|
|
|
+});
|
|
|
+
|
|
|
S2.define('select2/compat/query',[
|
|
|
|
|
|
], function () {
|