|
@@ -1,5 +1,5 @@
|
|
|
/*!
|
|
|
- * Select2 4.0.6-rc.1
|
|
|
+ * Select2 4.0.6
|
|
|
* https://select2.github.io
|
|
|
*
|
|
|
* Released under the MIT license
|
|
@@ -777,9 +777,9 @@ S2.define('select2/utils',[
|
|
|
|
|
|
var id = 0;
|
|
|
Utils.GetUniqueElementId = function (element) {
|
|
|
- // Get a unique element Id. If element has no id,
|
|
|
- // creates a new unique number, stores it in the id
|
|
|
- // attribute and returns the new id.
|
|
|
+ // Get a unique element Id. If element has no id,
|
|
|
+ // creates a new unique number, stores it in the id
|
|
|
+ // attribute and returns the new id.
|
|
|
// If an id already exists, it simply returns it.
|
|
|
|
|
|
var select2Id = element.getAttribute('data-select2-id');
|
|
@@ -798,7 +798,7 @@ S2.define('select2/utils',[
|
|
|
|
|
|
Utils.StoreData = function (element, name, value) {
|
|
|
// Stores an item in the cache for a specified element.
|
|
|
- // name is the cache key.
|
|
|
+ // name is the cache key.
|
|
|
var id = Utils.GetUniqueElementId(element);
|
|
|
if (!Utils.__cache[id]) {
|
|
|
Utils.__cache[id] = {};
|
|
@@ -809,19 +809,20 @@ S2.define('select2/utils',[
|
|
|
|
|
|
Utils.GetData = function (element, name) {
|
|
|
// Retrieves a value from the cache by its key (name)
|
|
|
- // name is optional. If no name specified, return
|
|
|
+ // name is optional. If no name specified, return
|
|
|
// all cache items for the specified element.
|
|
|
// and for a specified element.
|
|
|
var id = Utils.GetUniqueElementId(element);
|
|
|
if (name) {
|
|
|
if (Utils.__cache[id]) {
|
|
|
- return Utils.__cache[id][name] != null ?
|
|
|
- Utils.__cache[id][name]:
|
|
|
- $(element).data(name); // Fallback to HTML5 data attribs.
|
|
|
+ if (Utils.__cache[id][name] != null) {
|
|
|
+ return Utils.__cache[id][name];
|
|
|
+ }
|
|
|
+ return $(element).data(name); // Fallback to HTML5 data attribs.
|
|
|
}
|
|
|
return $(element).data(name); // Fallback to HTML5 data attribs.
|
|
|
} else {
|
|
|
- return Utils.__cache[id];
|
|
|
+ return Utils.__cache[id];
|
|
|
}
|
|
|
};
|
|
|
|
|
@@ -1114,7 +1115,10 @@ S2.define('select2/results',[
|
|
|
}
|
|
|
|
|
|
self.setClasses();
|
|
|
- self.highlightFirstItem();
|
|
|
+
|
|
|
+ if (self.options.get('scrollAfterSelect')) {
|
|
|
+ self.highlightFirstItem();
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
container.on('unselect', function () {
|
|
@@ -1123,7 +1127,10 @@ S2.define('select2/results',[
|
|
|
}
|
|
|
|
|
|
self.setClasses();
|
|
|
- self.highlightFirstItem();
|
|
|
+
|
|
|
+ if (self.options.get('scrollAfterSelect')) {
|
|
|
+ self.highlightFirstItem();
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
container.on('open', function () {
|
|
@@ -1177,7 +1184,7 @@ S2.define('select2/results',[
|
|
|
|
|
|
var currentIndex = $options.index($highlighted);
|
|
|
|
|
|
- // If we are already at te top, don't move further
|
|
|
+ // If we are already at the top, don't move further
|
|
|
// If no options, currentIndex will be -1
|
|
|
if (currentIndex <= 0) {
|
|
|
return;
|
|
@@ -1470,11 +1477,10 @@ S2.define('select2/selection/base',[
|
|
|
self.$selection.removeAttr('aria-activedescendant');
|
|
|
self.$selection.removeAttr('aria-owns');
|
|
|
|
|
|
- self.$selection.focus();
|
|
|
window.setTimeout(function () {
|
|
|
self.$selection.focus();
|
|
|
}, 0);
|
|
|
-
|
|
|
+
|
|
|
self._detachCloseHandler(container);
|
|
|
});
|
|
|
|
|
@@ -1911,8 +1917,10 @@ S2.define('select2/selection/allowClear',[
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ var removeAll = this.options.get('translations').get('removeAllItems');
|
|
|
+
|
|
|
var $remove = $(
|
|
|
- '<span class="select2-selection__clear">' +
|
|
|
+ '<span class="select2-selection__clear" title="' + removeAll() +'">' +
|
|
|
'×' +
|
|
|
'</span>'
|
|
|
);
|
|
@@ -2503,6 +2511,7 @@ S2.define('select2/diacritics',[
|
|
|
'\u019F': 'O',
|
|
|
'\uA74A': 'O',
|
|
|
'\uA74C': 'O',
|
|
|
+ '\u0152': 'OE',
|
|
|
'\u01A2': 'OI',
|
|
|
'\uA74E': 'OO',
|
|
|
'\u0222': 'OU',
|
|
@@ -2912,6 +2921,7 @@ S2.define('select2/diacritics',[
|
|
|
'\uA74B': 'o',
|
|
|
'\uA74D': 'o',
|
|
|
'\u0275': 'o',
|
|
|
+ '\u0153': 'oe',
|
|
|
'\u01A3': 'oi',
|
|
|
'\u0223': 'ou',
|
|
|
'\uA74F': 'oo',
|
|
@@ -3080,8 +3090,9 @@ S2.define('select2/diacritics',[
|
|
|
'\u03CD': '\u03C5',
|
|
|
'\u03CB': '\u03C5',
|
|
|
'\u03B0': '\u03C5',
|
|
|
- '\u03C9': '\u03C9',
|
|
|
- '\u03C2': '\u03C3'
|
|
|
+ '\u03CE': '\u03C9',
|
|
|
+ '\u03C2': '\u03C3',
|
|
|
+ '\u2019': '\''
|
|
|
};
|
|
|
|
|
|
return diacritics;
|
|
@@ -3978,7 +3989,7 @@ S2.define('select2/dropdown',[
|
|
|
};
|
|
|
|
|
|
Dropdown.prototype.position = function ($dropdown, $container) {
|
|
|
- // Should be implmented in subclasses
|
|
|
+ // Should be implemented in subclasses
|
|
|
};
|
|
|
|
|
|
Dropdown.prototype.destroy = function () {
|
|
@@ -4383,10 +4394,10 @@ S2.define('select2/dropdown/attachBody',[
|
|
|
top: container.bottom
|
|
|
};
|
|
|
|
|
|
- // Determine what the parent element is to use for calciulating the offset
|
|
|
+ // Determine what the parent element is to use for calculating the offset
|
|
|
var $offsetParent = this.$dropdownParent;
|
|
|
|
|
|
- // For statically positoned elements, we need to get the element
|
|
|
+ // For statically positioned elements, we need to get the element
|
|
|
// that is determining the offset
|
|
|
if ($offsetParent.css('position') === 'static') {
|
|
|
$offsetParent = $offsetParent.offsetParent();
|
|
@@ -4616,6 +4627,9 @@ S2.define('select2/i18n/en',[],function () {
|
|
|
},
|
|
|
searching: function () {
|
|
|
return 'Searching…';
|
|
|
+ },
|
|
|
+ removeAllItems: function () {
|
|
|
+ return 'Remove all items';
|
|
|
}
|
|
|
};
|
|
|
});
|
|
@@ -4987,6 +5001,7 @@ S2.define('select2/defaults',[
|
|
|
maximumSelectionLength: 0,
|
|
|
minimumResultsForSearch: 0,
|
|
|
selectOnClose: false,
|
|
|
+ scrollAfterSelect: false,
|
|
|
sorter: function (data) {
|
|
|
return data;
|
|
|
},
|
|
@@ -5098,20 +5113,43 @@ S2.define('select2/options',[
|
|
|
|
|
|
$e.attr('ajax--url', Utils.GetData($e[0], 'ajaxUrl'));
|
|
|
Utils.StoreData($e[0], 'ajax-Url', Utils.GetData($e[0], 'ajaxUrl'));
|
|
|
-
|
|
|
}
|
|
|
|
|
|
var dataset = {};
|
|
|
|
|
|
+ function upperCaseLetter(_, letter) {
|
|
|
+ return letter.toUpperCase();
|
|
|
+ }
|
|
|
+
|
|
|
+ // Pre-load all of the attributes which are prefixed with `data-`
|
|
|
+ for (var attr = 0; attr < $e[0].attributes.length; attr++) {
|
|
|
+ var attributeName = $e[0].attributes[attr].name;
|
|
|
+ var prefix = 'data-';
|
|
|
+
|
|
|
+ if (attributeName.substr(0, prefix.length) == prefix) {
|
|
|
+ // Get the contents of the attribute after `data-`
|
|
|
+ var dataName = attributeName.substring(prefix.length);
|
|
|
+
|
|
|
+ // Get the data contents from the consistent source
|
|
|
+ // This is more than likely the jQuery data helper
|
|
|
+ var dataValue = Utils.GetData($e[0], dataName);
|
|
|
+
|
|
|
+ // camelCase the attribute name to match the spec
|
|
|
+ var camelDataName = dataName.replace(/-([a-z])/g, upperCaseLetter);
|
|
|
+
|
|
|
+ // Store the data attribute contents into the dataset since
|
|
|
+ dataset[camelDataName] = dataValue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// Prefer the element's `dataset` attribute if it exists
|
|
|
// jQuery 1.x does not correctly handle data attributes with multiple dashes
|
|
|
if ($.fn.jquery && $.fn.jquery.substr(0, 2) == '1.' && $e[0].dataset) {
|
|
|
- dataset = $.extend(true, {}, $e[0].dataset, Utils.GetData($e[0]));
|
|
|
- } else {
|
|
|
- dataset = Utils.GetData($e[0]);
|
|
|
+ dataset = $.extend(true, {}, $e[0].dataset, dataset);
|
|
|
}
|
|
|
|
|
|
- var data = $.extend(true, {}, dataset);
|
|
|
+ // Prefer our internal data cache if it exists
|
|
|
+ var data = $.extend(true, {}, Utils.GetData($e[0]), dataset);
|
|
|
|
|
|
data = Utils._convertData(data);
|
|
|
|
|
@@ -5419,6 +5457,23 @@ S2.define('select2/core',[
|
|
|
|
|
|
Select2.prototype._registerEvents = function () {
|
|
|
var self = this;
|
|
|
+
|
|
|
+ this.on('focus', function () {
|
|
|
+ self.$container.addClass('select2-container--focus');
|
|
|
+
|
|
|
+ if (!self.$container.hasClass('select2-container--disabled') &&
|
|
|
+ !self.isOpen()) {
|
|
|
+ if (self.options.get('multiple')) {
|
|
|
+ window.setTimeout(function () {
|
|
|
+ self.open();
|
|
|
+ },
|
|
|
+ self.options.get('ajax') ? 300 : 100);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ self.open();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
this.on('open', function () {
|
|
|
self.$container.addClass('select2-container--open');
|