select2-rails 4.0.8 → 4.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/select2-rails/version.rb +1 -1
- data/vendor/assets/javascripts/select2-full.js +229 -99
- data/vendor/assets/javascripts/select2.js +229 -99
- data/vendor/assets/javascripts/select2_locale_af.js +1 -1
- data/vendor/assets/javascripts/select2_locale_ar.js +1 -1
- data/vendor/assets/javascripts/select2_locale_az.js +1 -1
- data/vendor/assets/javascripts/select2_locale_bg.js +1 -1
- data/vendor/assets/javascripts/select2_locale_bn.js +1 -1
- data/vendor/assets/javascripts/select2_locale_bs.js +1 -1
- data/vendor/assets/javascripts/select2_locale_ca.js +1 -1
- data/vendor/assets/javascripts/select2_locale_cs.js +1 -1
- data/vendor/assets/javascripts/select2_locale_da.js +1 -1
- data/vendor/assets/javascripts/select2_locale_de.js +1 -1
- data/vendor/assets/javascripts/select2_locale_dsb.js +1 -1
- data/vendor/assets/javascripts/select2_locale_el.js +1 -1
- data/vendor/assets/javascripts/select2_locale_en.js +1 -1
- data/vendor/assets/javascripts/select2_locale_es.js +1 -1
- data/vendor/assets/javascripts/select2_locale_et.js +1 -1
- data/vendor/assets/javascripts/select2_locale_eu.js +1 -1
- data/vendor/assets/javascripts/select2_locale_fa.js +1 -1
- data/vendor/assets/javascripts/select2_locale_fi.js +1 -1
- data/vendor/assets/javascripts/select2_locale_fr.js +1 -1
- data/vendor/assets/javascripts/select2_locale_gl.js +1 -1
- data/vendor/assets/javascripts/select2_locale_he.js +1 -1
- data/vendor/assets/javascripts/select2_locale_hi.js +1 -1
- data/vendor/assets/javascripts/select2_locale_hr.js +1 -1
- data/vendor/assets/javascripts/select2_locale_hsb.js +1 -1
- data/vendor/assets/javascripts/select2_locale_hu.js +1 -1
- data/vendor/assets/javascripts/select2_locale_hy.js +1 -1
- data/vendor/assets/javascripts/select2_locale_id.js +1 -1
- data/vendor/assets/javascripts/select2_locale_is.js +1 -1
- data/vendor/assets/javascripts/select2_locale_it.js +1 -1
- data/vendor/assets/javascripts/select2_locale_ja.js +1 -1
- data/vendor/assets/javascripts/select2_locale_ka.js +1 -1
- data/vendor/assets/javascripts/select2_locale_km.js +1 -1
- data/vendor/assets/javascripts/select2_locale_ko.js +1 -1
- data/vendor/assets/javascripts/select2_locale_lt.js +1 -1
- data/vendor/assets/javascripts/select2_locale_lv.js +1 -1
- data/vendor/assets/javascripts/select2_locale_mk.js +1 -1
- data/vendor/assets/javascripts/select2_locale_ms.js +1 -1
- data/vendor/assets/javascripts/select2_locale_nb.js +1 -1
- data/vendor/assets/javascripts/select2_locale_ne.js +1 -1
- data/vendor/assets/javascripts/select2_locale_nl.js +1 -1
- data/vendor/assets/javascripts/select2_locale_pl.js +1 -1
- data/vendor/assets/javascripts/select2_locale_ps.js +1 -1
- data/vendor/assets/javascripts/select2_locale_pt-BR.js +1 -1
- data/vendor/assets/javascripts/select2_locale_pt.js +1 -1
- data/vendor/assets/javascripts/select2_locale_ro.js +1 -1
- data/vendor/assets/javascripts/select2_locale_ru.js +1 -1
- data/vendor/assets/javascripts/select2_locale_sk.js +1 -1
- data/vendor/assets/javascripts/select2_locale_sl.js +1 -1
- data/vendor/assets/javascripts/select2_locale_sq.js +1 -1
- data/vendor/assets/javascripts/select2_locale_sr-Cyrl.js +1 -1
- data/vendor/assets/javascripts/select2_locale_sr.js +1 -1
- data/vendor/assets/javascripts/select2_locale_sv.js +1 -1
- data/vendor/assets/javascripts/select2_locale_th.js +1 -1
- data/vendor/assets/javascripts/select2_locale_tk.js +1 -1
- data/vendor/assets/javascripts/select2_locale_tr.js +1 -1
- data/vendor/assets/javascripts/select2_locale_uk.js +1 -1
- data/vendor/assets/javascripts/select2_locale_vi.js +1 -1
- data/vendor/assets/javascripts/select2_locale_zh-CN.js +1 -1
- data/vendor/assets/javascripts/select2_locale_zh-TW.js +1 -1
- data/vendor/assets/stylesheets/select2.css +2 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa7afeef77581e6ce4d482852a85ec8988be1be558e2cdd5c9ba306149f92c08
|
4
|
+
data.tar.gz: 7dd5d6eb35f2880fc9b84230ab307605293fa19c1926a38af369f122ba10f68c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae1e831be34afb7918fbe7b5a2c4d4c377792a696d1886dc05d2b2efa00bb8887b715de8fe98319253b030a818cd61449c96ffb6ddda59b890b5275e85c6d875
|
7
|
+
data.tar.gz: 8f4a81baa622cf4c234f6504eff265390ebabb39c52bf83f874346502f3dd389bcad2206196e2c2eb535c5373a59bf07fa9b680353fcf3520f60932911109d81
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*!
|
2
|
-
* Select2 4.0.
|
2
|
+
* Select2 4.0.9
|
3
3
|
* https://select2.github.io
|
4
4
|
*
|
5
5
|
* Released under the MIT license
|
@@ -832,6 +832,8 @@ S2.define('select2/utils',[
|
|
832
832
|
if (Utils.__cache[id] != null) {
|
833
833
|
delete Utils.__cache[id];
|
834
834
|
}
|
835
|
+
|
836
|
+
element.removeAttribute('data-select2-id');
|
835
837
|
};
|
836
838
|
|
837
839
|
return Utils;
|
@@ -853,7 +855,7 @@ S2.define('select2/results',[
|
|
853
855
|
|
854
856
|
Results.prototype.render = function () {
|
855
857
|
var $results = $(
|
856
|
-
'<ul class="select2-results__options" role="
|
858
|
+
'<ul class="select2-results__options" role="listbox"></ul>'
|
857
859
|
);
|
858
860
|
|
859
861
|
if (this.options.get('multiple')) {
|
@@ -876,7 +878,7 @@ S2.define('select2/results',[
|
|
876
878
|
this.hideLoading();
|
877
879
|
|
878
880
|
var $message = $(
|
879
|
-
'<li role="
|
881
|
+
'<li role="alert" aria-live="assertive"' +
|
880
882
|
' class="select2-results__option"></li>'
|
881
883
|
);
|
882
884
|
|
@@ -1010,7 +1012,7 @@ S2.define('select2/results',[
|
|
1010
1012
|
option.className = 'select2-results__option';
|
1011
1013
|
|
1012
1014
|
var attrs = {
|
1013
|
-
'role': '
|
1015
|
+
'role': 'option',
|
1014
1016
|
'aria-selected': 'false'
|
1015
1017
|
};
|
1016
1018
|
|
@@ -1430,6 +1432,7 @@ S2.define('select2/selection/base',[
|
|
1430
1432
|
|
1431
1433
|
$selection.attr('title', this.$element.attr('title'));
|
1432
1434
|
$selection.attr('tabindex', this._tabindex);
|
1435
|
+
$selection.attr('aria-disabled', 'false');
|
1433
1436
|
|
1434
1437
|
this.$selection = $selection;
|
1435
1438
|
|
@@ -1439,7 +1442,6 @@ S2.define('select2/selection/base',[
|
|
1439
1442
|
BaseSelection.prototype.bind = function (container, $container) {
|
1440
1443
|
var self = this;
|
1441
1444
|
|
1442
|
-
var id = container.id + '-container';
|
1443
1445
|
var resultsId = container.id + '-results';
|
1444
1446
|
|
1445
1447
|
this.container = container;
|
@@ -1489,10 +1491,12 @@ S2.define('select2/selection/base',[
|
|
1489
1491
|
|
1490
1492
|
container.on('enable', function () {
|
1491
1493
|
self.$selection.attr('tabindex', self._tabindex);
|
1494
|
+
self.$selection.attr('aria-disabled', 'false');
|
1492
1495
|
});
|
1493
1496
|
|
1494
1497
|
container.on('disable', function () {
|
1495
1498
|
self.$selection.attr('tabindex', '-1');
|
1499
|
+
self.$selection.attr('aria-disabled', 'true');
|
1496
1500
|
});
|
1497
1501
|
};
|
1498
1502
|
|
@@ -1515,7 +1519,6 @@ S2.define('select2/selection/base',[
|
|
1515
1519
|
};
|
1516
1520
|
|
1517
1521
|
BaseSelection.prototype._attachCloseHandler = function (container) {
|
1518
|
-
var self = this;
|
1519
1522
|
|
1520
1523
|
$(document.body).on('mousedown.select2.' + container.id, function (e) {
|
1521
1524
|
var $target = $(e.target);
|
@@ -1525,8 +1528,6 @@ S2.define('select2/selection/base',[
|
|
1525
1528
|
var $all = $('.select2.select2-container--open');
|
1526
1529
|
|
1527
1530
|
$all.each(function () {
|
1528
|
-
var $this = $(this);
|
1529
|
-
|
1530
1531
|
if (this == $select[0]) {
|
1531
1532
|
return;
|
1532
1533
|
}
|
@@ -1653,7 +1654,14 @@ S2.define('select2/selection/single',[
|
|
1653
1654
|
var formatted = this.display(selection, $rendered);
|
1654
1655
|
|
1655
1656
|
$rendered.empty().append(formatted);
|
1656
|
-
|
1657
|
+
|
1658
|
+
var title = selection.title || selection.text;
|
1659
|
+
|
1660
|
+
if (title) {
|
1661
|
+
$rendered.attr('title', title);
|
1662
|
+
} else {
|
1663
|
+
$rendered.removeAttr('title');
|
1664
|
+
}
|
1657
1665
|
};
|
1658
1666
|
|
1659
1667
|
return SingleSelection;
|
@@ -1756,7 +1764,12 @@ S2.define('select2/selection/multiple',[
|
|
1756
1764
|
var formatted = this.display(selection, $selection);
|
1757
1765
|
|
1758
1766
|
$selection.append(formatted);
|
1759
|
-
|
1767
|
+
|
1768
|
+
var title = selection.title || selection.text;
|
1769
|
+
|
1770
|
+
if (title) {
|
1771
|
+
$selection.attr('title', title);
|
1772
|
+
}
|
1760
1773
|
|
1761
1774
|
Utils.StoreData($selection[0], 'data', selection);
|
1762
1775
|
|
@@ -1949,7 +1962,7 @@ S2.define('select2/selection/search',[
|
|
1949
1962
|
'<li class="select2-search select2-search--inline">' +
|
1950
1963
|
'<input class="select2-search__field" type="search" tabindex="-1"' +
|
1951
1964
|
' autocomplete="off" autocorrect="off" autocapitalize="none"' +
|
1952
|
-
' spellcheck="false" role="
|
1965
|
+
' spellcheck="false" role="searchbox" aria-autocomplete="list" />' +
|
1953
1966
|
'</li>'
|
1954
1967
|
);
|
1955
1968
|
|
@@ -1966,14 +1979,18 @@ S2.define('select2/selection/search',[
|
|
1966
1979
|
Search.prototype.bind = function (decorated, container, $container) {
|
1967
1980
|
var self = this;
|
1968
1981
|
|
1982
|
+
var resultsId = container.id + '-results';
|
1983
|
+
|
1969
1984
|
decorated.call(this, container, $container);
|
1970
1985
|
|
1971
1986
|
container.on('open', function () {
|
1987
|
+
self.$search.attr('aria-controls', resultsId);
|
1972
1988
|
self.$search.trigger('focus');
|
1973
1989
|
});
|
1974
1990
|
|
1975
1991
|
container.on('close', function () {
|
1976
1992
|
self.$search.val('');
|
1993
|
+
self.$search.removeAttr('aria-controls');
|
1977
1994
|
self.$search.removeAttr('aria-activedescendant');
|
1978
1995
|
self.$search.trigger('focus');
|
1979
1996
|
});
|
@@ -1993,7 +2010,11 @@ S2.define('select2/selection/search',[
|
|
1993
2010
|
});
|
1994
2011
|
|
1995
2012
|
container.on('results:focus', function (params) {
|
1996
|
-
|
2013
|
+
if (params.data._resultId) {
|
2014
|
+
self.$search.attr('aria-activedescendant', params.data._resultId);
|
2015
|
+
} else {
|
2016
|
+
self.$search.removeAttr('aria-activedescendant');
|
2017
|
+
}
|
1997
2018
|
});
|
1998
2019
|
|
1999
2020
|
this.$selection.on('focusin', '.select2-search--inline', function (evt) {
|
@@ -2027,6 +2048,12 @@ S2.define('select2/selection/search',[
|
|
2027
2048
|
}
|
2028
2049
|
});
|
2029
2050
|
|
2051
|
+
this.$selection.on('click', '.select2-search--inline', function (evt) {
|
2052
|
+
if (self.$search.val()) {
|
2053
|
+
evt.stopPropagation();
|
2054
|
+
}
|
2055
|
+
});
|
2056
|
+
|
2030
2057
|
// Try to detect the IE version should the `documentMode` property that
|
2031
2058
|
// is stored on the document. This is only implemented in IE and is
|
2032
2059
|
// slightly cleaner than doing a user agent check.
|
@@ -2145,7 +2172,7 @@ S2.define('select2/selection/search',[
|
|
2145
2172
|
var width = '';
|
2146
2173
|
|
2147
2174
|
if (this.$search.attr('placeholder') !== '') {
|
2148
|
-
width = this.$selection.find('.select2-selection__rendered').
|
2175
|
+
width = this.$selection.find('.select2-selection__rendered').width();
|
2149
2176
|
} else {
|
2150
2177
|
var minimumWidth = this.$search.val().length + 1;
|
2151
2178
|
|
@@ -3428,15 +3455,19 @@ S2.define('select2/data/array',[
|
|
3428
3455
|
'jquery'
|
3429
3456
|
], function (SelectAdapter, Utils, $) {
|
3430
3457
|
function ArrayAdapter ($element, options) {
|
3431
|
-
|
3458
|
+
this._dataToConvert = options.get('data') || [];
|
3432
3459
|
|
3433
3460
|
ArrayAdapter.__super__.constructor.call(this, $element, options);
|
3434
|
-
|
3435
|
-
this.addOptions(this.convertToOptions(data));
|
3436
3461
|
}
|
3437
3462
|
|
3438
3463
|
Utils.Extend(ArrayAdapter, SelectAdapter);
|
3439
3464
|
|
3465
|
+
ArrayAdapter.prototype.bind = function (container, $container) {
|
3466
|
+
ArrayAdapter.__super__.bind.call(this, container, $container);
|
3467
|
+
|
3468
|
+
this.addOptions(this.convertToOptions(this._dataToConvert));
|
3469
|
+
};
|
3470
|
+
|
3440
3471
|
ArrayAdapter.prototype.select = function (data) {
|
3441
3472
|
var $option = this.$element.find('option').filter(function (i, elm) {
|
3442
3473
|
return elm.value == data.id.toString();
|
@@ -3726,8 +3757,6 @@ S2.define('select2/data/tags',[
|
|
3726
3757
|
};
|
3727
3758
|
|
3728
3759
|
Tags.prototype._removeOldTags = function (_) {
|
3729
|
-
var tag = this._lastTag;
|
3730
|
-
|
3731
3760
|
var $options = this.$element.find('option[data-select2-tag]');
|
3732
3761
|
|
3733
3762
|
$options.each(function () {
|
@@ -3931,10 +3960,30 @@ S2.define('select2/data/maximumSelectionLength',[
|
|
3931
3960
|
decorated.call(this, $e, options);
|
3932
3961
|
}
|
3933
3962
|
|
3963
|
+
MaximumSelectionLength.prototype.bind =
|
3964
|
+
function (decorated, container, $container) {
|
3965
|
+
var self = this;
|
3966
|
+
|
3967
|
+
decorated.call(this, container, $container);
|
3968
|
+
|
3969
|
+
container.on('select', function () {
|
3970
|
+
self._checkIfMaximumSelected();
|
3971
|
+
});
|
3972
|
+
};
|
3973
|
+
|
3934
3974
|
MaximumSelectionLength.prototype.query =
|
3935
3975
|
function (decorated, params, callback) {
|
3936
3976
|
var self = this;
|
3937
3977
|
|
3978
|
+
this._checkIfMaximumSelected(function () {
|
3979
|
+
decorated.call(self, params, callback);
|
3980
|
+
});
|
3981
|
+
};
|
3982
|
+
|
3983
|
+
MaximumSelectionLength.prototype._checkIfMaximumSelected =
|
3984
|
+
function (_, successCallback) {
|
3985
|
+
var self = this;
|
3986
|
+
|
3938
3987
|
this.current(function (currentData) {
|
3939
3988
|
var count = currentData != null ? currentData.length : 0;
|
3940
3989
|
if (self.maximumSelectionLength > 0 &&
|
@@ -3947,7 +3996,10 @@ S2.define('select2/data/maximumSelectionLength',[
|
|
3947
3996
|
});
|
3948
3997
|
return;
|
3949
3998
|
}
|
3950
|
-
|
3999
|
+
|
4000
|
+
if (successCallback) {
|
4001
|
+
successCallback();
|
4002
|
+
}
|
3951
4003
|
});
|
3952
4004
|
};
|
3953
4005
|
|
@@ -4010,7 +4062,7 @@ S2.define('select2/dropdown/search',[
|
|
4010
4062
|
'<span class="select2-search select2-search--dropdown">' +
|
4011
4063
|
'<input class="select2-search__field" type="search" tabindex="-1"' +
|
4012
4064
|
' autocomplete="off" autocorrect="off" autocapitalize="none"' +
|
4013
|
-
' spellcheck="false" role="
|
4065
|
+
' spellcheck="false" role="searchbox" aria-autocomplete="list" />' +
|
4014
4066
|
'</span>'
|
4015
4067
|
);
|
4016
4068
|
|
@@ -4025,6 +4077,8 @@ S2.define('select2/dropdown/search',[
|
|
4025
4077
|
Search.prototype.bind = function (decorated, container, $container) {
|
4026
4078
|
var self = this;
|
4027
4079
|
|
4080
|
+
var resultsId = container.id + '-results';
|
4081
|
+
|
4028
4082
|
decorated.call(this, container, $container);
|
4029
4083
|
|
4030
4084
|
this.$search.on('keydown', function (evt) {
|
@@ -4047,6 +4101,7 @@ S2.define('select2/dropdown/search',[
|
|
4047
4101
|
|
4048
4102
|
container.on('open', function () {
|
4049
4103
|
self.$search.attr('tabindex', 0);
|
4104
|
+
self.$search.attr('aria-controls', resultsId);
|
4050
4105
|
|
4051
4106
|
self.$search.trigger('focus');
|
4052
4107
|
|
@@ -4057,6 +4112,8 @@ S2.define('select2/dropdown/search',[
|
|
4057
4112
|
|
4058
4113
|
container.on('close', function () {
|
4059
4114
|
self.$search.attr('tabindex', -1);
|
4115
|
+
self.$search.removeAttr('aria-controls');
|
4116
|
+
self.$search.removeAttr('aria-activedescendant');
|
4060
4117
|
|
4061
4118
|
self.$search.val('');
|
4062
4119
|
self.$search.trigger('blur');
|
@@ -4079,6 +4136,14 @@ S2.define('select2/dropdown/search',[
|
|
4079
4136
|
}
|
4080
4137
|
}
|
4081
4138
|
});
|
4139
|
+
|
4140
|
+
container.on('results:focus', function (params) {
|
4141
|
+
if (params.data._resultId) {
|
4142
|
+
self.$search.attr('aria-activedescendant', params.data._resultId);
|
4143
|
+
} else {
|
4144
|
+
self.$search.removeAttr('aria-activedescendant');
|
4145
|
+
}
|
4146
|
+
});
|
4082
4147
|
};
|
4083
4148
|
|
4084
4149
|
Search.prototype.handleSearch = function (evt) {
|
@@ -4223,7 +4288,7 @@ S2.define('select2/dropdown/infiniteScroll',[
|
|
4223
4288
|
var $option = $(
|
4224
4289
|
'<li ' +
|
4225
4290
|
'class="select2-results__option select2-results__option--load-more"' +
|
4226
|
-
'role="
|
4291
|
+
'role="option" aria-disabled="true"></li>'
|
4227
4292
|
);
|
4228
4293
|
|
4229
4294
|
var message = this.options.get('translations').get('loadingMore');
|
@@ -4249,27 +4314,11 @@ S2.define('select2/dropdown/attachBody',[
|
|
4249
4314
|
AttachBody.prototype.bind = function (decorated, container, $container) {
|
4250
4315
|
var self = this;
|
4251
4316
|
|
4252
|
-
var setupResultsEvents = false;
|
4253
|
-
|
4254
4317
|
decorated.call(this, container, $container);
|
4255
4318
|
|
4256
4319
|
container.on('open', function () {
|
4257
4320
|
self._showDropdown();
|
4258
4321
|
self._attachPositioningHandler(container);
|
4259
|
-
|
4260
|
-
if (!setupResultsEvents) {
|
4261
|
-
setupResultsEvents = true;
|
4262
|
-
|
4263
|
-
container.on('results:all', function () {
|
4264
|
-
self._positionDropdown();
|
4265
|
-
self._resizeDropdown();
|
4266
|
-
});
|
4267
|
-
|
4268
|
-
container.on('results:append', function () {
|
4269
|
-
self._positionDropdown();
|
4270
|
-
self._resizeDropdown();
|
4271
|
-
});
|
4272
|
-
}
|
4273
4322
|
});
|
4274
4323
|
|
4275
4324
|
container.on('close', function () {
|
@@ -4277,6 +4326,31 @@ S2.define('select2/dropdown/attachBody',[
|
|
4277
4326
|
self._detachPositioningHandler(container);
|
4278
4327
|
});
|
4279
4328
|
|
4329
|
+
container.on('results:all', function () {
|
4330
|
+
self._positionDropdown();
|
4331
|
+
self._resizeDropdown();
|
4332
|
+
});
|
4333
|
+
|
4334
|
+
container.on('results:append', function () {
|
4335
|
+
self._positionDropdown();
|
4336
|
+
self._resizeDropdown();
|
4337
|
+
});
|
4338
|
+
|
4339
|
+
container.on('results:message', function () {
|
4340
|
+
self._positionDropdown();
|
4341
|
+
self._resizeDropdown();
|
4342
|
+
});
|
4343
|
+
|
4344
|
+
container.on('select', function () {
|
4345
|
+
self._positionDropdown();
|
4346
|
+
self._resizeDropdown();
|
4347
|
+
});
|
4348
|
+
|
4349
|
+
container.on('unselect', function () {
|
4350
|
+
self._positionDropdown();
|
4351
|
+
self._resizeDropdown();
|
4352
|
+
});
|
4353
|
+
|
4280
4354
|
this.$dropdownContainer.on('mousedown', function (evt) {
|
4281
4355
|
evt.stopPropagation();
|
4282
4356
|
});
|
@@ -4868,66 +4942,29 @@ S2.define('select2/defaults',[
|
|
4868
4942
|
);
|
4869
4943
|
}
|
4870
4944
|
|
4871
|
-
|
4872
|
-
|
4873
|
-
|
4874
|
-
// Extract the region information if it is included
|
4875
|
-
var languageParts = options.language.split('-');
|
4876
|
-
var baseLanguage = languageParts[0];
|
4877
|
-
|
4878
|
-
options.language = [options.language, baseLanguage];
|
4879
|
-
} else {
|
4880
|
-
options.language = [options.language];
|
4881
|
-
}
|
4882
|
-
}
|
4883
|
-
|
4884
|
-
if ($.isArray(options.language)) {
|
4885
|
-
var languages = new Translation();
|
4886
|
-
options.language.push('en');
|
4945
|
+
// If the defaults were not previously applied from an element, it is
|
4946
|
+
// possible for the language option to have not been resolved
|
4947
|
+
options.language = this._resolveLanguage(options.language);
|
4887
4948
|
|
4888
|
-
|
4949
|
+
// Always fall back to English since it will always be complete
|
4950
|
+
options.language.push('en');
|
4889
4951
|
|
4890
|
-
|
4891
|
-
var name = languageNames[l];
|
4892
|
-
var language = {};
|
4893
|
-
|
4894
|
-
try {
|
4895
|
-
// Try to load it with the original name
|
4896
|
-
language = Translation.loadPath(name);
|
4897
|
-
} catch (e) {
|
4898
|
-
try {
|
4899
|
-
// If we couldn't load it, check if it wasn't the full path
|
4900
|
-
name = this.defaults.amdLanguageBase + name;
|
4901
|
-
language = Translation.loadPath(name);
|
4902
|
-
} catch (ex) {
|
4903
|
-
// The translation could not be loaded at all. Sometimes this is
|
4904
|
-
// because of a configuration problem, other times this can be
|
4905
|
-
// because of how Select2 helps load all possible translation files.
|
4906
|
-
if (options.debug && window.console && console.warn) {
|
4907
|
-
console.warn(
|
4908
|
-
'Select2: The language file for "' + name + '" could not be ' +
|
4909
|
-
'automatically loaded. A fallback will be used instead.'
|
4910
|
-
);
|
4911
|
-
}
|
4952
|
+
var uniqueLanguages = [];
|
4912
4953
|
|
4913
|
-
|
4914
|
-
|
4915
|
-
}
|
4954
|
+
for (var l = 0; l < options.language.length; l++) {
|
4955
|
+
var language = options.language[l];
|
4916
4956
|
|
4917
|
-
|
4957
|
+
if (uniqueLanguages.indexOf(language) === -1) {
|
4958
|
+
uniqueLanguages.push(language);
|
4918
4959
|
}
|
4960
|
+
}
|
4919
4961
|
|
4920
|
-
|
4921
|
-
} else {
|
4922
|
-
var baseTranslation = Translation.loadPath(
|
4923
|
-
this.defaults.amdLanguageBase + 'en'
|
4924
|
-
);
|
4925
|
-
var customTranslation = new Translation(options.language);
|
4926
|
-
|
4927
|
-
customTranslation.extend(baseTranslation);
|
4962
|
+
options.language = uniqueLanguages;
|
4928
4963
|
|
4929
|
-
|
4930
|
-
|
4964
|
+
options.translations = this._processTranslations(
|
4965
|
+
options.language,
|
4966
|
+
options.debug
|
4967
|
+
);
|
4931
4968
|
|
4932
4969
|
return options;
|
4933
4970
|
};
|
@@ -4994,7 +5031,7 @@ S2.define('select2/defaults',[
|
|
4994
5031
|
debug: false,
|
4995
5032
|
dropdownAutoWidth: false,
|
4996
5033
|
escapeMarkup: Utils.escapeMarkup,
|
4997
|
-
language:
|
5034
|
+
language: {},
|
4998
5035
|
matcher: matcher,
|
4999
5036
|
minimumInputLength: 0,
|
5000
5037
|
maximumInputLength: 0,
|
@@ -5016,6 +5053,103 @@ S2.define('select2/defaults',[
|
|
5016
5053
|
};
|
5017
5054
|
};
|
5018
5055
|
|
5056
|
+
Defaults.prototype.applyFromElement = function (options, $element) {
|
5057
|
+
var optionLanguage = options.language;
|
5058
|
+
var defaultLanguage = this.defaults.language;
|
5059
|
+
var elementLanguage = $element.prop('lang');
|
5060
|
+
var parentLanguage = $element.closest('[lang]').prop('lang');
|
5061
|
+
|
5062
|
+
var languages = Array.prototype.concat.call(
|
5063
|
+
this._resolveLanguage(elementLanguage),
|
5064
|
+
this._resolveLanguage(optionLanguage),
|
5065
|
+
this._resolveLanguage(defaultLanguage),
|
5066
|
+
this._resolveLanguage(parentLanguage)
|
5067
|
+
);
|
5068
|
+
|
5069
|
+
options.language = languages;
|
5070
|
+
|
5071
|
+
return options;
|
5072
|
+
};
|
5073
|
+
|
5074
|
+
Defaults.prototype._resolveLanguage = function (language) {
|
5075
|
+
if (!language) {
|
5076
|
+
return [];
|
5077
|
+
}
|
5078
|
+
|
5079
|
+
if ($.isEmptyObject(language)) {
|
5080
|
+
return [];
|
5081
|
+
}
|
5082
|
+
|
5083
|
+
if ($.isPlainObject(language)) {
|
5084
|
+
return [language];
|
5085
|
+
}
|
5086
|
+
|
5087
|
+
var languages;
|
5088
|
+
|
5089
|
+
if (!$.isArray(language)) {
|
5090
|
+
languages = [language];
|
5091
|
+
} else {
|
5092
|
+
languages = language;
|
5093
|
+
}
|
5094
|
+
|
5095
|
+
var resolvedLanguages = [];
|
5096
|
+
|
5097
|
+
for (var l = 0; l < languages.length; l++) {
|
5098
|
+
resolvedLanguages.push(languages[l]);
|
5099
|
+
|
5100
|
+
if (typeof languages[l] === 'string' && languages[l].indexOf('-') > 0) {
|
5101
|
+
// Extract the region information if it is included
|
5102
|
+
var languageParts = languages[l].split('-');
|
5103
|
+
var baseLanguage = languageParts[0];
|
5104
|
+
|
5105
|
+
resolvedLanguages.push(baseLanguage);
|
5106
|
+
}
|
5107
|
+
}
|
5108
|
+
|
5109
|
+
return resolvedLanguages;
|
5110
|
+
};
|
5111
|
+
|
5112
|
+
Defaults.prototype._processTranslations = function (languages, debug) {
|
5113
|
+
var translations = new Translation();
|
5114
|
+
|
5115
|
+
for (var l = 0; l < languages.length; l++) {
|
5116
|
+
var languageData = new Translation();
|
5117
|
+
|
5118
|
+
var language = languages[l];
|
5119
|
+
|
5120
|
+
if (typeof language === 'string') {
|
5121
|
+
try {
|
5122
|
+
// Try to load it with the original name
|
5123
|
+
languageData = Translation.loadPath(language);
|
5124
|
+
} catch (e) {
|
5125
|
+
try {
|
5126
|
+
// If we couldn't load it, check if it wasn't the full path
|
5127
|
+
language = this.defaults.amdLanguageBase + language;
|
5128
|
+
languageData = Translation.loadPath(language);
|
5129
|
+
} catch (ex) {
|
5130
|
+
// The translation could not be loaded at all. Sometimes this is
|
5131
|
+
// because of a configuration problem, other times this can be
|
5132
|
+
// because of how Select2 helps load all possible translation files
|
5133
|
+
if (debug && window.console && console.warn) {
|
5134
|
+
console.warn(
|
5135
|
+
'Select2: The language file for "' + language + '" could ' +
|
5136
|
+
'not be automatically loaded. A fallback will be used instead.'
|
5137
|
+
);
|
5138
|
+
}
|
5139
|
+
}
|
5140
|
+
}
|
5141
|
+
} else if ($.isPlainObject(language)) {
|
5142
|
+
languageData = new Translation(language);
|
5143
|
+
} else {
|
5144
|
+
languageData = language;
|
5145
|
+
}
|
5146
|
+
|
5147
|
+
translations.extend(languageData);
|
5148
|
+
}
|
5149
|
+
|
5150
|
+
return translations;
|
5151
|
+
};
|
5152
|
+
|
5019
5153
|
Defaults.prototype.set = function (key, value) {
|
5020
5154
|
var camelKey = $.camelCase(key);
|
5021
5155
|
|
@@ -5045,6 +5179,10 @@ S2.define('select2/options',[
|
|
5045
5179
|
this.fromElement($element);
|
5046
5180
|
}
|
5047
5181
|
|
5182
|
+
if ($element != null) {
|
5183
|
+
this.options = Defaults.applyFromElement(this.options, $element);
|
5184
|
+
}
|
5185
|
+
|
5048
5186
|
this.options = Defaults.apply(this.options);
|
5049
5187
|
|
5050
5188
|
if ($element && $element.is('input')) {
|
@@ -5068,14 +5206,6 @@ S2.define('select2/options',[
|
|
5068
5206
|
this.options.disabled = $e.prop('disabled');
|
5069
5207
|
}
|
5070
5208
|
|
5071
|
-
if (this.options.language == null) {
|
5072
|
-
if ($e.prop('lang')) {
|
5073
|
-
this.options.language = $e.prop('lang').toLowerCase();
|
5074
|
-
} else if ($e.closest('[lang]').prop('lang')) {
|
5075
|
-
this.options.language = $e.closest('[lang]').prop('lang');
|
5076
|
-
}
|
5077
|
-
}
|
5078
|
-
|
5079
5209
|
if (this.options.dir == null) {
|
5080
5210
|
if ($e.prop('dir')) {
|
5081
5211
|
this.options.dir = $e.prop('dir');
|