|
@@ -1,5 +1,5 @@
|
|
/*!
|
|
/*!
|
|
- * Select2 4.0.13
|
|
|
|
|
|
+ * Select2 4.1.0-beta.0
|
|
* https://select2.github.io
|
|
* https://select2.github.io
|
|
*
|
|
*
|
|
* Released under the MIT license
|
|
* Released under the MIT license
|
|
@@ -755,23 +755,6 @@ 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);
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
// Cache objects in Utils.__cache instead of $.data (see #4346)
|
|
// Cache objects in Utils.__cache instead of $.data (see #4346)
|
|
Utils.__cache = {};
|
|
Utils.__cache = {};
|
|
|
|
|
|
@@ -836,6 +819,28 @@ S2.define('select2/utils',[
|
|
element.removeAttribute('data-select2-id');
|
|
element.removeAttribute('data-select2-id');
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ Utils.copyNonInternalCssClasses = function (dest, src) {
|
|
|
|
+ var classes;
|
|
|
|
+
|
|
|
|
+ var destinationClasses = dest.getAttribute('class').trim().split(/\s+/);
|
|
|
|
+
|
|
|
|
+ destinationClasses = destinationClasses.filter(function (clazz) {
|
|
|
|
+ // Save all Select2 classes
|
|
|
|
+ return clazz.indexOf('select2-') === 0;
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ var sourceClasses = src.getAttribute('class').trim().split(/\s+/);
|
|
|
|
+
|
|
|
|
+ sourceClasses = sourceClasses.filter(function (clazz) {
|
|
|
|
+ // Only copy non-Select2 classes
|
|
|
|
+ return clazz.indexOf('select2-') !== 0;
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ var replacements = destinationClasses.concat(sourceClasses);
|
|
|
|
+
|
|
|
|
+ dest.setAttribute('class', replacements.join(' '));
|
|
|
|
+ };
|
|
|
|
+
|
|
return Utils;
|
|
return Utils;
|
|
});
|
|
});
|
|
|
|
|
|
@@ -961,7 +966,7 @@ S2.define('select2/results',[
|
|
var self = this;
|
|
var self = this;
|
|
|
|
|
|
this.data.current(function (selected) {
|
|
this.data.current(function (selected) {
|
|
- var selectedIds = $.map(selected, function (s) {
|
|
|
|
|
|
+ var selectedIds = selected.map(function (s) {
|
|
return s.id.toString();
|
|
return s.id.toString();
|
|
});
|
|
});
|
|
|
|
|
|
@@ -977,7 +982,7 @@ S2.define('select2/results',[
|
|
var id = '' + item.id;
|
|
var id = '' + item.id;
|
|
|
|
|
|
if ((item.element != null && item.element.selected) ||
|
|
if ((item.element != null && item.element.selected) ||
|
|
- (item.element == null && $.inArray(id, selectedIds) > -1)) {
|
|
|
|
|
|
+ (item.element == null && selectedIds.indexOf(id) > -1)) {
|
|
$option.attr('aria-selected', 'true');
|
|
$option.attr('aria-selected', 'true');
|
|
} else {
|
|
} else {
|
|
$option.attr('aria-selected', 'false');
|
|
$option.attr('aria-selected', 'false');
|
|
@@ -1250,7 +1255,7 @@ S2.define('select2/results',[
|
|
});
|
|
});
|
|
|
|
|
|
container.on('results:focus', function (params) {
|
|
container.on('results:focus', function (params) {
|
|
- params.element.addClass('select2-results__option--highlighted');
|
|
|
|
|
|
+ params.element[0].classList.add('select2-results__option--highlighted');
|
|
});
|
|
});
|
|
|
|
|
|
container.on('results:message', function (params) {
|
|
container.on('results:message', function (params) {
|
|
@@ -1595,7 +1600,7 @@ S2.define('select2/selection/single',[
|
|
SingleSelection.prototype.render = function () {
|
|
SingleSelection.prototype.render = function () {
|
|
var $selection = SingleSelection.__super__.render.call(this);
|
|
var $selection = SingleSelection.__super__.render.call(this);
|
|
|
|
|
|
- $selection.addClass('select2-selection--single');
|
|
|
|
|
|
+ $selection[0].classList.add('select2-selection--single');
|
|
|
|
|
|
$selection.html(
|
|
$selection.html(
|
|
'<span class="select2-selection__rendered"></span>' +
|
|
'<span class="select2-selection__rendered"></span>' +
|
|
@@ -1702,7 +1707,7 @@ S2.define('select2/selection/multiple',[
|
|
MultipleSelection.prototype.render = function () {
|
|
MultipleSelection.prototype.render = function () {
|
|
var $selection = MultipleSelection.__super__.render.call(this);
|
|
var $selection = MultipleSelection.__super__.render.call(this);
|
|
|
|
|
|
- $selection.addClass('select2-selection--multiple');
|
|
|
|
|
|
+ $selection[0].classList.add('select2-selection--multiple');
|
|
|
|
|
|
$selection.html(
|
|
$selection.html(
|
|
'<ul class="select2-selection__rendered"></ul>'
|
|
'<ul class="select2-selection__rendered"></ul>'
|
|
@@ -1799,15 +1804,15 @@ S2.define('select2/selection/multiple',[
|
|
|
|
|
|
var $rendered = this.$selection.find('.select2-selection__rendered');
|
|
var $rendered = this.$selection.find('.select2-selection__rendered');
|
|
|
|
|
|
- Utils.appendMany($rendered, $selections);
|
|
|
|
|
|
+ $rendered.append($selections);
|
|
};
|
|
};
|
|
|
|
|
|
return MultipleSelection;
|
|
return MultipleSelection;
|
|
});
|
|
});
|
|
|
|
|
|
S2.define('select2/selection/placeholder',[
|
|
S2.define('select2/selection/placeholder',[
|
|
- '../utils'
|
|
|
|
-], function (Utils) {
|
|
|
|
|
|
+
|
|
|
|
+], function () {
|
|
function Placeholder (decorated, $element, options) {
|
|
function Placeholder (decorated, $element, options) {
|
|
this.placeholder = this.normalizePlaceholder(options.get('placeholder'));
|
|
this.placeholder = this.normalizePlaceholder(options.get('placeholder'));
|
|
|
|
|
|
@@ -1829,8 +1834,8 @@ S2.define('select2/selection/placeholder',[
|
|
var $placeholder = this.selectionContainer();
|
|
var $placeholder = this.selectionContainer();
|
|
|
|
|
|
$placeholder.html(this.display(placeholder));
|
|
$placeholder.html(this.display(placeholder));
|
|
- $placeholder.addClass('select2-selection__placeholder')
|
|
|
|
- .removeClass('select2-selection__choice');
|
|
|
|
|
|
+ $placeholder[0].classList.add('select2-selection__placeholder');
|
|
|
|
+ $placeholder[0].classList.remove('select2-selection__choice');
|
|
|
|
|
|
return $placeholder;
|
|
return $placeholder;
|
|
};
|
|
};
|
|
@@ -2206,6 +2211,30 @@ S2.define('select2/selection/search',[
|
|
return Search;
|
|
return Search;
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+S2.define('select2/selection/selectionCss',[
|
|
|
|
+ '../utils'
|
|
|
|
+], function (Utils) {
|
|
|
|
+ function SelectionCSS () { }
|
|
|
|
+
|
|
|
|
+ SelectionCSS.prototype.render = function (decorated) {
|
|
|
|
+ var $selection = decorated.call(this);
|
|
|
|
+
|
|
|
|
+ var selectionCssClass = this.options.get('selectionCssClass') || '';
|
|
|
|
+
|
|
|
|
+ if (selectionCssClass.indexOf(':all:') !== -1) {
|
|
|
|
+ selectionCssClass = selectionCssClass.replace(':all:', '');
|
|
|
|
+
|
|
|
|
+ Utils.copyNonInternalCssClasses($selection[0], this.$element[0]);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $selection.addClass(selectionCssClass);
|
|
|
|
+
|
|
|
|
+ return $selection;
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ return SelectionCSS;
|
|
|
|
+});
|
|
|
|
+
|
|
S2.define('select2/selection/eventRelay',[
|
|
S2.define('select2/selection/eventRelay',[
|
|
'jquery'
|
|
'jquery'
|
|
], function ($) {
|
|
], function ($) {
|
|
@@ -2229,7 +2258,7 @@ S2.define('select2/selection/eventRelay',[
|
|
|
|
|
|
container.on('*', function (name, params) {
|
|
container.on('*', function (name, params) {
|
|
// Ignore events that should not be relayed
|
|
// Ignore events that should not be relayed
|
|
- if ($.inArray(name, relayEvents) === -1) {
|
|
|
|
|
|
+ if (relayEvents.indexOf(name) === -1) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -2244,7 +2273,7 @@ S2.define('select2/selection/eventRelay',[
|
|
self.$element.trigger(evt);
|
|
self.$element.trigger(evt);
|
|
|
|
|
|
// Only handle preventable events if it was one
|
|
// Only handle preventable events if it was one
|
|
- if ($.inArray(name, preventableEvents) === -1) {
|
|
|
|
|
|
+ if (preventableEvents.indexOf(name) === -1) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -3199,16 +3228,14 @@ S2.define('select2/data/select',[
|
|
Utils.Extend(SelectAdapter, BaseAdapter);
|
|
Utils.Extend(SelectAdapter, BaseAdapter);
|
|
|
|
|
|
SelectAdapter.prototype.current = function (callback) {
|
|
SelectAdapter.prototype.current = function (callback) {
|
|
- var data = [];
|
|
|
|
var self = this;
|
|
var self = this;
|
|
|
|
|
|
- this.$element.find(':selected').each(function () {
|
|
|
|
- var $option = $(this);
|
|
|
|
-
|
|
|
|
- var option = self.item($option);
|
|
|
|
-
|
|
|
|
- data.push(option);
|
|
|
|
- });
|
|
|
|
|
|
+ var data = Array.prototype.map.call(
|
|
|
|
+ this.$element[0].querySelectorAll(':checked'),
|
|
|
|
+ function (selectedElement) {
|
|
|
|
+ return self.item($(selectedElement));
|
|
|
|
+ }
|
|
|
|
+ );
|
|
|
|
|
|
callback(data);
|
|
callback(data);
|
|
};
|
|
};
|
|
@@ -3219,7 +3246,9 @@ S2.define('select2/data/select',[
|
|
data.selected = true;
|
|
data.selected = true;
|
|
|
|
|
|
// If data.element is a DOM node, use it instead
|
|
// If data.element is a DOM node, use it instead
|
|
- if ($(data.element).is('option')) {
|
|
|
|
|
|
+ if (
|
|
|
|
+ data.element != null && data.element.tagName.toLowerCase() === 'option'
|
|
|
|
+ ) {
|
|
data.element.selected = true;
|
|
data.element.selected = true;
|
|
|
|
|
|
this.$element.trigger('input').trigger('change');
|
|
this.$element.trigger('input').trigger('change');
|
|
@@ -3237,7 +3266,7 @@ S2.define('select2/data/select',[
|
|
for (var d = 0; d < data.length; d++) {
|
|
for (var d = 0; d < data.length; d++) {
|
|
var id = data[d].id;
|
|
var id = data[d].id;
|
|
|
|
|
|
- if ($.inArray(id, val) === -1) {
|
|
|
|
|
|
+ if (val.indexOf(id) === -1) {
|
|
val.push(id);
|
|
val.push(id);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -3262,7 +3291,10 @@ S2.define('select2/data/select',[
|
|
|
|
|
|
data.selected = false;
|
|
data.selected = false;
|
|
|
|
|
|
- if ($(data.element).is('option')) {
|
|
|
|
|
|
+ if (
|
|
|
|
+ data.element != null &&
|
|
|
|
+ data.element.tagName.toLowerCase() === 'option'
|
|
|
|
+ ) {
|
|
data.element.selected = false;
|
|
data.element.selected = false;
|
|
|
|
|
|
this.$element.trigger('input').trigger('change');
|
|
this.$element.trigger('input').trigger('change');
|
|
@@ -3276,7 +3308,7 @@ S2.define('select2/data/select',[
|
|
for (var d = 0; d < currentData.length; d++) {
|
|
for (var d = 0; d < currentData.length; d++) {
|
|
var id = currentData[d].id;
|
|
var id = currentData[d].id;
|
|
|
|
|
|
- if (id !== data.id && $.inArray(id, val) === -1) {
|
|
|
|
|
|
+ if (id !== data.id && val.indexOf(id) === -1) {
|
|
val.push(id);
|
|
val.push(id);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -3316,12 +3348,15 @@ S2.define('select2/data/select',[
|
|
var $options = this.$element.children();
|
|
var $options = this.$element.children();
|
|
|
|
|
|
$options.each(function () {
|
|
$options.each(function () {
|
|
- var $option = $(this);
|
|
|
|
-
|
|
|
|
- if (!$option.is('option') && !$option.is('optgroup')) {
|
|
|
|
|
|
+ if (
|
|
|
|
+ this.tagName.toLowerCase() !== 'option' &&
|
|
|
|
+ this.tagName.toLowerCase() !== 'optgroup'
|
|
|
|
+ ) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ var $option = $(this);
|
|
|
|
+
|
|
var option = self.item($option);
|
|
var option = self.item($option);
|
|
|
|
|
|
var matches = self.matches(params, option);
|
|
var matches = self.matches(params, option);
|
|
@@ -3337,7 +3372,7 @@ S2.define('select2/data/select',[
|
|
};
|
|
};
|
|
|
|
|
|
SelectAdapter.prototype.addOptions = function ($options) {
|
|
SelectAdapter.prototype.addOptions = function ($options) {
|
|
- Utils.appendMany(this.$element, $options);
|
|
|
|
|
|
+ this.$element.append($options);
|
|
};
|
|
};
|
|
|
|
|
|
SelectAdapter.prototype.option = function (data) {
|
|
SelectAdapter.prototype.option = function (data) {
|
|
@@ -3372,15 +3407,13 @@ S2.define('select2/data/select',[
|
|
option.title = data.title;
|
|
option.title = data.title;
|
|
}
|
|
}
|
|
|
|
|
|
- var $option = $(option);
|
|
|
|
-
|
|
|
|
var normalizedData = this._normalizeItem(data);
|
|
var normalizedData = this._normalizeItem(data);
|
|
normalizedData.element = option;
|
|
normalizedData.element = option;
|
|
|
|
|
|
// Override the option's data with the combined data
|
|
// Override the option's data with the combined data
|
|
Utils.StoreData(option, 'data', normalizedData);
|
|
Utils.StoreData(option, 'data', normalizedData);
|
|
|
|
|
|
- return $option;
|
|
|
|
|
|
+ return $(option);
|
|
};
|
|
};
|
|
|
|
|
|
SelectAdapter.prototype.item = function ($option) {
|
|
SelectAdapter.prototype.item = function ($option) {
|
|
@@ -3392,7 +3425,9 @@ S2.define('select2/data/select',[
|
|
return data;
|
|
return data;
|
|
}
|
|
}
|
|
|
|
|
|
- if ($option.is('option')) {
|
|
|
|
|
|
+ var option = $option[0];
|
|
|
|
+
|
|
|
|
+ if (option.tagName.toLowerCase() === 'option') {
|
|
data = {
|
|
data = {
|
|
id: $option.val(),
|
|
id: $option.val(),
|
|
text: $option.text(),
|
|
text: $option.text(),
|
|
@@ -3400,7 +3435,7 @@ S2.define('select2/data/select',[
|
|
selected: $option.prop('selected'),
|
|
selected: $option.prop('selected'),
|
|
title: $option.prop('title')
|
|
title: $option.prop('title')
|
|
};
|
|
};
|
|
- } else if ($option.is('optgroup')) {
|
|
|
|
|
|
+ } else if (option.tagName.toLowerCase() === 'optgroup') {
|
|
data = {
|
|
data = {
|
|
text: $option.prop('label'),
|
|
text: $option.prop('label'),
|
|
children: [],
|
|
children: [],
|
|
@@ -3524,7 +3559,7 @@ S2.define('select2/data/array',[
|
|
var item = this._normalizeItem(data[d]);
|
|
var item = this._normalizeItem(data[d]);
|
|
|
|
|
|
// Skip items which were pre-loaded, only merge the data
|
|
// Skip items which were pre-loaded, only merge the data
|
|
- if ($.inArray(item.id, existingIds) >= 0) {
|
|
|
|
|
|
+ if (existingIds.indexOf(item.id) >= 0) {
|
|
var $existingOption = $existing.filter(onlyItem(item));
|
|
var $existingOption = $existing.filter(onlyItem(item));
|
|
|
|
|
|
var existingData = this.item($existingOption);
|
|
var existingData = this.item($existingOption);
|
|
@@ -3542,7 +3577,7 @@ S2.define('select2/data/array',[
|
|
if (item.children) {
|
|
if (item.children) {
|
|
var $children = this.convertToOptions(item.children);
|
|
var $children = this.convertToOptions(item.children);
|
|
|
|
|
|
- Utils.appendMany($option, $children);
|
|
|
|
|
|
+ $option.append($children);
|
|
}
|
|
}
|
|
|
|
|
|
$options.push($option);
|
|
$options.push($option);
|
|
@@ -3626,7 +3661,7 @@ S2.define('select2/data/ajax',[
|
|
|
|
|
|
if (self.options.get('debug') && window.console && console.error) {
|
|
if (self.options.get('debug') && window.console && console.error) {
|
|
// Check to make sure that the response included a `results` key.
|
|
// Check to make sure that the response included a `results` key.
|
|
- if (!results || !results.results || !$.isArray(results.results)) {
|
|
|
|
|
|
+ if (!results || !results.results || !Array.isArray(results.results)) {
|
|
console.error(
|
|
console.error(
|
|
'Select2: The AJAX results did not return an array in the ' +
|
|
'Select2: The AJAX results did not return an array in the ' +
|
|
'`results` key of the response.'
|
|
'`results` key of the response.'
|
|
@@ -3685,7 +3720,7 @@ S2.define('select2/data/tags',[
|
|
|
|
|
|
decorated.call(this, $element, options);
|
|
decorated.call(this, $element, options);
|
|
|
|
|
|
- if ($.isArray(tags)) {
|
|
|
|
|
|
+ if (Array.isArray(tags)) {
|
|
for (var t = 0; t < tags.length; t++) {
|
|
for (var t = 0; t < tags.length; t++) {
|
|
var tag = tags[t];
|
|
var tag = tags[t];
|
|
var item = this._normalizeItem(tag);
|
|
var item = this._normalizeItem(tag);
|
|
@@ -3761,7 +3796,11 @@ S2.define('select2/data/tags',[
|
|
};
|
|
};
|
|
|
|
|
|
Tags.prototype.createTag = function (decorated, params) {
|
|
Tags.prototype.createTag = function (decorated, params) {
|
|
- var term = $.trim(params.term);
|
|
|
|
|
|
+ if (params.term == null) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var term = params.term.trim();
|
|
|
|
|
|
if (term === '') {
|
|
if (term === '') {
|
|
return null;
|
|
return null;
|
|
@@ -3876,7 +3915,7 @@ S2.define('select2/data/tokenizer',[
|
|
while (i < term.length) {
|
|
while (i < term.length) {
|
|
var termChar = term[i];
|
|
var termChar = term[i];
|
|
|
|
|
|
- if ($.inArray(termChar, separators) === -1) {
|
|
|
|
|
|
+ if (separators.indexOf(termChar) === -1) {
|
|
i++;
|
|
i++;
|
|
|
|
|
|
continue;
|
|
continue;
|
|
@@ -4071,9 +4110,8 @@ S2.define('select2/dropdown',[
|
|
});
|
|
});
|
|
|
|
|
|
S2.define('select2/dropdown/search',[
|
|
S2.define('select2/dropdown/search',[
|
|
- 'jquery',
|
|
|
|
- '../utils'
|
|
|
|
-], function ($, Utils) {
|
|
|
|
|
|
+ 'jquery'
|
|
|
|
+], function ($) {
|
|
function Search () { }
|
|
function Search () { }
|
|
|
|
|
|
Search.prototype.render = function (decorated) {
|
|
Search.prototype.render = function (decorated) {
|
|
@@ -4151,9 +4189,9 @@ S2.define('select2/dropdown/search',[
|
|
var showSearch = self.showSearch(params);
|
|
var showSearch = self.showSearch(params);
|
|
|
|
|
|
if (showSearch) {
|
|
if (showSearch) {
|
|
- self.$searchContainer.removeClass('select2-search--hide');
|
|
|
|
|
|
+ self.$searchContainer[0].classList.remove('select2-search--hide');
|
|
} else {
|
|
} else {
|
|
- self.$searchContainer.addClass('select2-search--hide');
|
|
|
|
|
|
+ self.$searchContainer[0].classList.add('select2-search--hide');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|
|
@@ -4365,8 +4403,8 @@ S2.define('select2/dropdown/attachBody',[
|
|
// Clone all of the container classes
|
|
// Clone all of the container classes
|
|
$dropdown.attr('class', $container.attr('class'));
|
|
$dropdown.attr('class', $container.attr('class'));
|
|
|
|
|
|
- $dropdown.removeClass('select2');
|
|
|
|
- $dropdown.addClass('select2-container--open');
|
|
|
|
|
|
+ $dropdown[0].classList.remove('select2');
|
|
|
|
+ $dropdown[0].classList.add('select2-container--open');
|
|
|
|
|
|
$dropdown.css({
|
|
$dropdown.css({
|
|
position: 'absolute',
|
|
position: 'absolute',
|
|
@@ -4472,8 +4510,10 @@ S2.define('select2/dropdown/attachBody',[
|
|
AttachBody.prototype._positionDropdown = function () {
|
|
AttachBody.prototype._positionDropdown = function () {
|
|
var $window = $(window);
|
|
var $window = $(window);
|
|
|
|
|
|
- var isCurrentlyAbove = this.$dropdown.hasClass('select2-dropdown--above');
|
|
|
|
- var isCurrentlyBelow = this.$dropdown.hasClass('select2-dropdown--below');
|
|
|
|
|
|
+ var isCurrentlyAbove = this.$dropdown[0].classList
|
|
|
|
+ .contains('select2-dropdown--above');
|
|
|
|
+ var isCurrentlyBelow = this.$dropdown[0].classList
|
|
|
|
+ .contains('select2-dropdown--below');
|
|
|
|
|
|
var newDirection = null;
|
|
var newDirection = null;
|
|
|
|
|
|
@@ -4545,12 +4585,13 @@ S2.define('select2/dropdown/attachBody',[
|
|
}
|
|
}
|
|
|
|
|
|
if (newDirection != null) {
|
|
if (newDirection != null) {
|
|
- this.$dropdown
|
|
|
|
- .removeClass('select2-dropdown--below select2-dropdown--above')
|
|
|
|
- .addClass('select2-dropdown--' + newDirection);
|
|
|
|
- this.$container
|
|
|
|
- .removeClass('select2-container--below select2-container--above')
|
|
|
|
- .addClass('select2-container--' + newDirection);
|
|
|
|
|
|
+ this.$dropdown[0].classList.remove('select2-dropdown--below');
|
|
|
|
+ this.$dropdown[0].classList.remove('select2-dropdown--above');
|
|
|
|
+ this.$dropdown[0].classList.add('select2-dropdown--' + newDirection);
|
|
|
|
+
|
|
|
|
+ this.$container[0].classList.remove('select2-container--below');
|
|
|
|
+ this.$container[0].classList.remove('select2-container--above');
|
|
|
|
+ this.$container[0].classList.add('select2-container--' + newDirection);
|
|
}
|
|
}
|
|
|
|
|
|
this.$dropdownContainer.css(css);
|
|
this.$dropdownContainer.css(css);
|
|
@@ -4707,6 +4748,30 @@ S2.define('select2/dropdown/closeOnSelect',[
|
|
return CloseOnSelect;
|
|
return CloseOnSelect;
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+S2.define('select2/dropdown/dropdownCss',[
|
|
|
|
+ '../utils'
|
|
|
|
+], function (Utils) {
|
|
|
|
+ function DropdownCSS () { }
|
|
|
|
+
|
|
|
|
+ DropdownCSS.prototype.render = function (decorated) {
|
|
|
|
+ var $dropdown = decorated.call(this);
|
|
|
|
+
|
|
|
|
+ var dropdownCssClass = this.options.get('dropdownCssClass') || '';
|
|
|
|
+
|
|
|
|
+ if (dropdownCssClass.indexOf(':all:') !== -1) {
|
|
|
|
+ dropdownCssClass = dropdownCssClass.replace(':all:', '');
|
|
|
|
+
|
|
|
|
+ Utils.copyNonInternalCssClasses($dropdown[0], this.$element[0]);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $dropdown.addClass(dropdownCssClass);
|
|
|
|
+
|
|
|
|
+ return $dropdown;
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ return DropdownCSS;
|
|
|
|
+});
|
|
|
|
+
|
|
S2.define('select2/i18n/en',[],function () {
|
|
S2.define('select2/i18n/en',[],function () {
|
|
// English
|
|
// English
|
|
return {
|
|
return {
|
|
@@ -4757,7 +4822,6 @@ S2.define('select2/i18n/en',[],function () {
|
|
|
|
|
|
S2.define('select2/defaults',[
|
|
S2.define('select2/defaults',[
|
|
'jquery',
|
|
'jquery',
|
|
- 'require',
|
|
|
|
|
|
|
|
'./results',
|
|
'./results',
|
|
|
|
|
|
@@ -4766,6 +4830,7 @@ S2.define('select2/defaults',[
|
|
'./selection/placeholder',
|
|
'./selection/placeholder',
|
|
'./selection/allowClear',
|
|
'./selection/allowClear',
|
|
'./selection/search',
|
|
'./selection/search',
|
|
|
|
+ './selection/selectionCss',
|
|
'./selection/eventRelay',
|
|
'./selection/eventRelay',
|
|
|
|
|
|
'./utils',
|
|
'./utils',
|
|
@@ -4789,14 +4854,15 @@ S2.define('select2/defaults',[
|
|
'./dropdown/minimumResultsForSearch',
|
|
'./dropdown/minimumResultsForSearch',
|
|
'./dropdown/selectOnClose',
|
|
'./dropdown/selectOnClose',
|
|
'./dropdown/closeOnSelect',
|
|
'./dropdown/closeOnSelect',
|
|
|
|
+ './dropdown/dropdownCss',
|
|
|
|
|
|
'./i18n/en'
|
|
'./i18n/en'
|
|
-], function ($, require,
|
|
|
|
|
|
+], function ($,
|
|
|
|
|
|
ResultsList,
|
|
ResultsList,
|
|
|
|
|
|
SingleSelection, MultipleSelection, Placeholder, AllowClear,
|
|
SingleSelection, MultipleSelection, Placeholder, AllowClear,
|
|
- SelectionSearch, EventRelay,
|
|
|
|
|
|
+ SelectionSearch, SelectionCSS, EventRelay,
|
|
|
|
|
|
Utils, Translation, DIACRITICS,
|
|
Utils, Translation, DIACRITICS,
|
|
|
|
|
|
@@ -4805,6 +4871,7 @@ S2.define('select2/defaults',[
|
|
|
|
|
|
Dropdown, DropdownSearch, HidePlaceholder, InfiniteScroll,
|
|
Dropdown, DropdownSearch, HidePlaceholder, InfiniteScroll,
|
|
AttachBody, MinimumResultsForSearch, SelectOnClose, CloseOnSelect,
|
|
AttachBody, MinimumResultsForSearch, SelectOnClose, CloseOnSelect,
|
|
|
|
+ DropdownCSS,
|
|
|
|
|
|
EnglishTranslation) {
|
|
EnglishTranslation) {
|
|
function Defaults () {
|
|
function Defaults () {
|
|
@@ -4854,24 +4921,6 @@ S2.define('select2/defaults',[
|
|
Tokenizer
|
|
Tokenizer
|
|
);
|
|
);
|
|
}
|
|
}
|
|
-
|
|
|
|
- if (options.query != null) {
|
|
|
|
- var Query = require(options.amdBase + 'compat/query');
|
|
|
|
-
|
|
|
|
- options.dataAdapter = Utils.Decorate(
|
|
|
|
- options.dataAdapter,
|
|
|
|
- Query
|
|
|
|
- );
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (options.initSelection != null) {
|
|
|
|
- var InitSelection = require(options.amdBase + 'compat/initSelection');
|
|
|
|
-
|
|
|
|
- options.dataAdapter = Utils.Decorate(
|
|
|
|
- options.dataAdapter,
|
|
|
|
- InitSelection
|
|
|
|
- );
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
if (options.resultsAdapter == null) {
|
|
if (options.resultsAdapter == null) {
|
|
@@ -4927,8 +4976,6 @@ S2.define('select2/defaults',[
|
|
options.dropdownCss != null ||
|
|
options.dropdownCss != null ||
|
|
options.adaptDropdownCssClass != null
|
|
options.adaptDropdownCssClass != null
|
|
) {
|
|
) {
|
|
- var DropdownCSS = require(options.amdBase + 'compat/dropdownCss');
|
|
|
|
-
|
|
|
|
options.dropdownAdapter = Utils.Decorate(
|
|
options.dropdownAdapter = Utils.Decorate(
|
|
options.dropdownAdapter,
|
|
options.dropdownAdapter,
|
|
DropdownCSS
|
|
DropdownCSS
|
|
@@ -4975,11 +5022,9 @@ S2.define('select2/defaults',[
|
|
options.containerCss != null ||
|
|
options.containerCss != null ||
|
|
options.adaptContainerCssClass != null
|
|
options.adaptContainerCssClass != null
|
|
) {
|
|
) {
|
|
- var ContainerCSS = require(options.amdBase + 'compat/containerCss');
|
|
|
|
-
|
|
|
|
options.selectionAdapter = Utils.Decorate(
|
|
options.selectionAdapter = Utils.Decorate(
|
|
options.selectionAdapter,
|
|
options.selectionAdapter,
|
|
- ContainerCSS
|
|
|
|
|
|
+ SelectionCSS
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -5028,7 +5073,7 @@ S2.define('select2/defaults',[
|
|
|
|
|
|
function matcher (params, data) {
|
|
function matcher (params, data) {
|
|
// Always return the object if there is nothing to compare
|
|
// Always return the object if there is nothing to compare
|
|
- if ($.trim(params.term) === '') {
|
|
|
|
|
|
+ if (params.term == null || params.term.trim() === '') {
|
|
return data;
|
|
return data;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -5072,7 +5117,6 @@ S2.define('select2/defaults',[
|
|
}
|
|
}
|
|
|
|
|
|
this.defaults = {
|
|
this.defaults = {
|
|
- amdBase: './',
|
|
|
|
amdLanguageBase: './i18n/',
|
|
amdLanguageBase: './i18n/',
|
|
closeOnSelect: true,
|
|
closeOnSelect: true,
|
|
debug: false,
|
|
debug: false,
|
|
@@ -5133,7 +5177,7 @@ S2.define('select2/defaults',[
|
|
|
|
|
|
var languages;
|
|
var languages;
|
|
|
|
|
|
- if (!$.isArray(language)) {
|
|
|
|
|
|
+ if (!Array.isArray(language)) {
|
|
languages = [language];
|
|
languages = [language];
|
|
} else {
|
|
} else {
|
|
languages = language;
|
|
languages = language;
|
|
@@ -5214,11 +5258,10 @@ S2.define('select2/defaults',[
|
|
});
|
|
});
|
|
|
|
|
|
S2.define('select2/options',[
|
|
S2.define('select2/options',[
|
|
- 'require',
|
|
|
|
'jquery',
|
|
'jquery',
|
|
'./defaults',
|
|
'./defaults',
|
|
'./utils'
|
|
'./utils'
|
|
-], function (require, $, Defaults, Utils) {
|
|
|
|
|
|
+], function ($, Defaults, Utils) {
|
|
function Options (options, $element) {
|
|
function Options (options, $element) {
|
|
this.options = options;
|
|
this.options = options;
|
|
|
|
|
|
@@ -5231,15 +5274,6 @@ S2.define('select2/options',[
|
|
}
|
|
}
|
|
|
|
|
|
this.options = Defaults.apply(this.options);
|
|
this.options = Defaults.apply(this.options);
|
|
-
|
|
|
|
- if ($element && $element.is('input')) {
|
|
|
|
- var InputCompat = require(this.get('amdBase') + 'compat/inputData');
|
|
|
|
-
|
|
|
|
- this.options.dataAdapter = Utils.Decorate(
|
|
|
|
- this.options.dataAdapter,
|
|
|
|
- InputCompat
|
|
|
|
- );
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
Options.prototype.fromElement = function ($e) {
|
|
Options.prototype.fromElement = function ($e) {
|
|
@@ -5331,7 +5365,7 @@ S2.define('select2/options',[
|
|
data = Utils._convertData(data);
|
|
data = Utils._convertData(data);
|
|
|
|
|
|
for (var key in data) {
|
|
for (var key in data) {
|
|
- if ($.inArray(key, excludedData) > -1) {
|
|
|
|
|
|
+ if (excludedData.indexOf(key) > -1) {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -5435,7 +5469,7 @@ S2.define('select2/core',[
|
|
});
|
|
});
|
|
|
|
|
|
// Hide the original select
|
|
// Hide the original select
|
|
- $element.addClass('select2-hidden-accessible');
|
|
|
|
|
|
+ $element[0].classList.add('select2-hidden-accessible');
|
|
$element.attr('aria-hidden', 'true');
|
|
$element.attr('aria-hidden', 'true');
|
|
|
|
|
|
// Synchronize any monitored attributes
|
|
// Synchronize any monitored attributes
|
|
@@ -5555,42 +5589,15 @@ S2.define('select2/core',[
|
|
this._syncA = Utils.bind(this._syncAttributes, this);
|
|
this._syncA = Utils.bind(this._syncAttributes, this);
|
|
this._syncS = Utils.bind(this._syncSubtree, this);
|
|
this._syncS = Utils.bind(this._syncSubtree, this);
|
|
|
|
|
|
- if (this.$element[0].attachEvent) {
|
|
|
|
- this.$element[0].attachEvent('onpropertychange', this._syncA);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- var observer = window.MutationObserver ||
|
|
|
|
- window.WebKitMutationObserver ||
|
|
|
|
- window.MozMutationObserver
|
|
|
|
- ;
|
|
|
|
-
|
|
|
|
- if (observer != null) {
|
|
|
|
- this._observer = new observer(function (mutations) {
|
|
|
|
- self._syncA();
|
|
|
|
- self._syncS(null, mutations);
|
|
|
|
- });
|
|
|
|
- this._observer.observe(this.$element[0], {
|
|
|
|
- attributes: true,
|
|
|
|
- childList: true,
|
|
|
|
- subtree: false
|
|
|
|
- });
|
|
|
|
- } else if (this.$element[0].addEventListener) {
|
|
|
|
- this.$element[0].addEventListener(
|
|
|
|
- 'DOMAttrModified',
|
|
|
|
- self._syncA,
|
|
|
|
- false
|
|
|
|
- );
|
|
|
|
- this.$element[0].addEventListener(
|
|
|
|
- 'DOMNodeInserted',
|
|
|
|
- self._syncS,
|
|
|
|
- false
|
|
|
|
- );
|
|
|
|
- this.$element[0].addEventListener(
|
|
|
|
- 'DOMNodeRemoved',
|
|
|
|
- self._syncS,
|
|
|
|
- false
|
|
|
|
- );
|
|
|
|
- }
|
|
|
|
|
|
+ this._observer = new window.MutationObserver(function (mutations) {
|
|
|
|
+ self._syncA();
|
|
|
|
+ self._syncS(mutations);
|
|
|
|
+ });
|
|
|
|
+ this._observer.observe(this.$element[0], {
|
|
|
|
+ attributes: true,
|
|
|
|
+ childList: true,
|
|
|
|
+ subtree: false
|
|
|
|
+ });
|
|
};
|
|
};
|
|
|
|
|
|
Select2.prototype._registerDataEvents = function () {
|
|
Select2.prototype._registerDataEvents = function () {
|
|
@@ -5614,7 +5621,7 @@ S2.define('select2/core',[
|
|
});
|
|
});
|
|
|
|
|
|
this.selection.on('*', function (name, params) {
|
|
this.selection.on('*', function (name, params) {
|
|
- if ($.inArray(name, nonRelayEvents) !== -1) {
|
|
|
|
|
|
+ if (nonRelayEvents.indexOf(name) !== -1) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -5642,23 +5649,23 @@ S2.define('select2/core',[
|
|
var self = this;
|
|
var self = this;
|
|
|
|
|
|
this.on('open', function () {
|
|
this.on('open', function () {
|
|
- self.$container.addClass('select2-container--open');
|
|
|
|
|
|
+ self.$container[0].classList.add('select2-container--open');
|
|
});
|
|
});
|
|
|
|
|
|
this.on('close', function () {
|
|
this.on('close', function () {
|
|
- self.$container.removeClass('select2-container--open');
|
|
|
|
|
|
+ self.$container[0].classList.remove('select2-container--open');
|
|
});
|
|
});
|
|
|
|
|
|
this.on('enable', function () {
|
|
this.on('enable', function () {
|
|
- self.$container.removeClass('select2-container--disabled');
|
|
|
|
|
|
+ self.$container[0].classList.remove('select2-container--disabled');
|
|
});
|
|
});
|
|
|
|
|
|
this.on('disable', function () {
|
|
this.on('disable', function () {
|
|
- self.$container.addClass('select2-container--disabled');
|
|
|
|
|
|
+ self.$container[0].classList.add('select2-container--disabled');
|
|
});
|
|
});
|
|
|
|
|
|
this.on('blur', function () {
|
|
this.on('blur', function () {
|
|
- self.$container.removeClass('select2-container--focus');
|
|
|
|
|
|
+ self.$container[0].classList.remove('select2-container--focus');
|
|
});
|
|
});
|
|
|
|
|
|
this.on('query', function (params) {
|
|
this.on('query', function (params) {
|
|
@@ -5734,49 +5741,30 @@ S2.define('select2/core',[
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
- Select2.prototype._isChangeMutation = function (evt, mutations) {
|
|
|
|
- var changed = false;
|
|
|
|
|
|
+ Select2.prototype._isChangeMutation = function (mutations) {
|
|
var self = this;
|
|
var self = this;
|
|
|
|
|
|
- // Ignore any mutation events raised for elements that aren't options or
|
|
|
|
- // optgroups. This handles the case when the select element is destroyed
|
|
|
|
- if (
|
|
|
|
- evt && evt.target && (
|
|
|
|
- evt.target.nodeName !== 'OPTION' && evt.target.nodeName !== 'OPTGROUP'
|
|
|
|
- )
|
|
|
|
- ) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (!mutations) {
|
|
|
|
- // If mutation events aren't supported, then we can only assume that the
|
|
|
|
- // change affected the selections
|
|
|
|
- changed = true;
|
|
|
|
- } else if (mutations.addedNodes && mutations.addedNodes.length > 0) {
|
|
|
|
|
|
+ if (mutations.addedNodes && mutations.addedNodes.length > 0) {
|
|
for (var n = 0; n < mutations.addedNodes.length; n++) {
|
|
for (var n = 0; n < mutations.addedNodes.length; n++) {
|
|
var node = mutations.addedNodes[n];
|
|
var node = mutations.addedNodes[n];
|
|
|
|
|
|
if (node.selected) {
|
|
if (node.selected) {
|
|
- changed = true;
|
|
|
|
|
|
+ return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else if (mutations.removedNodes && mutations.removedNodes.length > 0) {
|
|
} else if (mutations.removedNodes && mutations.removedNodes.length > 0) {
|
|
- changed = true;
|
|
|
|
- } else if ($.isArray(mutations)) {
|
|
|
|
- $.each(mutations, function(evt, mutation) {
|
|
|
|
- if (self._isChangeMutation(evt, mutation)) {
|
|
|
|
- // We've found a change mutation.
|
|
|
|
- // Let's escape from the loop and continue
|
|
|
|
- changed = true;
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
|
|
+ return true;
|
|
|
|
+ } else if (Array.isArray(mutations)) {
|
|
|
|
+ return mutations.some(function (mutation) {
|
|
|
|
+ return self._isChangeMutation(mutation);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
- return changed;
|
|
|
|
|
|
+
|
|
|
|
+ return false;
|
|
};
|
|
};
|
|
|
|
|
|
- Select2.prototype._syncSubtree = function (evt, mutations) {
|
|
|
|
- var changed = this._isChangeMutation(evt, mutations);
|
|
|
|
|
|
+ Select2.prototype._syncSubtree = function (mutations) {
|
|
|
|
+ var changed = this._isChangeMutation(mutations);
|
|
var self = this;
|
|
var self = this;
|
|
|
|
|
|
// Only re-pull the data if we think there is a change
|
|
// Only re-pull the data if we think there is a change
|
|
@@ -5881,11 +5869,11 @@ S2.define('select2/core',[
|
|
};
|
|
};
|
|
|
|
|
|
Select2.prototype.isOpen = function () {
|
|
Select2.prototype.isOpen = function () {
|
|
- return this.$container.hasClass('select2-container--open');
|
|
|
|
|
|
+ return this.$container[0].classList.contains('select2-container--open');
|
|
};
|
|
};
|
|
|
|
|
|
Select2.prototype.hasFocus = function () {
|
|
Select2.prototype.hasFocus = function () {
|
|
- return this.$container.hasClass('select2-container--focus');
|
|
|
|
|
|
+ return this.$container[0].classList.contains('select2-container--focus');
|
|
};
|
|
};
|
|
|
|
|
|
Select2.prototype.focus = function (data) {
|
|
Select2.prototype.focus = function (data) {
|
|
@@ -5894,7 +5882,7 @@ S2.define('select2/core',[
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- this.$container.addClass('select2-container--focus');
|
|
|
|
|
|
+ this.$container[0].classList.add('select2-container--focus');
|
|
this.trigger('focus', {});
|
|
this.trigger('focus', {});
|
|
};
|
|
};
|
|
|
|
|
|
@@ -5948,8 +5936,8 @@ S2.define('select2/core',[
|
|
|
|
|
|
var newVal = args[0];
|
|
var newVal = args[0];
|
|
|
|
|
|
- if ($.isArray(newVal)) {
|
|
|
|
- newVal = $.map(newVal, function (obj) {
|
|
|
|
|
|
+ if (Array.isArray(newVal)) {
|
|
|
|
+ newVal = newVal.map(function (obj) {
|
|
return obj.toString();
|
|
return obj.toString();
|
|
});
|
|
});
|
|
}
|
|
}
|
|
@@ -5960,21 +5948,8 @@ S2.define('select2/core',[
|
|
Select2.prototype.destroy = function () {
|
|
Select2.prototype.destroy = function () {
|
|
this.$container.remove();
|
|
this.$container.remove();
|
|
|
|
|
|
- if (this.$element[0].detachEvent) {
|
|
|
|
- this.$element[0].detachEvent('onpropertychange', this._syncA);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (this._observer != null) {
|
|
|
|
- this._observer.disconnect();
|
|
|
|
- this._observer = null;
|
|
|
|
- } else if (this.$element[0].removeEventListener) {
|
|
|
|
- this.$element[0]
|
|
|
|
- .removeEventListener('DOMAttrModified', this._syncA, false);
|
|
|
|
- this.$element[0]
|
|
|
|
- .removeEventListener('DOMNodeInserted', this._syncS, false);
|
|
|
|
- this.$element[0]
|
|
|
|
- .removeEventListener('DOMNodeRemoved', this._syncS, false);
|
|
|
|
- }
|
|
|
|
|
|
+ this._observer.disconnect();
|
|
|
|
+ this._observer = null;
|
|
|
|
|
|
this._syncA = null;
|
|
this._syncA = null;
|
|
this._syncS = null;
|
|
this._syncS = null;
|
|
@@ -5983,7 +5958,7 @@ S2.define('select2/core',[
|
|
this.$element.attr('tabindex',
|
|
this.$element.attr('tabindex',
|
|
Utils.GetData(this.$element[0], 'old-tabindex'));
|
|
Utils.GetData(this.$element[0], 'old-tabindex'));
|
|
|
|
|
|
- this.$element.removeClass('select2-hidden-accessible');
|
|
|
|
|
|
+ this.$element[0].classList.remove('select2-hidden-accessible');
|
|
this.$element.attr('aria-hidden', 'false');
|
|
this.$element.attr('aria-hidden', 'false');
|
|
Utils.RemoveData(this.$element[0]);
|
|
Utils.RemoveData(this.$element[0]);
|
|
this.$element.removeData('select2');
|
|
this.$element.removeData('select2');
|
|
@@ -6011,7 +5986,8 @@ S2.define('select2/core',[
|
|
|
|
|
|
this.$container = $container;
|
|
this.$container = $container;
|
|
|
|
|
|
- this.$container.addClass('select2-container--' + this.options.get('theme'));
|
|
|
|
|
|
+ this.$container[0].classList
|
|
|
|
+ .add('select2-container--' + this.options.get('theme'));
|
|
|
|
|
|
Utils.StoreData($container[0], 'element', this.$element);
|
|
Utils.StoreData($container[0], 'element', this.$element);
|
|
|
|
|
|
@@ -6069,7 +6045,7 @@ S2.define('jquery.select2',[
|
|
});
|
|
});
|
|
|
|
|
|
// Check if we should be returning `this`
|
|
// Check if we should be returning `this`
|
|
- if ($.inArray(options, thisMethods) > -1) {
|
|
|
|
|
|
+ if (thisMethods.indexOf(options) > -1) {
|
|
return this;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
|