select2-rails 4.0.9 → 4.1.0.pre.beta.1

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.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/select2-rails/version.rb +1 -1
  4. data/vendor/assets/javascripts/select2-full.js +428 -702
  5. data/vendor/assets/javascripts/select2.js +426 -300
  6. data/vendor/assets/javascripts/select2_locale_af.js +1 -1
  7. data/vendor/assets/javascripts/select2_locale_ar.js +1 -1
  8. data/vendor/assets/javascripts/select2_locale_az.js +1 -1
  9. data/vendor/assets/javascripts/select2_locale_bg.js +1 -1
  10. data/vendor/assets/javascripts/select2_locale_bn.js +1 -1
  11. data/vendor/assets/javascripts/select2_locale_bs.js +1 -1
  12. data/vendor/assets/javascripts/select2_locale_ca.js +1 -1
  13. data/vendor/assets/javascripts/select2_locale_cs.js +1 -1
  14. data/vendor/assets/javascripts/select2_locale_da.js +1 -1
  15. data/vendor/assets/javascripts/select2_locale_de.js +2 -2
  16. data/vendor/assets/javascripts/select2_locale_dsb.js +1 -1
  17. data/vendor/assets/javascripts/select2_locale_el.js +1 -1
  18. data/vendor/assets/javascripts/select2_locale_en.js +2 -2
  19. data/vendor/assets/javascripts/select2_locale_eo.js +3 -0
  20. data/vendor/assets/javascripts/select2_locale_es.js +1 -1
  21. data/vendor/assets/javascripts/select2_locale_et.js +1 -1
  22. data/vendor/assets/javascripts/select2_locale_eu.js +1 -1
  23. data/vendor/assets/javascripts/select2_locale_fa.js +1 -1
  24. data/vendor/assets/javascripts/select2_locale_fi.js +1 -1
  25. data/vendor/assets/javascripts/select2_locale_fr.js +1 -1
  26. data/vendor/assets/javascripts/select2_locale_gl.js +1 -1
  27. data/vendor/assets/javascripts/select2_locale_he.js +1 -1
  28. data/vendor/assets/javascripts/select2_locale_hi.js +1 -1
  29. data/vendor/assets/javascripts/select2_locale_hr.js +1 -1
  30. data/vendor/assets/javascripts/select2_locale_hsb.js +1 -1
  31. data/vendor/assets/javascripts/select2_locale_hu.js +1 -1
  32. data/vendor/assets/javascripts/select2_locale_hy.js +1 -1
  33. data/vendor/assets/javascripts/select2_locale_id.js +1 -1
  34. data/vendor/assets/javascripts/select2_locale_is.js +1 -1
  35. data/vendor/assets/javascripts/select2_locale_it.js +1 -1
  36. data/vendor/assets/javascripts/select2_locale_ja.js +1 -1
  37. data/vendor/assets/javascripts/select2_locale_ka.js +1 -1
  38. data/vendor/assets/javascripts/select2_locale_km.js +1 -1
  39. data/vendor/assets/javascripts/select2_locale_ko.js +1 -1
  40. data/vendor/assets/javascripts/select2_locale_lt.js +1 -1
  41. data/vendor/assets/javascripts/select2_locale_lv.js +1 -1
  42. data/vendor/assets/javascripts/select2_locale_mk.js +1 -1
  43. data/vendor/assets/javascripts/select2_locale_ms.js +1 -1
  44. data/vendor/assets/javascripts/select2_locale_nb.js +1 -1
  45. data/vendor/assets/javascripts/select2_locale_ne.js +1 -1
  46. data/vendor/assets/javascripts/select2_locale_nl.js +1 -1
  47. data/vendor/assets/javascripts/select2_locale_pa.js +3 -0
  48. data/vendor/assets/javascripts/select2_locale_pl.js +1 -1
  49. data/vendor/assets/javascripts/select2_locale_ps.js +1 -1
  50. data/vendor/assets/javascripts/select2_locale_pt-BR.js +1 -1
  51. data/vendor/assets/javascripts/select2_locale_pt.js +1 -1
  52. data/vendor/assets/javascripts/select2_locale_ro.js +1 -1
  53. data/vendor/assets/javascripts/select2_locale_ru.js +1 -1
  54. data/vendor/assets/javascripts/select2_locale_sk.js +1 -1
  55. data/vendor/assets/javascripts/select2_locale_sl.js +1 -1
  56. data/vendor/assets/javascripts/select2_locale_sq.js +1 -1
  57. data/vendor/assets/javascripts/select2_locale_sr-Cyrl.js +1 -1
  58. data/vendor/assets/javascripts/select2_locale_sr.js +1 -1
  59. data/vendor/assets/javascripts/select2_locale_sv.js +1 -1
  60. data/vendor/assets/javascripts/select2_locale_th.js +1 -1
  61. data/vendor/assets/javascripts/select2_locale_tk.js +1 -1
  62. data/vendor/assets/javascripts/select2_locale_tr.js +1 -1
  63. data/vendor/assets/javascripts/select2_locale_uk.js +1 -1
  64. data/vendor/assets/javascripts/select2_locale_vi.js +1 -1
  65. data/vendor/assets/javascripts/select2_locale_zh-CN.js +1 -1
  66. data/vendor/assets/javascripts/select2_locale_zh-TW.js +1 -1
  67. data/vendor/assets/stylesheets/select2.css +103 -69
  68. metadata +5 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa7afeef77581e6ce4d482852a85ec8988be1be558e2cdd5c9ba306149f92c08
4
- data.tar.gz: 7dd5d6eb35f2880fc9b84230ab307605293fa19c1926a38af369f122ba10f68c
3
+ metadata.gz: fc63c98004a81bcbada24c6f86fb04467186e4273d2caf2acbf834a4750bfa1b
4
+ data.tar.gz: 44b43109d599ba5e6f854e3cf3f5ae68a8ac7e40fe82a8335c1f43549325b63e
5
5
  SHA512:
6
- metadata.gz: ae1e831be34afb7918fbe7b5a2c4d4c377792a696d1886dc05d2b2efa00bb8887b715de8fe98319253b030a818cd61449c96ffb6ddda59b890b5275e85c6d875
7
- data.tar.gz: 8f4a81baa622cf4c234f6504eff265390ebabb39c52bf83f874346502f3dd389bcad2206196e2c2eb535c5373a59bf07fa9b680353fcf3520f60932911109d81
6
+ metadata.gz: 6f0562e6f4a652e22168fb340d61a0e8dc4843140b3cf04988b66a8f9d51406b396d2b3787658d2981a501bfe4721177b27ffd2206b8683ed9b3695c2056d37f
7
+ data.tar.gz: 25f80632ed6fe45d70da0771086a037d7d717b88405d8332d3434a6d5d3080095f63325aa7f118b55237bb8fcfe0a15da6520c4e68a38d20111f4ed34252234d
data/README.md CHANGED
@@ -56,7 +56,7 @@ To apply the language, pass whatever language you'd like to use to the [`languag
56
56
 
57
57
  Possible languages:
58
58
 
59
- af, ar, az, bg, bn, bs, ca, cs, da, de, dsb, el, en, es, et, eu, fa, fi, fr, gl, he, hi, hr, hsb, hu, hy, id, is, it, ja, ka, km, ko, lt, lv, mk, ms, nb, ne, nl, pl, ps, pt, pt-BR, ro, ru, sk, sl, sq, sr, sr-Cyrl, sv, th, tk, tr, uk, vi, zh-CN, zh-TW
59
+ af, ar, az, bg, bn, bs, ca, cs, da, de, dsb, el, en, eo, es, et, eu, fa, fi, fr, gl, he, hi, hr, hsb, hu, hy, id, is, it, ja, ka, km, ko, lt, lv, mk, ms, nb, ne, nl, pa, pl, ps, pt, pt-BR, ro, ru, sk, sl, sq, sr, sr-Cyrl, sv, th, tk, tr, uk, vi, zh-CN, zh-TW
60
60
 
61
61
  ## Example
62
62
  Code [here](https://github.com/argerim/select_2_example)
@@ -1,5 +1,5 @@
1
1
  module Select2
2
2
  module Rails
3
- VERSION = '4.0.9'
3
+ VERSION = '4.1.0-beta.1'
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Select2 4.0.9
2
+ * Select2 4.1.0-beta.1
3
3
  * https://select2.github.io
4
4
  *
5
5
  * Released under the MIT license
@@ -755,23 +755,6 @@ S2.define('select2/utils',[
755
755
  });
756
756
  };
757
757
 
758
- // Append an array of jQuery nodes to a given element.
759
- Utils.appendMany = function ($element, $nodes) {
760
- // jQuery 1.7.x does not support $.fn.append() with an array
761
- // Fall back to a jQuery object collection using $.fn.add()
762
- if ($.fn.jquery.substr(0, 3) === '1.7') {
763
- var $jqNodes = $();
764
-
765
- $.map($nodes, function (node) {
766
- $jqNodes = $jqNodes.add(node);
767
- });
768
-
769
- $nodes = $jqNodes;
770
- }
771
-
772
- $element.append($nodes);
773
- };
774
-
775
758
  // Cache objects in Utils.__cache instead of $.data (see #4346)
776
759
  Utils.__cache = {};
777
760
 
@@ -779,20 +762,25 @@ S2.define('select2/utils',[
779
762
  Utils.GetUniqueElementId = function (element) {
780
763
  // Get a unique element Id. If element has no id,
781
764
  // creates a new unique number, stores it in the id
782
- // attribute and returns the new id.
783
- // If an id already exists, it simply returns it.
765
+ // attribute and returns the new id with a prefix.
766
+ // If an id already exists, it simply returns it with a prefix.
784
767
 
785
768
  var select2Id = element.getAttribute('data-select2-id');
786
- if (select2Id == null) {
787
- // If element has id, use it.
788
- if (element.id) {
789
- select2Id = element.id;
790
- element.setAttribute('data-select2-id', select2Id);
791
- } else {
792
- element.setAttribute('data-select2-id', ++id);
793
- select2Id = id.toString();
794
- }
769
+
770
+ if (select2Id != null) {
771
+ return select2Id;
772
+ }
773
+
774
+ // If element has id, use it.
775
+ if (element.id) {
776
+ select2Id = 'select2-data-' + element.id;
777
+ } else {
778
+ select2Id = 'select2-data-' + (++id).toString() +
779
+ '-' + Utils.generateChars(4);
795
780
  }
781
+
782
+ element.setAttribute('data-select2-id', select2Id);
783
+
796
784
  return select2Id;
797
785
  };
798
786
 
@@ -836,6 +824,28 @@ S2.define('select2/utils',[
836
824
  element.removeAttribute('data-select2-id');
837
825
  };
838
826
 
827
+ Utils.copyNonInternalCssClasses = function (dest, src) {
828
+ var classes;
829
+
830
+ var destinationClasses = dest.getAttribute('class').trim().split(/\s+/);
831
+
832
+ destinationClasses = destinationClasses.filter(function (clazz) {
833
+ // Save all Select2 classes
834
+ return clazz.indexOf('select2-') === 0;
835
+ });
836
+
837
+ var sourceClasses = src.getAttribute('class').trim().split(/\s+/);
838
+
839
+ sourceClasses = sourceClasses.filter(function (clazz) {
840
+ // Only copy non-Select2 classes
841
+ return clazz.indexOf('select2-') !== 0;
842
+ });
843
+
844
+ var replacements = destinationClasses.concat(sourceClasses);
845
+
846
+ dest.setAttribute('class', replacements.join(' '));
847
+ };
848
+
839
849
  return Utils;
840
850
  });
841
851
 
@@ -940,9 +950,9 @@ S2.define('select2/results',[
940
950
 
941
951
  Results.prototype.highlightFirstItem = function () {
942
952
  var $options = this.$results
943
- .find('.select2-results__option[aria-selected]');
953
+ .find('.select2-results__option--selectable');
944
954
 
945
- var $selected = $options.filter('[aria-selected=true]');
955
+ var $selected = $options.filter('.select2-results__option--selected');
946
956
 
947
957
  // Check if there are any selected options
948
958
  if ($selected.length > 0) {
@@ -961,12 +971,12 @@ S2.define('select2/results',[
961
971
  var self = this;
962
972
 
963
973
  this.data.current(function (selected) {
964
- var selectedIds = $.map(selected, function (s) {
974
+ var selectedIds = selected.map(function (s) {
965
975
  return s.id.toString();
966
976
  });
967
977
 
968
978
  var $options = self.$results
969
- .find('.select2-results__option[aria-selected]');
979
+ .find('.select2-results__option--selectable');
970
980
 
971
981
  $options.each(function () {
972
982
  var $option = $(this);
@@ -977,9 +987,11 @@ S2.define('select2/results',[
977
987
  var id = '' + item.id;
978
988
 
979
989
  if ((item.element != null && item.element.selected) ||
980
- (item.element == null && $.inArray(id, selectedIds) > -1)) {
990
+ (item.element == null && selectedIds.indexOf(id) > -1)) {
991
+ this.classList.add('select2-results__option--selected');
981
992
  $option.attr('aria-selected', 'true');
982
993
  } else {
994
+ this.classList.remove('select2-results__option--selected');
983
995
  $option.attr('aria-selected', 'false');
984
996
  }
985
997
  });
@@ -1009,11 +1021,11 @@ S2.define('select2/results',[
1009
1021
 
1010
1022
  Results.prototype.option = function (data) {
1011
1023
  var option = document.createElement('li');
1012
- option.className = 'select2-results__option';
1024
+ option.classList.add('select2-results__option');
1025
+ option.classList.add('select2-results__option--selectable');
1013
1026
 
1014
1027
  var attrs = {
1015
- 'role': 'option',
1016
- 'aria-selected': 'false'
1028
+ 'role': 'option'
1017
1029
  };
1018
1030
 
1019
1031
  var matches = window.Element.prototype.matches ||
@@ -1022,12 +1034,14 @@ S2.define('select2/results',[
1022
1034
 
1023
1035
  if ((data.element != null && matches.call(data.element, ':disabled')) ||
1024
1036
  (data.element == null && data.disabled)) {
1025
- delete attrs['aria-selected'];
1026
1037
  attrs['aria-disabled'] = 'true';
1038
+
1039
+ option.classList.remove('select2-results__option--selectable');
1040
+ option.classList.add('select2-results__option--disabled');
1027
1041
  }
1028
1042
 
1029
1043
  if (data.id == null) {
1030
- delete attrs['aria-selected'];
1044
+ option.classList.remove('select2-results__option--selectable');
1031
1045
  }
1032
1046
 
1033
1047
  if (data._resultId != null) {
@@ -1041,7 +1055,9 @@ S2.define('select2/results',[
1041
1055
  if (data.children) {
1042
1056
  attrs.role = 'group';
1043
1057
  attrs['aria-label'] = data.text;
1044
- delete attrs['aria-selected'];
1058
+
1059
+ option.classList.remove('select2-results__option--selectable');
1060
+ option.classList.add('select2-results__option--group');
1045
1061
  }
1046
1062
 
1047
1063
  for (var attr in attrs) {
@@ -1056,7 +1072,6 @@ S2.define('select2/results',[
1056
1072
  var label = document.createElement('strong');
1057
1073
  label.className = 'select2-results__group';
1058
1074
 
1059
- var $label = $(label);
1060
1075
  this.template(data, label);
1061
1076
 
1062
1077
  var $children = [];
@@ -1175,7 +1190,7 @@ S2.define('select2/results',[
1175
1190
 
1176
1191
  var data = Utils.GetData($highlighted[0], 'data');
1177
1192
 
1178
- if ($highlighted.attr('aria-selected') == 'true') {
1193
+ if ($highlighted.hasClass('select2-results__option--selected')) {
1179
1194
  self.trigger('close', {});
1180
1195
  } else {
1181
1196
  self.trigger('select', {
@@ -1187,7 +1202,7 @@ S2.define('select2/results',[
1187
1202
  container.on('results:previous', function () {
1188
1203
  var $highlighted = self.getHighlightedResults();
1189
1204
 
1190
- var $options = self.$results.find('[aria-selected]');
1205
+ var $options = self.$results.find('.select2-results__option--selectable');
1191
1206
 
1192
1207
  var currentIndex = $options.index($highlighted);
1193
1208
 
@@ -1222,7 +1237,7 @@ S2.define('select2/results',[
1222
1237
  container.on('results:next', function () {
1223
1238
  var $highlighted = self.getHighlightedResults();
1224
1239
 
1225
- var $options = self.$results.find('[aria-selected]');
1240
+ var $options = self.$results.find('.select2-results__option--selectable');
1226
1241
 
1227
1242
  var currentIndex = $options.index($highlighted);
1228
1243
 
@@ -1250,7 +1265,8 @@ S2.define('select2/results',[
1250
1265
  });
1251
1266
 
1252
1267
  container.on('results:focus', function (params) {
1253
- params.element.addClass('select2-results__option--highlighted');
1268
+ params.element[0].classList.add('select2-results__option--highlighted');
1269
+ params.element[0].setAttribute('aria-selected', 'true');
1254
1270
  });
1255
1271
 
1256
1272
  container.on('results:message', function (params) {
@@ -1282,13 +1298,13 @@ S2.define('select2/results',[
1282
1298
  });
1283
1299
  }
1284
1300
 
1285
- this.$results.on('mouseup', '.select2-results__option[aria-selected]',
1301
+ this.$results.on('mouseup', '.select2-results__option--selectable',
1286
1302
  function (evt) {
1287
1303
  var $this = $(this);
1288
1304
 
1289
1305
  var data = Utils.GetData(this, 'data');
1290
1306
 
1291
- if ($this.attr('aria-selected') === 'true') {
1307
+ if ($this.hasClass('select2-results__option--selected')) {
1292
1308
  if (self.options.get('multiple')) {
1293
1309
  self.trigger('unselect', {
1294
1310
  originalEvent: evt,
@@ -1307,12 +1323,13 @@ S2.define('select2/results',[
1307
1323
  });
1308
1324
  });
1309
1325
 
1310
- this.$results.on('mouseenter', '.select2-results__option[aria-selected]',
1326
+ this.$results.on('mouseenter', '.select2-results__option--selectable',
1311
1327
  function (evt) {
1312
1328
  var data = Utils.GetData(this, 'data');
1313
1329
 
1314
1330
  self.getHighlightedResults()
1315
- .removeClass('select2-results__option--highlighted');
1331
+ .removeClass('select2-results__option--highlighted')
1332
+ .attr('aria-selected', 'false');
1316
1333
 
1317
1334
  self.trigger('results:focus', {
1318
1335
  data: data,
@@ -1339,7 +1356,7 @@ S2.define('select2/results',[
1339
1356
  return;
1340
1357
  }
1341
1358
 
1342
- var $options = this.$results.find('[aria-selected]');
1359
+ var $options = this.$results.find('.select2-results__option--selectable');
1343
1360
 
1344
1361
  var currentIndex = $options.index($highlighted);
1345
1362
 
@@ -1556,6 +1573,27 @@ S2.define('select2/selection/base',[
1556
1573
  throw new Error('The `update` method must be defined in child classes.');
1557
1574
  };
1558
1575
 
1576
+ /**
1577
+ * Helper method to abstract the "enabled" (not "disabled") state of this
1578
+ * object.
1579
+ *
1580
+ * @return {true} if the instance is not disabled.
1581
+ * @return {false} if the instance is disabled.
1582
+ */
1583
+ BaseSelection.prototype.isEnabled = function () {
1584
+ return !this.isDisabled();
1585
+ };
1586
+
1587
+ /**
1588
+ * Helper method to abstract the "disabled" state of this object.
1589
+ *
1590
+ * @return {true} if the disabled option is true.
1591
+ * @return {false} if the disabled option is false.
1592
+ */
1593
+ BaseSelection.prototype.isDisabled = function () {
1594
+ return this.options.get('disabled');
1595
+ };
1596
+
1559
1597
  return BaseSelection;
1560
1598
  });
1561
1599
 
@@ -1574,7 +1612,7 @@ S2.define('select2/selection/single',[
1574
1612
  SingleSelection.prototype.render = function () {
1575
1613
  var $selection = SingleSelection.__super__.render.call(this);
1576
1614
 
1577
- $selection.addClass('select2-selection--single');
1615
+ $selection[0].classList.add('select2-selection--single');
1578
1616
 
1579
1617
  $selection.html(
1580
1618
  '<span class="select2-selection__rendered"></span>' +
@@ -1681,7 +1719,7 @@ S2.define('select2/selection/multiple',[
1681
1719
  MultipleSelection.prototype.render = function () {
1682
1720
  var $selection = MultipleSelection.__super__.render.call(this);
1683
1721
 
1684
- $selection.addClass('select2-selection--multiple');
1722
+ $selection[0].classList.add('select2-selection--multiple');
1685
1723
 
1686
1724
  $selection.html(
1687
1725
  '<ul class="select2-selection__rendered"></ul>'
@@ -1695,6 +1733,9 @@ S2.define('select2/selection/multiple',[
1695
1733
 
1696
1734
  MultipleSelection.__super__.bind.apply(this, arguments);
1697
1735
 
1736
+ var id = container.id + '-container';
1737
+ this.$selection.find('.select2-selection__rendered').attr('id', id);
1738
+
1698
1739
  this.$selection.on('click', function (evt) {
1699
1740
  self.trigger('toggle', {
1700
1741
  originalEvent: evt
@@ -1706,7 +1747,7 @@ S2.define('select2/selection/multiple',[
1706
1747
  '.select2-selection__choice__remove',
1707
1748
  function (evt) {
1708
1749
  // Ignore the event if it is disabled
1709
- if (self.options.get('disabled')) {
1750
+ if (self.isDisabled()) {
1710
1751
  return;
1711
1752
  }
1712
1753
 
@@ -1721,6 +1762,19 @@ S2.define('select2/selection/multiple',[
1721
1762
  });
1722
1763
  }
1723
1764
  );
1765
+
1766
+ this.$selection.on(
1767
+ 'keydown',
1768
+ '.select2-selection__choice__remove',
1769
+ function (evt) {
1770
+ // Ignore the event if it is disabled
1771
+ if (self.isDisabled()) {
1772
+ return;
1773
+ }
1774
+
1775
+ evt.stopPropagation();
1776
+ }
1777
+ );
1724
1778
  };
1725
1779
 
1726
1780
  MultipleSelection.prototype.clear = function () {
@@ -1739,9 +1793,11 @@ S2.define('select2/selection/multiple',[
1739
1793
  MultipleSelection.prototype.selectionContainer = function () {
1740
1794
  var $container = $(
1741
1795
  '<li class="select2-selection__choice">' +
1742
- '<span class="select2-selection__choice__remove" role="presentation">' +
1743
- '&times;' +
1744
- '</span>' +
1796
+ '<button type="button" class="select2-selection__choice__remove" ' +
1797
+ 'tabindex="-1">' +
1798
+ '<span aria-hidden="true">&times;</span>' +
1799
+ '</button>' +
1800
+ '<span class="select2-selection__choice__display"></span>' +
1745
1801
  '</li>'
1746
1802
  );
1747
1803
 
@@ -1757,13 +1813,26 @@ S2.define('select2/selection/multiple',[
1757
1813
 
1758
1814
  var $selections = [];
1759
1815
 
1816
+ var selectionIdPrefix = this.$selection.find('.select2-selection__rendered')
1817
+ .attr('id') + '-choice-';
1818
+
1760
1819
  for (var d = 0; d < data.length; d++) {
1761
1820
  var selection = data[d];
1762
1821
 
1763
1822
  var $selection = this.selectionContainer();
1764
1823
  var formatted = this.display(selection, $selection);
1765
1824
 
1766
- $selection.append(formatted);
1825
+ var selectionId = selectionIdPrefix + Utils.generateChars(4) + '-';
1826
+
1827
+ if (selection.id) {
1828
+ selectionId += selection.id;
1829
+ } else {
1830
+ selectionId += Utils.generateChars(4);
1831
+ }
1832
+
1833
+ $selection.find('.select2-selection__choice__display')
1834
+ .append(formatted)
1835
+ .attr('id', selectionId);
1767
1836
 
1768
1837
  var title = selection.title || selection.text;
1769
1838
 
@@ -1771,6 +1840,14 @@ S2.define('select2/selection/multiple',[
1771
1840
  $selection.attr('title', title);
1772
1841
  }
1773
1842
 
1843
+ var removeItem = this.options.get('translations').get('removeItem');
1844
+
1845
+ var $remove = $selection.find('.select2-selection__choice__remove');
1846
+
1847
+ $remove.attr('title', removeItem());
1848
+ $remove.attr('aria-label', removeItem());
1849
+ $remove.attr('aria-describedby', selectionId);
1850
+
1774
1851
  Utils.StoreData($selection[0], 'data', selection);
1775
1852
 
1776
1853
  $selections.push($selection);
@@ -1778,15 +1855,15 @@ S2.define('select2/selection/multiple',[
1778
1855
 
1779
1856
  var $rendered = this.$selection.find('.select2-selection__rendered');
1780
1857
 
1781
- Utils.appendMany($rendered, $selections);
1858
+ $rendered.append($selections);
1782
1859
  };
1783
1860
 
1784
1861
  return MultipleSelection;
1785
1862
  });
1786
1863
 
1787
1864
  S2.define('select2/selection/placeholder',[
1788
- '../utils'
1789
- ], function (Utils) {
1865
+
1866
+ ], function () {
1790
1867
  function Placeholder (decorated, $element, options) {
1791
1868
  this.placeholder = this.normalizePlaceholder(options.get('placeholder'));
1792
1869
 
@@ -1808,8 +1885,8 @@ S2.define('select2/selection/placeholder',[
1808
1885
  var $placeholder = this.selectionContainer();
1809
1886
 
1810
1887
  $placeholder.html(this.display(placeholder));
1811
- $placeholder.addClass('select2-selection__placeholder')
1812
- .removeClass('select2-selection__choice');
1888
+ $placeholder[0].classList.add('select2-selection__placeholder');
1889
+ $placeholder[0].classList.remove('select2-selection__choice');
1813
1890
 
1814
1891
  return $placeholder;
1815
1892
  };
@@ -1867,7 +1944,7 @@ S2.define('select2/selection/allowClear',[
1867
1944
 
1868
1945
  AllowClear.prototype._handleClear = function (_, evt) {
1869
1946
  // Ignore the event if it is disabled
1870
- if (this.options.get('disabled')) {
1947
+ if (this.isDisabled()) {
1871
1948
  return;
1872
1949
  }
1873
1950
 
@@ -1910,7 +1987,7 @@ S2.define('select2/selection/allowClear',[
1910
1987
  }
1911
1988
  }
1912
1989
 
1913
- this.$element.trigger('change');
1990
+ this.$element.trigger('input').trigger('change');
1914
1991
 
1915
1992
  this.trigger('toggle', {});
1916
1993
  };
@@ -1928,21 +2005,29 @@ S2.define('select2/selection/allowClear',[
1928
2005
  AllowClear.prototype.update = function (decorated, data) {
1929
2006
  decorated.call(this, data);
1930
2007
 
2008
+ this.$selection.find('.select2-selection__clear').remove();
2009
+
1931
2010
  if (this.$selection.find('.select2-selection__placeholder').length > 0 ||
1932
2011
  data.length === 0) {
1933
2012
  return;
1934
2013
  }
1935
2014
 
1936
- var removeAll = this.options.get('translations').get('removeAllItems');
2015
+ var selectionId = this.$selection.find('.select2-selection__rendered')
2016
+ .attr('id');
2017
+
2018
+ var removeAll = this.options.get('translations').get('removeAllItems');
1937
2019
 
1938
2020
  var $remove = $(
1939
- '<span class="select2-selection__clear" title="' + removeAll() +'">' +
1940
- '&times;' +
1941
- '</span>'
2021
+ '<button type="button" class="select2-selection__clear" tabindex="-1">' +
2022
+ '<span aria-hidden="true">&times;</span>' +
2023
+ '</button>'
1942
2024
  );
2025
+ $remove.attr('title', removeAll());
2026
+ $remove.attr('aria-label', removeAll());
2027
+ $remove.attr('aria-describedby', selectionId);
1943
2028
  Utils.StoreData($remove[0], 'data', data);
1944
2029
 
1945
- this.$selection.find('.select2-selection__rendered').prepend($remove);
2030
+ this.$selection.prepend($remove);
1946
2031
  };
1947
2032
 
1948
2033
  return AllowClear;
@@ -1959,19 +2044,22 @@ S2.define('select2/selection/search',[
1959
2044
 
1960
2045
  Search.prototype.render = function (decorated) {
1961
2046
  var $search = $(
1962
- '<li class="select2-search select2-search--inline">' +
2047
+ '<span class="select2-search select2-search--inline">' +
1963
2048
  '<input class="select2-search__field" type="search" tabindex="-1"' +
1964
- ' autocomplete="off" autocorrect="off" autocapitalize="none"' +
2049
+ ' autocorrect="off" autocapitalize="none"' +
1965
2050
  ' spellcheck="false" role="searchbox" aria-autocomplete="list" />' +
1966
- '</li>'
2051
+ '</span>'
1967
2052
  );
1968
2053
 
1969
2054
  this.$searchContainer = $search;
1970
2055
  this.$search = $search.find('input');
1971
2056
 
2057
+ this.$search.prop('autocomplete', this.options.get('autocomplete'));
2058
+
1972
2059
  var $rendered = decorated.call(this);
1973
2060
 
1974
2061
  this._transferTabIndex();
2062
+ $rendered.append(this.$searchContainer);
1975
2063
 
1976
2064
  return $rendered;
1977
2065
  };
@@ -1980,9 +2068,12 @@ S2.define('select2/selection/search',[
1980
2068
  var self = this;
1981
2069
 
1982
2070
  var resultsId = container.id + '-results';
2071
+ var selectionId = container.id + '-container';
1983
2072
 
1984
2073
  decorated.call(this, container, $container);
1985
2074
 
2075
+ self.$search.attr('aria-describedby', selectionId);
2076
+
1986
2077
  container.on('open', function () {
1987
2078
  self.$search.attr('aria-controls', resultsId);
1988
2079
  self.$search.trigger('focus');
@@ -1990,6 +2081,7 @@ S2.define('select2/selection/search',[
1990
2081
 
1991
2082
  container.on('close', function () {
1992
2083
  self.$search.val('');
2084
+ self.resizeSearch();
1993
2085
  self.$search.removeAttr('aria-controls');
1994
2086
  self.$search.removeAttr('aria-activedescendant');
1995
2087
  self.$search.trigger('focus');
@@ -2035,8 +2127,8 @@ S2.define('select2/selection/search',[
2035
2127
  var key = evt.which;
2036
2128
 
2037
2129
  if (key === KEYS.BACKSPACE && self.$search.val() === '') {
2038
- var $previousChoice = self.$searchContainer
2039
- .prev('.select2-selection__choice');
2130
+ var $previousChoice = self.$selection
2131
+ .find('.select2-selection__choice').last();
2040
2132
 
2041
2133
  if ($previousChoice.length > 0) {
2042
2134
  var item = Utils.GetData($previousChoice[0], 'data');
@@ -2134,9 +2226,6 @@ S2.define('select2/selection/search',[
2134
2226
 
2135
2227
  decorated.call(this, data);
2136
2228
 
2137
- this.$selection.find('.select2-selection__rendered')
2138
- .append(this.$searchContainer);
2139
-
2140
2229
  this.resizeSearch();
2141
2230
  if (searchHadFocus) {
2142
2231
  this.$search.trigger('focus');
@@ -2169,11 +2258,9 @@ S2.define('select2/selection/search',[
2169
2258
  Search.prototype.resizeSearch = function () {
2170
2259
  this.$search.css('width', '25px');
2171
2260
 
2172
- var width = '';
2261
+ var width = '100%';
2173
2262
 
2174
- if (this.$search.attr('placeholder') !== '') {
2175
- width = this.$selection.find('.select2-selection__rendered').width();
2176
- } else {
2263
+ if (this.$search.attr('placeholder') === '') {
2177
2264
  var minimumWidth = this.$search.val().length + 1;
2178
2265
 
2179
2266
  width = (minimumWidth * 0.75) + 'em';
@@ -2185,6 +2272,30 @@ S2.define('select2/selection/search',[
2185
2272
  return Search;
2186
2273
  });
2187
2274
 
2275
+ S2.define('select2/selection/selectionCss',[
2276
+ '../utils'
2277
+ ], function (Utils) {
2278
+ function SelectionCSS () { }
2279
+
2280
+ SelectionCSS.prototype.render = function (decorated) {
2281
+ var $selection = decorated.call(this);
2282
+
2283
+ var selectionCssClass = this.options.get('selectionCssClass') || '';
2284
+
2285
+ if (selectionCssClass.indexOf(':all:') !== -1) {
2286
+ selectionCssClass = selectionCssClass.replace(':all:', '');
2287
+
2288
+ Utils.copyNonInternalCssClasses($selection[0], this.$element[0]);
2289
+ }
2290
+
2291
+ $selection.addClass(selectionCssClass);
2292
+
2293
+ return $selection;
2294
+ };
2295
+
2296
+ return SelectionCSS;
2297
+ });
2298
+
2188
2299
  S2.define('select2/selection/eventRelay',[
2189
2300
  'jquery'
2190
2301
  ], function ($) {
@@ -2208,7 +2319,7 @@ S2.define('select2/selection/eventRelay',[
2208
2319
 
2209
2320
  container.on('*', function (name, params) {
2210
2321
  // Ignore events that should not be relayed
2211
- if ($.inArray(name, relayEvents) === -1) {
2322
+ if (relayEvents.indexOf(name) === -1) {
2212
2323
  return;
2213
2324
  }
2214
2325
 
@@ -2223,7 +2334,7 @@ S2.define('select2/selection/eventRelay',[
2223
2334
  self.$element.trigger(evt);
2224
2335
 
2225
2336
  // Only handle preventable events if it was one
2226
- if ($.inArray(name, preventableEvents) === -1) {
2337
+ if (preventableEvents.indexOf(name) === -1) {
2227
2338
  return;
2228
2339
  }
2229
2340
 
@@ -3178,16 +3289,14 @@ S2.define('select2/data/select',[
3178
3289
  Utils.Extend(SelectAdapter, BaseAdapter);
3179
3290
 
3180
3291
  SelectAdapter.prototype.current = function (callback) {
3181
- var data = [];
3182
3292
  var self = this;
3183
3293
 
3184
- this.$element.find(':selected').each(function () {
3185
- var $option = $(this);
3186
-
3187
- var option = self.item($option);
3188
-
3189
- data.push(option);
3190
- });
3294
+ var data = Array.prototype.map.call(
3295
+ this.$element[0].querySelectorAll(':checked'),
3296
+ function (selectedElement) {
3297
+ return self.item($(selectedElement));
3298
+ }
3299
+ );
3191
3300
 
3192
3301
  callback(data);
3193
3302
  };
@@ -3198,10 +3307,12 @@ S2.define('select2/data/select',[
3198
3307
  data.selected = true;
3199
3308
 
3200
3309
  // If data.element is a DOM node, use it instead
3201
- if ($(data.element).is('option')) {
3310
+ if (
3311
+ data.element != null && data.element.tagName.toLowerCase() === 'option'
3312
+ ) {
3202
3313
  data.element.selected = true;
3203
3314
 
3204
- this.$element.trigger('change');
3315
+ this.$element.trigger('input').trigger('change');
3205
3316
 
3206
3317
  return;
3207
3318
  }
@@ -3216,19 +3327,19 @@ S2.define('select2/data/select',[
3216
3327
  for (var d = 0; d < data.length; d++) {
3217
3328
  var id = data[d].id;
3218
3329
 
3219
- if ($.inArray(id, val) === -1) {
3330
+ if (val.indexOf(id) === -1) {
3220
3331
  val.push(id);
3221
3332
  }
3222
3333
  }
3223
3334
 
3224
3335
  self.$element.val(val);
3225
- self.$element.trigger('change');
3336
+ self.$element.trigger('input').trigger('change');
3226
3337
  });
3227
3338
  } else {
3228
3339
  var val = data.id;
3229
3340
 
3230
3341
  this.$element.val(val);
3231
- this.$element.trigger('change');
3342
+ this.$element.trigger('input').trigger('change');
3232
3343
  }
3233
3344
  };
3234
3345
 
@@ -3241,10 +3352,13 @@ S2.define('select2/data/select',[
3241
3352
 
3242
3353
  data.selected = false;
3243
3354
 
3244
- if ($(data.element).is('option')) {
3355
+ if (
3356
+ data.element != null &&
3357
+ data.element.tagName.toLowerCase() === 'option'
3358
+ ) {
3245
3359
  data.element.selected = false;
3246
3360
 
3247
- this.$element.trigger('change');
3361
+ this.$element.trigger('input').trigger('change');
3248
3362
 
3249
3363
  return;
3250
3364
  }
@@ -3255,14 +3369,14 @@ S2.define('select2/data/select',[
3255
3369
  for (var d = 0; d < currentData.length; d++) {
3256
3370
  var id = currentData[d].id;
3257
3371
 
3258
- if (id !== data.id && $.inArray(id, val) === -1) {
3372
+ if (id !== data.id && val.indexOf(id) === -1) {
3259
3373
  val.push(id);
3260
3374
  }
3261
3375
  }
3262
3376
 
3263
3377
  self.$element.val(val);
3264
3378
 
3265
- self.$element.trigger('change');
3379
+ self.$element.trigger('input').trigger('change');
3266
3380
  });
3267
3381
  };
3268
3382
 
@@ -3295,12 +3409,15 @@ S2.define('select2/data/select',[
3295
3409
  var $options = this.$element.children();
3296
3410
 
3297
3411
  $options.each(function () {
3298
- var $option = $(this);
3299
-
3300
- if (!$option.is('option') && !$option.is('optgroup')) {
3412
+ if (
3413
+ this.tagName.toLowerCase() !== 'option' &&
3414
+ this.tagName.toLowerCase() !== 'optgroup'
3415
+ ) {
3301
3416
  return;
3302
3417
  }
3303
3418
 
3419
+ var $option = $(this);
3420
+
3304
3421
  var option = self.item($option);
3305
3422
 
3306
3423
  var matches = self.matches(params, option);
@@ -3316,7 +3433,7 @@ S2.define('select2/data/select',[
3316
3433
  };
3317
3434
 
3318
3435
  SelectAdapter.prototype.addOptions = function ($options) {
3319
- Utils.appendMany(this.$element, $options);
3436
+ this.$element.append($options);
3320
3437
  };
3321
3438
 
3322
3439
  SelectAdapter.prototype.option = function (data) {
@@ -3351,15 +3468,13 @@ S2.define('select2/data/select',[
3351
3468
  option.title = data.title;
3352
3469
  }
3353
3470
 
3354
- var $option = $(option);
3355
-
3356
3471
  var normalizedData = this._normalizeItem(data);
3357
3472
  normalizedData.element = option;
3358
3473
 
3359
3474
  // Override the option's data with the combined data
3360
3475
  Utils.StoreData(option, 'data', normalizedData);
3361
3476
 
3362
- return $option;
3477
+ return $(option);
3363
3478
  };
3364
3479
 
3365
3480
  SelectAdapter.prototype.item = function ($option) {
@@ -3371,7 +3486,9 @@ S2.define('select2/data/select',[
3371
3486
  return data;
3372
3487
  }
3373
3488
 
3374
- if ($option.is('option')) {
3489
+ var option = $option[0];
3490
+
3491
+ if (option.tagName.toLowerCase() === 'option') {
3375
3492
  data = {
3376
3493
  id: $option.val(),
3377
3494
  text: $option.text(),
@@ -3379,7 +3496,7 @@ S2.define('select2/data/select',[
3379
3496
  selected: $option.prop('selected'),
3380
3497
  title: $option.prop('title')
3381
3498
  };
3382
- } else if ($option.is('optgroup')) {
3499
+ } else if (option.tagName.toLowerCase() === 'optgroup') {
3383
3500
  data = {
3384
3501
  text: $option.prop('label'),
3385
3502
  children: [],
@@ -3503,7 +3620,7 @@ S2.define('select2/data/array',[
3503
3620
  var item = this._normalizeItem(data[d]);
3504
3621
 
3505
3622
  // Skip items which were pre-loaded, only merge the data
3506
- if ($.inArray(item.id, existingIds) >= 0) {
3623
+ if (existingIds.indexOf(item.id) >= 0) {
3507
3624
  var $existingOption = $existing.filter(onlyItem(item));
3508
3625
 
3509
3626
  var existingData = this.item($existingOption);
@@ -3521,7 +3638,7 @@ S2.define('select2/data/array',[
3521
3638
  if (item.children) {
3522
3639
  var $children = this.convertToOptions(item.children);
3523
3640
 
3524
- Utils.appendMany($option, $children);
3641
+ $option.append($children);
3525
3642
  }
3526
3643
 
3527
3644
  $options.push($option);
@@ -3605,7 +3722,7 @@ S2.define('select2/data/ajax',[
3605
3722
 
3606
3723
  if (self.options.get('debug') && window.console && console.error) {
3607
3724
  // Check to make sure that the response included a `results` key.
3608
- if (!results || !results.results || !$.isArray(results.results)) {
3725
+ if (!results || !results.results || !Array.isArray(results.results)) {
3609
3726
  console.error(
3610
3727
  'Select2: The AJAX results did not return an array in the ' +
3611
3728
  '`results` key of the response.'
@@ -3664,7 +3781,7 @@ S2.define('select2/data/tags',[
3664
3781
 
3665
3782
  decorated.call(this, $element, options);
3666
3783
 
3667
- if ($.isArray(tags)) {
3784
+ if (Array.isArray(tags)) {
3668
3785
  for (var t = 0; t < tags.length; t++) {
3669
3786
  var tag = tags[t];
3670
3787
  var item = this._normalizeItem(tag);
@@ -3740,7 +3857,11 @@ S2.define('select2/data/tags',[
3740
3857
  };
3741
3858
 
3742
3859
  Tags.prototype.createTag = function (decorated, params) {
3743
- var term = $.trim(params.term);
3860
+ if (params.term == null) {
3861
+ return null;
3862
+ }
3863
+
3864
+ var term = params.term.trim();
3744
3865
 
3745
3866
  if (term === '') {
3746
3867
  return null;
@@ -3855,7 +3976,7 @@ S2.define('select2/data/tokenizer',[
3855
3976
  while (i < term.length) {
3856
3977
  var termChar = term[i];
3857
3978
 
3858
- if ($.inArray(termChar, separators) === -1) {
3979
+ if (separators.indexOf(termChar) === -1) {
3859
3980
  i++;
3860
3981
 
3861
3982
  continue;
@@ -4050,9 +4171,8 @@ S2.define('select2/dropdown',[
4050
4171
  });
4051
4172
 
4052
4173
  S2.define('select2/dropdown/search',[
4053
- 'jquery',
4054
- '../utils'
4055
- ], function ($, Utils) {
4174
+ 'jquery'
4175
+ ], function ($) {
4056
4176
  function Search () { }
4057
4177
 
4058
4178
  Search.prototype.render = function (decorated) {
@@ -4061,7 +4181,7 @@ S2.define('select2/dropdown/search',[
4061
4181
  var $search = $(
4062
4182
  '<span class="select2-search select2-search--dropdown">' +
4063
4183
  '<input class="select2-search__field" type="search" tabindex="-1"' +
4064
- ' autocomplete="off" autocorrect="off" autocapitalize="none"' +
4184
+ ' autocorrect="off" autocapitalize="none"' +
4065
4185
  ' spellcheck="false" role="searchbox" aria-autocomplete="list" />' +
4066
4186
  '</span>'
4067
4187
  );
@@ -4069,6 +4189,8 @@ S2.define('select2/dropdown/search',[
4069
4189
  this.$searchContainer = $search;
4070
4190
  this.$search = $search.find('input');
4071
4191
 
4192
+ this.$search.prop('autocomplete', this.options.get('autocomplete'));
4193
+
4072
4194
  $rendered.prepend($search);
4073
4195
 
4074
4196
  return $rendered;
@@ -4130,9 +4252,9 @@ S2.define('select2/dropdown/search',[
4130
4252
  var showSearch = self.showSearch(params);
4131
4253
 
4132
4254
  if (showSearch) {
4133
- self.$searchContainer.removeClass('select2-search--hide');
4255
+ self.$searchContainer[0].classList.remove('select2-search--hide');
4134
4256
  } else {
4135
- self.$searchContainer.addClass('select2-search--hide');
4257
+ self.$searchContainer[0].classList.add('select2-search--hide');
4136
4258
  }
4137
4259
  }
4138
4260
  });
@@ -4306,7 +4428,7 @@ S2.define('select2/dropdown/attachBody',[
4306
4428
  '../utils'
4307
4429
  ], function ($, Utils) {
4308
4430
  function AttachBody (decorated, $element, options) {
4309
- this.$dropdownParent = options.get('dropdownParent') || $(document.body);
4431
+ this.$dropdownParent = $(options.get('dropdownParent') || document.body);
4310
4432
 
4311
4433
  decorated.call(this, $element, options);
4312
4434
  }
@@ -4319,6 +4441,9 @@ S2.define('select2/dropdown/attachBody',[
4319
4441
  container.on('open', function () {
4320
4442
  self._showDropdown();
4321
4443
  self._attachPositioningHandler(container);
4444
+
4445
+ // Must bind after the results handlers to ensure correct sizing
4446
+ self._bindContainerResultHandlers(container);
4322
4447
  });
4323
4448
 
4324
4449
  container.on('close', function () {
@@ -4326,31 +4451,6 @@ S2.define('select2/dropdown/attachBody',[
4326
4451
  self._detachPositioningHandler(container);
4327
4452
  });
4328
4453
 
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
-
4354
4454
  this.$dropdownContainer.on('mousedown', function (evt) {
4355
4455
  evt.stopPropagation();
4356
4456
  });
@@ -4366,8 +4466,8 @@ S2.define('select2/dropdown/attachBody',[
4366
4466
  // Clone all of the container classes
4367
4467
  $dropdown.attr('class', $container.attr('class'));
4368
4468
 
4369
- $dropdown.removeClass('select2');
4370
- $dropdown.addClass('select2-container--open');
4469
+ $dropdown[0].classList.remove('select2');
4470
+ $dropdown[0].classList.add('select2-container--open');
4371
4471
 
4372
4472
  $dropdown.css({
4373
4473
  position: 'absolute',
@@ -4392,6 +4492,44 @@ S2.define('select2/dropdown/attachBody',[
4392
4492
  this.$dropdownContainer.detach();
4393
4493
  };
4394
4494
 
4495
+ AttachBody.prototype._bindContainerResultHandlers =
4496
+ function (decorated, container) {
4497
+
4498
+ // These should only be bound once
4499
+ if (this._containerResultsHandlersBound) {
4500
+ return;
4501
+ }
4502
+
4503
+ var self = this;
4504
+
4505
+ container.on('results:all', function () {
4506
+ self._positionDropdown();
4507
+ self._resizeDropdown();
4508
+ });
4509
+
4510
+ container.on('results:append', function () {
4511
+ self._positionDropdown();
4512
+ self._resizeDropdown();
4513
+ });
4514
+
4515
+ container.on('results:message', function () {
4516
+ self._positionDropdown();
4517
+ self._resizeDropdown();
4518
+ });
4519
+
4520
+ container.on('select', function () {
4521
+ self._positionDropdown();
4522
+ self._resizeDropdown();
4523
+ });
4524
+
4525
+ container.on('unselect', function () {
4526
+ self._positionDropdown();
4527
+ self._resizeDropdown();
4528
+ });
4529
+
4530
+ this._containerResultsHandlersBound = true;
4531
+ };
4532
+
4395
4533
  AttachBody.prototype._attachPositioningHandler =
4396
4534
  function (decorated, container) {
4397
4535
  var self = this;
@@ -4435,8 +4573,10 @@ S2.define('select2/dropdown/attachBody',[
4435
4573
  AttachBody.prototype._positionDropdown = function () {
4436
4574
  var $window = $(window);
4437
4575
 
4438
- var isCurrentlyAbove = this.$dropdown.hasClass('select2-dropdown--above');
4439
- var isCurrentlyBelow = this.$dropdown.hasClass('select2-dropdown--below');
4576
+ var isCurrentlyAbove = this.$dropdown[0].classList
4577
+ .contains('select2-dropdown--above');
4578
+ var isCurrentlyBelow = this.$dropdown[0].classList
4579
+ .contains('select2-dropdown--below');
4440
4580
 
4441
4581
  var newDirection = null;
4442
4582
 
@@ -4477,7 +4617,17 @@ S2.define('select2/dropdown/attachBody',[
4477
4617
  $offsetParent = $offsetParent.offsetParent();
4478
4618
  }
4479
4619
 
4480
- var parentOffset = $offsetParent.offset();
4620
+ var parentOffset = {
4621
+ top: 0,
4622
+ left: 0
4623
+ };
4624
+
4625
+ if (
4626
+ $.contains(document.body, $offsetParent[0]) ||
4627
+ $offsetParent[0].isConnected
4628
+ ) {
4629
+ parentOffset = $offsetParent.offset();
4630
+ }
4481
4631
 
4482
4632
  css.top -= parentOffset.top;
4483
4633
  css.left -= parentOffset.left;
@@ -4498,12 +4648,13 @@ S2.define('select2/dropdown/attachBody',[
4498
4648
  }
4499
4649
 
4500
4650
  if (newDirection != null) {
4501
- this.$dropdown
4502
- .removeClass('select2-dropdown--below select2-dropdown--above')
4503
- .addClass('select2-dropdown--' + newDirection);
4504
- this.$container
4505
- .removeClass('select2-container--below select2-container--above')
4506
- .addClass('select2-container--' + newDirection);
4651
+ this.$dropdown[0].classList.remove('select2-dropdown--below');
4652
+ this.$dropdown[0].classList.remove('select2-dropdown--above');
4653
+ this.$dropdown[0].classList.add('select2-dropdown--' + newDirection);
4654
+
4655
+ this.$container[0].classList.remove('select2-container--below');
4656
+ this.$container[0].classList.remove('select2-container--above');
4657
+ this.$container[0].classList.add('select2-container--' + newDirection);
4507
4658
  }
4508
4659
 
4509
4660
  this.$dropdownContainer.css(css);
@@ -4660,6 +4811,30 @@ S2.define('select2/dropdown/closeOnSelect',[
4660
4811
  return CloseOnSelect;
4661
4812
  });
4662
4813
 
4814
+ S2.define('select2/dropdown/dropdownCss',[
4815
+ '../utils'
4816
+ ], function (Utils) {
4817
+ function DropdownCSS () { }
4818
+
4819
+ DropdownCSS.prototype.render = function (decorated) {
4820
+ var $dropdown = decorated.call(this);
4821
+
4822
+ var dropdownCssClass = this.options.get('dropdownCssClass') || '';
4823
+
4824
+ if (dropdownCssClass.indexOf(':all:') !== -1) {
4825
+ dropdownCssClass = dropdownCssClass.replace(':all:', '');
4826
+
4827
+ Utils.copyNonInternalCssClasses($dropdown[0], this.$element[0]);
4828
+ }
4829
+
4830
+ $dropdown.addClass(dropdownCssClass);
4831
+
4832
+ return $dropdown;
4833
+ };
4834
+
4835
+ return DropdownCSS;
4836
+ });
4837
+
4663
4838
  S2.define('select2/i18n/en',[],function () {
4664
4839
  // English
4665
4840
  return {
@@ -4704,13 +4879,15 @@ S2.define('select2/i18n/en',[],function () {
4704
4879
  },
4705
4880
  removeAllItems: function () {
4706
4881
  return 'Remove all items';
4882
+ },
4883
+ removeItem: function () {
4884
+ return 'Remove item';
4707
4885
  }
4708
4886
  };
4709
4887
  });
4710
4888
 
4711
4889
  S2.define('select2/defaults',[
4712
4890
  'jquery',
4713
- 'require',
4714
4891
 
4715
4892
  './results',
4716
4893
 
@@ -4719,6 +4896,7 @@ S2.define('select2/defaults',[
4719
4896
  './selection/placeholder',
4720
4897
  './selection/allowClear',
4721
4898
  './selection/search',
4899
+ './selection/selectionCss',
4722
4900
  './selection/eventRelay',
4723
4901
 
4724
4902
  './utils',
@@ -4742,14 +4920,15 @@ S2.define('select2/defaults',[
4742
4920
  './dropdown/minimumResultsForSearch',
4743
4921
  './dropdown/selectOnClose',
4744
4922
  './dropdown/closeOnSelect',
4923
+ './dropdown/dropdownCss',
4745
4924
 
4746
4925
  './i18n/en'
4747
- ], function ($, require,
4926
+ ], function ($,
4748
4927
 
4749
4928
  ResultsList,
4750
4929
 
4751
4930
  SingleSelection, MultipleSelection, Placeholder, AllowClear,
4752
- SelectionSearch, EventRelay,
4931
+ SelectionSearch, SelectionCSS, EventRelay,
4753
4932
 
4754
4933
  Utils, Translation, DIACRITICS,
4755
4934
 
@@ -4758,6 +4937,7 @@ S2.define('select2/defaults',[
4758
4937
 
4759
4938
  Dropdown, DropdownSearch, HidePlaceholder, InfiniteScroll,
4760
4939
  AttachBody, MinimumResultsForSearch, SelectOnClose, CloseOnSelect,
4940
+ DropdownCSS,
4761
4941
 
4762
4942
  EnglishTranslation) {
4763
4943
  function Defaults () {
@@ -4807,24 +4987,6 @@ S2.define('select2/defaults',[
4807
4987
  Tokenizer
4808
4988
  );
4809
4989
  }
4810
-
4811
- if (options.query != null) {
4812
- var Query = require(options.amdBase + 'compat/query');
4813
-
4814
- options.dataAdapter = Utils.Decorate(
4815
- options.dataAdapter,
4816
- Query
4817
- );
4818
- }
4819
-
4820
- if (options.initSelection != null) {
4821
- var InitSelection = require(options.amdBase + 'compat/initSelection');
4822
-
4823
- options.dataAdapter = Utils.Decorate(
4824
- options.dataAdapter,
4825
- InitSelection
4826
- );
4827
- }
4828
4990
  }
4829
4991
 
4830
4992
  if (options.resultsAdapter == null) {
@@ -4875,13 +5037,7 @@ S2.define('select2/defaults',[
4875
5037
  );
4876
5038
  }
4877
5039
 
4878
- if (
4879
- options.dropdownCssClass != null ||
4880
- options.dropdownCss != null ||
4881
- options.adaptDropdownCssClass != null
4882
- ) {
4883
- var DropdownCSS = require(options.amdBase + 'compat/dropdownCss');
4884
-
5040
+ if (options.dropdownCssClass != null) {
4885
5041
  options.dropdownAdapter = Utils.Decorate(
4886
5042
  options.dropdownAdapter,
4887
5043
  DropdownCSS
@@ -4923,16 +5079,10 @@ S2.define('select2/defaults',[
4923
5079
  );
4924
5080
  }
4925
5081
 
4926
- if (
4927
- options.containerCssClass != null ||
4928
- options.containerCss != null ||
4929
- options.adaptContainerCssClass != null
4930
- ) {
4931
- var ContainerCSS = require(options.amdBase + 'compat/containerCss');
4932
-
5082
+ if (options.selectionCssClass != null) {
4933
5083
  options.selectionAdapter = Utils.Decorate(
4934
5084
  options.selectionAdapter,
4935
- ContainerCSS
5085
+ SelectionCSS
4936
5086
  );
4937
5087
  }
4938
5088
 
@@ -4981,7 +5131,7 @@ S2.define('select2/defaults',[
4981
5131
 
4982
5132
  function matcher (params, data) {
4983
5133
  // Always return the object if there is nothing to compare
4984
- if ($.trim(params.term) === '') {
5134
+ if (params.term == null || params.term.trim() === '') {
4985
5135
  return data;
4986
5136
  }
4987
5137
 
@@ -5025,8 +5175,8 @@ S2.define('select2/defaults',[
5025
5175
  }
5026
5176
 
5027
5177
  this.defaults = {
5028
- amdBase: './',
5029
5178
  amdLanguageBase: './i18n/',
5179
+ autocomplete: 'off',
5030
5180
  closeOnSelect: true,
5031
5181
  debug: false,
5032
5182
  dropdownAutoWidth: false,
@@ -5086,7 +5236,7 @@ S2.define('select2/defaults',[
5086
5236
 
5087
5237
  var languages;
5088
5238
 
5089
- if (!$.isArray(language)) {
5239
+ if (!Array.isArray(language)) {
5090
5240
  languages = [language];
5091
5241
  } else {
5092
5242
  languages = language;
@@ -5167,11 +5317,10 @@ S2.define('select2/defaults',[
5167
5317
  });
5168
5318
 
5169
5319
  S2.define('select2/options',[
5170
- 'require',
5171
5320
  'jquery',
5172
5321
  './defaults',
5173
5322
  './utils'
5174
- ], function (require, $, Defaults, Utils) {
5323
+ ], function ($, Defaults, Utils) {
5175
5324
  function Options (options, $element) {
5176
5325
  this.options = options;
5177
5326
 
@@ -5184,15 +5333,6 @@ S2.define('select2/options',[
5184
5333
  }
5185
5334
 
5186
5335
  this.options = Defaults.apply(this.options);
5187
-
5188
- if ($element && $element.is('input')) {
5189
- var InputCompat = require(this.get('amdBase') + 'compat/inputData');
5190
-
5191
- this.options.dataAdapter = Utils.Decorate(
5192
- this.options.dataAdapter,
5193
- InputCompat
5194
- );
5195
- }
5196
5336
  }
5197
5337
 
5198
5338
  Options.prototype.fromElement = function ($e) {
@@ -5206,6 +5346,10 @@ S2.define('select2/options',[
5206
5346
  this.options.disabled = $e.prop('disabled');
5207
5347
  }
5208
5348
 
5349
+ if (this.options.autocomplete == null && $e.prop('autocomplete')) {
5350
+ this.options.autocomplete = $e.prop('autocomplete');
5351
+ }
5352
+
5209
5353
  if (this.options.dir == null) {
5210
5354
  if ($e.prop('dir')) {
5211
5355
  this.options.dir = $e.prop('dir');
@@ -5284,7 +5428,7 @@ S2.define('select2/options',[
5284
5428
  data = Utils._convertData(data);
5285
5429
 
5286
5430
  for (var key in data) {
5287
- if ($.inArray(key, excludedData) > -1) {
5431
+ if (excludedData.indexOf(key) > -1) {
5288
5432
  continue;
5289
5433
  }
5290
5434
 
@@ -5388,7 +5532,7 @@ S2.define('select2/core',[
5388
5532
  });
5389
5533
 
5390
5534
  // Hide the original select
5391
- $element.addClass('select2-hidden-accessible');
5535
+ $element[0].classList.add('select2-hidden-accessible');
5392
5536
  $element.attr('aria-hidden', 'true');
5393
5537
 
5394
5538
  // Synchronize any monitored attributes
@@ -5508,42 +5652,15 @@ S2.define('select2/core',[
5508
5652
  this._syncA = Utils.bind(this._syncAttributes, this);
5509
5653
  this._syncS = Utils.bind(this._syncSubtree, this);
5510
5654
 
5511
- if (this.$element[0].attachEvent) {
5512
- this.$element[0].attachEvent('onpropertychange', this._syncA);
5513
- }
5514
-
5515
- var observer = window.MutationObserver ||
5516
- window.WebKitMutationObserver ||
5517
- window.MozMutationObserver
5518
- ;
5519
-
5520
- if (observer != null) {
5521
- this._observer = new observer(function (mutations) {
5522
- $.each(mutations, self._syncA);
5523
- $.each(mutations, self._syncS);
5524
- });
5525
- this._observer.observe(this.$element[0], {
5526
- attributes: true,
5527
- childList: true,
5528
- subtree: false
5529
- });
5530
- } else if (this.$element[0].addEventListener) {
5531
- this.$element[0].addEventListener(
5532
- 'DOMAttrModified',
5533
- self._syncA,
5534
- false
5535
- );
5536
- this.$element[0].addEventListener(
5537
- 'DOMNodeInserted',
5538
- self._syncS,
5539
- false
5540
- );
5541
- this.$element[0].addEventListener(
5542
- 'DOMNodeRemoved',
5543
- self._syncS,
5544
- false
5545
- );
5546
- }
5655
+ this._observer = new window.MutationObserver(function (mutations) {
5656
+ self._syncA();
5657
+ self._syncS(mutations);
5658
+ });
5659
+ this._observer.observe(this.$element[0], {
5660
+ attributes: true,
5661
+ childList: true,
5662
+ subtree: false
5663
+ });
5547
5664
  };
5548
5665
 
5549
5666
  Select2.prototype._registerDataEvents = function () {
@@ -5567,7 +5684,7 @@ S2.define('select2/core',[
5567
5684
  });
5568
5685
 
5569
5686
  this.selection.on('*', function (name, params) {
5570
- if ($.inArray(name, nonRelayEvents) !== -1) {
5687
+ if (nonRelayEvents.indexOf(name) !== -1) {
5571
5688
  return;
5572
5689
  }
5573
5690
 
@@ -5595,23 +5712,23 @@ S2.define('select2/core',[
5595
5712
  var self = this;
5596
5713
 
5597
5714
  this.on('open', function () {
5598
- self.$container.addClass('select2-container--open');
5715
+ self.$container[0].classList.add('select2-container--open');
5599
5716
  });
5600
5717
 
5601
5718
  this.on('close', function () {
5602
- self.$container.removeClass('select2-container--open');
5719
+ self.$container[0].classList.remove('select2-container--open');
5603
5720
  });
5604
5721
 
5605
5722
  this.on('enable', function () {
5606
- self.$container.removeClass('select2-container--disabled');
5723
+ self.$container[0].classList.remove('select2-container--disabled');
5607
5724
  });
5608
5725
 
5609
5726
  this.on('disable', function () {
5610
- self.$container.addClass('select2-container--disabled');
5727
+ self.$container[0].classList.add('select2-container--disabled');
5611
5728
  });
5612
5729
 
5613
5730
  this.on('blur', function () {
5614
- self.$container.removeClass('select2-container--focus');
5731
+ self.$container[0].classList.remove('select2-container--focus');
5615
5732
  });
5616
5733
 
5617
5734
  this.on('query', function (params) {
@@ -5642,7 +5759,7 @@ S2.define('select2/core',[
5642
5759
  if (self.isOpen()) {
5643
5760
  if (key === KEYS.ESC || key === KEYS.TAB ||
5644
5761
  (key === KEYS.UP && evt.altKey)) {
5645
- self.close();
5762
+ self.close(evt);
5646
5763
 
5647
5764
  evt.preventDefault();
5648
5765
  } else if (key === KEYS.ENTER) {
@@ -5676,7 +5793,7 @@ S2.define('select2/core',[
5676
5793
  Select2.prototype._syncAttributes = function () {
5677
5794
  this.options.set('disabled', this.$element.prop('disabled'));
5678
5795
 
5679
- if (this.options.get('disabled')) {
5796
+ if (this.isDisabled()) {
5680
5797
  if (this.isOpen()) {
5681
5798
  this.close();
5682
5799
  }
@@ -5687,36 +5804,32 @@ S2.define('select2/core',[
5687
5804
  }
5688
5805
  };
5689
5806
 
5690
- Select2.prototype._syncSubtree = function (evt, mutations) {
5691
- var changed = false;
5807
+ Select2.prototype._isChangeMutation = function (mutations) {
5692
5808
  var self = this;
5693
5809
 
5694
- // Ignore any mutation events raised for elements that aren't options or
5695
- // optgroups. This handles the case when the select element is destroyed
5696
- if (
5697
- evt && evt.target && (
5698
- evt.target.nodeName !== 'OPTION' && evt.target.nodeName !== 'OPTGROUP'
5699
- )
5700
- ) {
5701
- return;
5702
- }
5703
-
5704
- if (!mutations) {
5705
- // If mutation events aren't supported, then we can only assume that the
5706
- // change affected the selections
5707
- changed = true;
5708
- } else if (mutations.addedNodes && mutations.addedNodes.length > 0) {
5810
+ if (mutations.addedNodes && mutations.addedNodes.length > 0) {
5709
5811
  for (var n = 0; n < mutations.addedNodes.length; n++) {
5710
5812
  var node = mutations.addedNodes[n];
5711
5813
 
5712
5814
  if (node.selected) {
5713
- changed = true;
5815
+ return true;
5714
5816
  }
5715
5817
  }
5716
5818
  } else if (mutations.removedNodes && mutations.removedNodes.length > 0) {
5717
- changed = true;
5819
+ return true;
5820
+ } else if (Array.isArray(mutations)) {
5821
+ return mutations.some(function (mutation) {
5822
+ return self._isChangeMutation(mutation);
5823
+ });
5718
5824
  }
5719
5825
 
5826
+ return false;
5827
+ };
5828
+
5829
+ Select2.prototype._syncSubtree = function (mutations) {
5830
+ var changed = this._isChangeMutation(mutations);
5831
+ var self = this;
5832
+
5720
5833
  // Only re-pull the data if we think there is a change
5721
5834
  if (changed) {
5722
5835
  this.dataAdapter.current(function (currentData) {
@@ -5766,7 +5879,7 @@ S2.define('select2/core',[
5766
5879
  };
5767
5880
 
5768
5881
  Select2.prototype.toggleDropdown = function () {
5769
- if (this.options.get('disabled')) {
5882
+ if (this.isDisabled()) {
5770
5883
  return;
5771
5884
  }
5772
5885
 
@@ -5782,23 +5895,48 @@ S2.define('select2/core',[
5782
5895
  return;
5783
5896
  }
5784
5897
 
5898
+ if (this.isDisabled()) {
5899
+ return;
5900
+ }
5901
+
5785
5902
  this.trigger('query', {});
5786
5903
  };
5787
5904
 
5788
- Select2.prototype.close = function () {
5905
+ Select2.prototype.close = function (evt) {
5789
5906
  if (!this.isOpen()) {
5790
5907
  return;
5791
5908
  }
5792
5909
 
5793
- this.trigger('close', {});
5910
+ this.trigger('close', { originalEvent : evt });
5911
+ };
5912
+
5913
+ /**
5914
+ * Helper method to abstract the "enabled" (not "disabled") state of this
5915
+ * object.
5916
+ *
5917
+ * @return {true} if the instance is not disabled.
5918
+ * @return {false} if the instance is disabled.
5919
+ */
5920
+ Select2.prototype.isEnabled = function () {
5921
+ return !this.isDisabled();
5922
+ };
5923
+
5924
+ /**
5925
+ * Helper method to abstract the "disabled" state of this object.
5926
+ *
5927
+ * @return {true} if the disabled option is true.
5928
+ * @return {false} if the disabled option is false.
5929
+ */
5930
+ Select2.prototype.isDisabled = function () {
5931
+ return this.options.get('disabled');
5794
5932
  };
5795
5933
 
5796
5934
  Select2.prototype.isOpen = function () {
5797
- return this.$container.hasClass('select2-container--open');
5935
+ return this.$container[0].classList.contains('select2-container--open');
5798
5936
  };
5799
5937
 
5800
5938
  Select2.prototype.hasFocus = function () {
5801
- return this.$container.hasClass('select2-container--focus');
5939
+ return this.$container[0].classList.contains('select2-container--focus');
5802
5940
  };
5803
5941
 
5804
5942
  Select2.prototype.focus = function (data) {
@@ -5807,7 +5945,7 @@ S2.define('select2/core',[
5807
5945
  return;
5808
5946
  }
5809
5947
 
5810
- this.$container.addClass('select2-container--focus');
5948
+ this.$container[0].classList.add('select2-container--focus');
5811
5949
  this.trigger('focus', {});
5812
5950
  };
5813
5951
 
@@ -5861,33 +5999,20 @@ S2.define('select2/core',[
5861
5999
 
5862
6000
  var newVal = args[0];
5863
6001
 
5864
- if ($.isArray(newVal)) {
5865
- newVal = $.map(newVal, function (obj) {
6002
+ if (Array.isArray(newVal)) {
6003
+ newVal = newVal.map(function (obj) {
5866
6004
  return obj.toString();
5867
6005
  });
5868
6006
  }
5869
6007
 
5870
- this.$element.val(newVal).trigger('change');
6008
+ this.$element.val(newVal).trigger('input').trigger('change');
5871
6009
  };
5872
6010
 
5873
6011
  Select2.prototype.destroy = function () {
5874
6012
  this.$container.remove();
5875
6013
 
5876
- if (this.$element[0].detachEvent) {
5877
- this.$element[0].detachEvent('onpropertychange', this._syncA);
5878
- }
5879
-
5880
- if (this._observer != null) {
5881
- this._observer.disconnect();
5882
- this._observer = null;
5883
- } else if (this.$element[0].removeEventListener) {
5884
- this.$element[0]
5885
- .removeEventListener('DOMAttrModified', this._syncA, false);
5886
- this.$element[0]
5887
- .removeEventListener('DOMNodeInserted', this._syncS, false);
5888
- this.$element[0]
5889
- .removeEventListener('DOMNodeRemoved', this._syncS, false);
5890
- }
6014
+ this._observer.disconnect();
6015
+ this._observer = null;
5891
6016
 
5892
6017
  this._syncA = null;
5893
6018
  this._syncS = null;
@@ -5896,7 +6021,7 @@ S2.define('select2/core',[
5896
6021
  this.$element.attr('tabindex',
5897
6022
  Utils.GetData(this.$element[0], 'old-tabindex'));
5898
6023
 
5899
- this.$element.removeClass('select2-hidden-accessible');
6024
+ this.$element[0].classList.remove('select2-hidden-accessible');
5900
6025
  this.$element.attr('aria-hidden', 'false');
5901
6026
  Utils.RemoveData(this.$element[0]);
5902
6027
  this.$element.removeData('select2');
@@ -5924,7 +6049,8 @@ S2.define('select2/core',[
5924
6049
 
5925
6050
  this.$container = $container;
5926
6051
 
5927
- this.$container.addClass('select2-container--' + this.options.get('theme'));
6052
+ this.$container[0].classList
6053
+ .add('select2-container--' + this.options.get('theme'));
5928
6054
 
5929
6055
  Utils.StoreData($container[0], 'element', this.$element);
5930
6056
 
@@ -5934,406 +6060,6 @@ S2.define('select2/core',[
5934
6060
  return Select2;
5935
6061
  });
5936
6062
 
5937
- S2.define('select2/compat/utils',[
5938
- 'jquery'
5939
- ], function ($) {
5940
- function syncCssClasses ($dest, $src, adapter) {
5941
- var classes, replacements = [], adapted;
5942
-
5943
- classes = $.trim($dest.attr('class'));
5944
-
5945
- if (classes) {
5946
- classes = '' + classes; // for IE which returns object
5947
-
5948
- $(classes.split(/\s+/)).each(function () {
5949
- // Save all Select2 classes
5950
- if (this.indexOf('select2-') === 0) {
5951
- replacements.push(this);
5952
- }
5953
- });
5954
- }
5955
-
5956
- classes = $.trim($src.attr('class'));
5957
-
5958
- if (classes) {
5959
- classes = '' + classes; // for IE which returns object
5960
-
5961
- $(classes.split(/\s+/)).each(function () {
5962
- // Only adapt non-Select2 classes
5963
- if (this.indexOf('select2-') !== 0) {
5964
- adapted = adapter(this);
5965
-
5966
- if (adapted != null) {
5967
- replacements.push(adapted);
5968
- }
5969
- }
5970
- });
5971
- }
5972
-
5973
- $dest.attr('class', replacements.join(' '));
5974
- }
5975
-
5976
- return {
5977
- syncCssClasses: syncCssClasses
5978
- };
5979
- });
5980
-
5981
- S2.define('select2/compat/containerCss',[
5982
- 'jquery',
5983
- './utils'
5984
- ], function ($, CompatUtils) {
5985
- // No-op CSS adapter that discards all classes by default
5986
- function _containerAdapter (clazz) {
5987
- return null;
5988
- }
5989
-
5990
- function ContainerCSS () { }
5991
-
5992
- ContainerCSS.prototype.render = function (decorated) {
5993
- var $container = decorated.call(this);
5994
-
5995
- var containerCssClass = this.options.get('containerCssClass') || '';
5996
-
5997
- if ($.isFunction(containerCssClass)) {
5998
- containerCssClass = containerCssClass(this.$element);
5999
- }
6000
-
6001
- var containerCssAdapter = this.options.get('adaptContainerCssClass');
6002
- containerCssAdapter = containerCssAdapter || _containerAdapter;
6003
-
6004
- if (containerCssClass.indexOf(':all:') !== -1) {
6005
- containerCssClass = containerCssClass.replace(':all:', '');
6006
-
6007
- var _cssAdapter = containerCssAdapter;
6008
-
6009
- containerCssAdapter = function (clazz) {
6010
- var adapted = _cssAdapter(clazz);
6011
-
6012
- if (adapted != null) {
6013
- // Append the old one along with the adapted one
6014
- return adapted + ' ' + clazz;
6015
- }
6016
-
6017
- return clazz;
6018
- };
6019
- }
6020
-
6021
- var containerCss = this.options.get('containerCss') || {};
6022
-
6023
- if ($.isFunction(containerCss)) {
6024
- containerCss = containerCss(this.$element);
6025
- }
6026
-
6027
- CompatUtils.syncCssClasses($container, this.$element, containerCssAdapter);
6028
-
6029
- $container.css(containerCss);
6030
- $container.addClass(containerCssClass);
6031
-
6032
- return $container;
6033
- };
6034
-
6035
- return ContainerCSS;
6036
- });
6037
-
6038
- S2.define('select2/compat/dropdownCss',[
6039
- 'jquery',
6040
- './utils'
6041
- ], function ($, CompatUtils) {
6042
- // No-op CSS adapter that discards all classes by default
6043
- function _dropdownAdapter (clazz) {
6044
- return null;
6045
- }
6046
-
6047
- function DropdownCSS () { }
6048
-
6049
- DropdownCSS.prototype.render = function (decorated) {
6050
- var $dropdown = decorated.call(this);
6051
-
6052
- var dropdownCssClass = this.options.get('dropdownCssClass') || '';
6053
-
6054
- if ($.isFunction(dropdownCssClass)) {
6055
- dropdownCssClass = dropdownCssClass(this.$element);
6056
- }
6057
-
6058
- var dropdownCssAdapter = this.options.get('adaptDropdownCssClass');
6059
- dropdownCssAdapter = dropdownCssAdapter || _dropdownAdapter;
6060
-
6061
- if (dropdownCssClass.indexOf(':all:') !== -1) {
6062
- dropdownCssClass = dropdownCssClass.replace(':all:', '');
6063
-
6064
- var _cssAdapter = dropdownCssAdapter;
6065
-
6066
- dropdownCssAdapter = function (clazz) {
6067
- var adapted = _cssAdapter(clazz);
6068
-
6069
- if (adapted != null) {
6070
- // Append the old one along with the adapted one
6071
- return adapted + ' ' + clazz;
6072
- }
6073
-
6074
- return clazz;
6075
- };
6076
- }
6077
-
6078
- var dropdownCss = this.options.get('dropdownCss') || {};
6079
-
6080
- if ($.isFunction(dropdownCss)) {
6081
- dropdownCss = dropdownCss(this.$element);
6082
- }
6083
-
6084
- CompatUtils.syncCssClasses($dropdown, this.$element, dropdownCssAdapter);
6085
-
6086
- $dropdown.css(dropdownCss);
6087
- $dropdown.addClass(dropdownCssClass);
6088
-
6089
- return $dropdown;
6090
- };
6091
-
6092
- return DropdownCSS;
6093
- });
6094
-
6095
- S2.define('select2/compat/initSelection',[
6096
- 'jquery'
6097
- ], function ($) {
6098
- function InitSelection (decorated, $element, options) {
6099
- if (options.get('debug') && window.console && console.warn) {
6100
- console.warn(
6101
- 'Select2: The `initSelection` option has been deprecated in favor' +
6102
- ' of a custom data adapter that overrides the `current` method. ' +
6103
- 'This method is now called multiple times instead of a single ' +
6104
- 'time when the instance is initialized. Support will be removed ' +
6105
- 'for the `initSelection` option in future versions of Select2'
6106
- );
6107
- }
6108
-
6109
- this.initSelection = options.get('initSelection');
6110
- this._isInitialized = false;
6111
-
6112
- decorated.call(this, $element, options);
6113
- }
6114
-
6115
- InitSelection.prototype.current = function (decorated, callback) {
6116
- var self = this;
6117
-
6118
- if (this._isInitialized) {
6119
- decorated.call(this, callback);
6120
-
6121
- return;
6122
- }
6123
-
6124
- this.initSelection.call(null, this.$element, function (data) {
6125
- self._isInitialized = true;
6126
-
6127
- if (!$.isArray(data)) {
6128
- data = [data];
6129
- }
6130
-
6131
- callback(data);
6132
- });
6133
- };
6134
-
6135
- return InitSelection;
6136
- });
6137
-
6138
- S2.define('select2/compat/inputData',[
6139
- 'jquery',
6140
- '../utils'
6141
- ], function ($, Utils) {
6142
- function InputData (decorated, $element, options) {
6143
- this._currentData = [];
6144
- this._valueSeparator = options.get('valueSeparator') || ',';
6145
-
6146
- if ($element.prop('type') === 'hidden') {
6147
- if (options.get('debug') && console && console.warn) {
6148
- console.warn(
6149
- 'Select2: Using a hidden input with Select2 is no longer ' +
6150
- 'supported and may stop working in the future. It is recommended ' +
6151
- 'to use a `<select>` element instead.'
6152
- );
6153
- }
6154
- }
6155
-
6156
- decorated.call(this, $element, options);
6157
- }
6158
-
6159
- InputData.prototype.current = function (_, callback) {
6160
- function getSelected (data, selectedIds) {
6161
- var selected = [];
6162
-
6163
- if (data.selected || $.inArray(data.id, selectedIds) !== -1) {
6164
- data.selected = true;
6165
- selected.push(data);
6166
- } else {
6167
- data.selected = false;
6168
- }
6169
-
6170
- if (data.children) {
6171
- selected.push.apply(selected, getSelected(data.children, selectedIds));
6172
- }
6173
-
6174
- return selected;
6175
- }
6176
-
6177
- var selected = [];
6178
-
6179
- for (var d = 0; d < this._currentData.length; d++) {
6180
- var data = this._currentData[d];
6181
-
6182
- selected.push.apply(
6183
- selected,
6184
- getSelected(
6185
- data,
6186
- this.$element.val().split(
6187
- this._valueSeparator
6188
- )
6189
- )
6190
- );
6191
- }
6192
-
6193
- callback(selected);
6194
- };
6195
-
6196
- InputData.prototype.select = function (_, data) {
6197
- if (!this.options.get('multiple')) {
6198
- this.current(function (allData) {
6199
- $.map(allData, function (data) {
6200
- data.selected = false;
6201
- });
6202
- });
6203
-
6204
- this.$element.val(data.id);
6205
- this.$element.trigger('change');
6206
- } else {
6207
- var value = this.$element.val();
6208
- value += this._valueSeparator + data.id;
6209
-
6210
- this.$element.val(value);
6211
- this.$element.trigger('change');
6212
- }
6213
- };
6214
-
6215
- InputData.prototype.unselect = function (_, data) {
6216
- var self = this;
6217
-
6218
- data.selected = false;
6219
-
6220
- this.current(function (allData) {
6221
- var values = [];
6222
-
6223
- for (var d = 0; d < allData.length; d++) {
6224
- var item = allData[d];
6225
-
6226
- if (data.id == item.id) {
6227
- continue;
6228
- }
6229
-
6230
- values.push(item.id);
6231
- }
6232
-
6233
- self.$element.val(values.join(self._valueSeparator));
6234
- self.$element.trigger('change');
6235
- });
6236
- };
6237
-
6238
- InputData.prototype.query = function (_, params, callback) {
6239
- var results = [];
6240
-
6241
- for (var d = 0; d < this._currentData.length; d++) {
6242
- var data = this._currentData[d];
6243
-
6244
- var matches = this.matches(params, data);
6245
-
6246
- if (matches !== null) {
6247
- results.push(matches);
6248
- }
6249
- }
6250
-
6251
- callback({
6252
- results: results
6253
- });
6254
- };
6255
-
6256
- InputData.prototype.addOptions = function (_, $options) {
6257
- var options = $.map($options, function ($option) {
6258
- return Utils.GetData($option[0], 'data');
6259
- });
6260
-
6261
- this._currentData.push.apply(this._currentData, options);
6262
- };
6263
-
6264
- return InputData;
6265
- });
6266
-
6267
- S2.define('select2/compat/matcher',[
6268
- 'jquery'
6269
- ], function ($) {
6270
- function oldMatcher (matcher) {
6271
- function wrappedMatcher (params, data) {
6272
- var match = $.extend(true, {}, data);
6273
-
6274
- if (params.term == null || $.trim(params.term) === '') {
6275
- return match;
6276
- }
6277
-
6278
- if (data.children) {
6279
- for (var c = data.children.length - 1; c >= 0; c--) {
6280
- var child = data.children[c];
6281
-
6282
- // Check if the child object matches
6283
- // The old matcher returned a boolean true or false
6284
- var doesMatch = matcher(params.term, child.text, child);
6285
-
6286
- // If the child didn't match, pop it off
6287
- if (!doesMatch) {
6288
- match.children.splice(c, 1);
6289
- }
6290
- }
6291
-
6292
- if (match.children.length > 0) {
6293
- return match;
6294
- }
6295
- }
6296
-
6297
- if (matcher(params.term, data.text, data)) {
6298
- return match;
6299
- }
6300
-
6301
- return null;
6302
- }
6303
-
6304
- return wrappedMatcher;
6305
- }
6306
-
6307
- return oldMatcher;
6308
- });
6309
-
6310
- S2.define('select2/compat/query',[
6311
-
6312
- ], function () {
6313
- function Query (decorated, $element, options) {
6314
- if (options.get('debug') && window.console && console.warn) {
6315
- console.warn(
6316
- 'Select2: The `query` option has been deprecated in favor of a ' +
6317
- 'custom data adapter that overrides the `query` method. Support ' +
6318
- 'will be removed for the `query` option in future versions of ' +
6319
- 'Select2.'
6320
- );
6321
- }
6322
-
6323
- decorated.call(this, $element, options);
6324
- }
6325
-
6326
- Query.prototype.query = function (_, params, callback) {
6327
- params.callback = callback;
6328
-
6329
- var query = this.options.get('query');
6330
-
6331
- query.call(null, params);
6332
- };
6333
-
6334
- return Query;
6335
- });
6336
-
6337
6063
  S2.define('select2/dropdown/attachContainer',[
6338
6064
 
6339
6065
  ], function () {
@@ -6346,8 +6072,8 @@ S2.define('select2/dropdown/attachContainer',[
6346
6072
  var $dropdownContainer = $container.find('.dropdown-wrapper');
6347
6073
  $dropdownContainer.append($dropdown);
6348
6074
 
6349
- $dropdown.addClass('select2-dropdown--below');
6350
- $container.addClass('select2-container--below');
6075
+ $dropdown[0].classList.add('select2-dropdown--below');
6076
+ $container[0].classList.add('select2-container--below');
6351
6077
  };
6352
6078
 
6353
6079
  return AttachContainer;
@@ -6694,7 +6420,7 @@ S2.define('jquery.select2',[
6694
6420
  });
6695
6421
 
6696
6422
  // Check if we should be returning `this`
6697
- if ($.inArray(options, thisMethods) > -1) {
6423
+ if (thisMethods.indexOf(options) > -1) {
6698
6424
  return this;
6699
6425
  }
6700
6426