select2-rails 4.0.5 → 4.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) 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 +237 -80
  5. data/vendor/assets/javascripts/select2.js +233 -77
  6. data/vendor/assets/javascripts/select2_locale_af.js +2 -2
  7. data/vendor/assets/javascripts/select2_locale_ar.js +2 -2
  8. data/vendor/assets/javascripts/select2_locale_az.js +2 -2
  9. data/vendor/assets/javascripts/select2_locale_bg.js +2 -2
  10. data/vendor/assets/javascripts/select2_locale_bn.js +3 -0
  11. data/vendor/assets/javascripts/select2_locale_bs.js +2 -2
  12. data/vendor/assets/javascripts/select2_locale_ca.js +2 -2
  13. data/vendor/assets/javascripts/select2_locale_cs.js +2 -2
  14. data/vendor/assets/javascripts/select2_locale_da.js +2 -2
  15. data/vendor/assets/javascripts/select2_locale_de.js +2 -2
  16. data/vendor/assets/javascripts/select2_locale_dsb.js +2 -2
  17. data/vendor/assets/javascripts/select2_locale_el.js +2 -2
  18. data/vendor/assets/javascripts/select2_locale_en.js +2 -2
  19. data/vendor/assets/javascripts/select2_locale_es.js +2 -2
  20. data/vendor/assets/javascripts/select2_locale_et.js +2 -2
  21. data/vendor/assets/javascripts/select2_locale_eu.js +2 -2
  22. data/vendor/assets/javascripts/select2_locale_fa.js +2 -2
  23. data/vendor/assets/javascripts/select2_locale_fi.js +2 -2
  24. data/vendor/assets/javascripts/select2_locale_fr.js +2 -2
  25. data/vendor/assets/javascripts/select2_locale_gl.js +2 -2
  26. data/vendor/assets/javascripts/select2_locale_he.js +2 -2
  27. data/vendor/assets/javascripts/select2_locale_hi.js +2 -2
  28. data/vendor/assets/javascripts/select2_locale_hr.js +2 -2
  29. data/vendor/assets/javascripts/select2_locale_hsb.js +2 -2
  30. data/vendor/assets/javascripts/select2_locale_hu.js +2 -2
  31. data/vendor/assets/javascripts/select2_locale_hy.js +2 -2
  32. data/vendor/assets/javascripts/select2_locale_id.js +2 -2
  33. data/vendor/assets/javascripts/select2_locale_is.js +2 -2
  34. data/vendor/assets/javascripts/select2_locale_it.js +2 -2
  35. data/vendor/assets/javascripts/select2_locale_ja.js +2 -2
  36. data/vendor/assets/javascripts/select2_locale_ka.js +3 -0
  37. data/vendor/assets/javascripts/select2_locale_km.js +2 -2
  38. data/vendor/assets/javascripts/select2_locale_ko.js +2 -2
  39. data/vendor/assets/javascripts/select2_locale_lt.js +2 -2
  40. data/vendor/assets/javascripts/select2_locale_lv.js +2 -2
  41. data/vendor/assets/javascripts/select2_locale_mk.js +2 -2
  42. data/vendor/assets/javascripts/select2_locale_ms.js +2 -2
  43. data/vendor/assets/javascripts/select2_locale_nb.js +2 -2
  44. data/vendor/assets/javascripts/select2_locale_ne.js +3 -0
  45. data/vendor/assets/javascripts/select2_locale_nl.js +2 -2
  46. data/vendor/assets/javascripts/select2_locale_pl.js +2 -2
  47. data/vendor/assets/javascripts/select2_locale_ps.js +2 -2
  48. data/vendor/assets/javascripts/select2_locale_pt-BR.js +2 -2
  49. data/vendor/assets/javascripts/select2_locale_pt.js +2 -2
  50. data/vendor/assets/javascripts/select2_locale_ro.js +2 -2
  51. data/vendor/assets/javascripts/select2_locale_ru.js +2 -2
  52. data/vendor/assets/javascripts/select2_locale_sk.js +2 -2
  53. data/vendor/assets/javascripts/select2_locale_sl.js +2 -2
  54. data/vendor/assets/javascripts/select2_locale_sq.js +3 -0
  55. data/vendor/assets/javascripts/select2_locale_sr-Cyrl.js +2 -2
  56. data/vendor/assets/javascripts/select2_locale_sr.js +2 -2
  57. data/vendor/assets/javascripts/select2_locale_sv.js +2 -2
  58. data/vendor/assets/javascripts/select2_locale_th.js +2 -2
  59. data/vendor/assets/javascripts/select2_locale_tk.js +3 -0
  60. data/vendor/assets/javascripts/select2_locale_tr.js +2 -2
  61. data/vendor/assets/javascripts/select2_locale_uk.js +2 -2
  62. data/vendor/assets/javascripts/select2_locale_vi.js +2 -2
  63. data/vendor/assets/javascripts/select2_locale_zh-CN.js +2 -2
  64. data/vendor/assets/javascripts/select2_locale_zh-TW.js +2 -2
  65. data/vendor/assets/stylesheets/select2.css +5 -5
  66. metadata +6 -1
@@ -1,11 +1,11 @@
1
1
  /*!
2
- * Select2 4.0.5
2
+ * Select2 4.0.6
3
3
  * https://select2.github.io
4
4
  *
5
5
  * Released under the MIT license
6
6
  * https://github.com/select2/select2/blob/master/LICENSE.md
7
7
  */
8
- (function (factory) {
8
+ ;(function (factory) {
9
9
  if (typeof define === 'function' && define.amd) {
10
10
  // AMD. Register as an anonymous module.
11
11
  define(['jquery'], factory);
@@ -574,10 +574,10 @@ S2.define('select2/utils',[
574
574
  DecoratedClass.prototype = new ctr();
575
575
 
576
576
  for (var m = 0; m < superMethods.length; m++) {
577
- var superMethod = superMethods[m];
577
+ var superMethod = superMethods[m];
578
578
 
579
- DecoratedClass.prototype[superMethod] =
580
- SuperClass.prototype[superMethod];
579
+ DecoratedClass.prototype[superMethod] =
580
+ SuperClass.prototype[superMethod];
581
581
  }
582
582
 
583
583
  var calledMethod = function (methodName) {
@@ -772,6 +772,68 @@ S2.define('select2/utils',[
772
772
  $element.append($nodes);
773
773
  };
774
774
 
775
+ // Cache objects in Utils.__cache instead of $.data (see #4346)
776
+ Utils.__cache = {};
777
+
778
+ var id = 0;
779
+ Utils.GetUniqueElementId = function (element) {
780
+ // Get a unique element Id. If element has no id,
781
+ // 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.
784
+
785
+ 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
+ }
795
+ }
796
+ return select2Id;
797
+ };
798
+
799
+ Utils.StoreData = function (element, name, value) {
800
+ // Stores an item in the cache for a specified element.
801
+ // name is the cache key.
802
+ var id = Utils.GetUniqueElementId(element);
803
+ if (!Utils.__cache[id]) {
804
+ Utils.__cache[id] = {};
805
+ }
806
+
807
+ Utils.__cache[id][name] = value;
808
+ };
809
+
810
+ Utils.GetData = function (element, name) {
811
+ // Retrieves a value from the cache by its key (name)
812
+ // name is optional. If no name specified, return
813
+ // all cache items for the specified element.
814
+ // and for a specified element.
815
+ var id = Utils.GetUniqueElementId(element);
816
+ if (name) {
817
+ if (Utils.__cache[id]) {
818
+ if (Utils.__cache[id][name] != null) {
819
+ return Utils.__cache[id][name];
820
+ }
821
+ return $(element).data(name); // Fallback to HTML5 data attribs.
822
+ }
823
+ return $(element).data(name); // Fallback to HTML5 data attribs.
824
+ } else {
825
+ return Utils.__cache[id];
826
+ }
827
+ };
828
+
829
+ Utils.RemoveData = function (element) {
830
+ // Removes all cached items for a specified element.
831
+ var id = Utils.GetUniqueElementId(element);
832
+ if (Utils.__cache[id] != null) {
833
+ delete Utils.__cache[id];
834
+ }
835
+ };
836
+
775
837
  return Utils;
776
838
  });
777
839
 
@@ -907,7 +969,7 @@ S2.define('select2/results',[
907
969
  $options.each(function () {
908
970
  var $option = $(this);
909
971
 
910
- var item = $.data(this, 'data');
972
+ var item = Utils.GetData(this, 'data');
911
973
 
912
974
  // id needs to be converted to a string when comparing
913
975
  var id = '' + item.id;
@@ -1012,7 +1074,7 @@ S2.define('select2/results',[
1012
1074
  this.template(data, option);
1013
1075
  }
1014
1076
 
1015
- $.data(option, 'data', data);
1077
+ Utils.StoreData(option, 'data', data);
1016
1078
 
1017
1079
  return option;
1018
1080
  };
@@ -1053,7 +1115,10 @@ S2.define('select2/results',[
1053
1115
  }
1054
1116
 
1055
1117
  self.setClasses();
1056
- self.highlightFirstItem();
1118
+
1119
+ if (self.options.get('scrollAfterSelect')) {
1120
+ self.highlightFirstItem();
1121
+ }
1057
1122
  });
1058
1123
 
1059
1124
  container.on('unselect', function () {
@@ -1062,7 +1127,10 @@ S2.define('select2/results',[
1062
1127
  }
1063
1128
 
1064
1129
  self.setClasses();
1065
- self.highlightFirstItem();
1130
+
1131
+ if (self.options.get('scrollAfterSelect')) {
1132
+ self.highlightFirstItem();
1133
+ }
1066
1134
  });
1067
1135
 
1068
1136
  container.on('open', function () {
@@ -1098,7 +1166,7 @@ S2.define('select2/results',[
1098
1166
  return;
1099
1167
  }
1100
1168
 
1101
- var data = $highlighted.data('data');
1169
+ var data = Utils.GetData($highlighted[0], 'data');
1102
1170
 
1103
1171
  if ($highlighted.attr('aria-selected') == 'true') {
1104
1172
  self.trigger('close', {});
@@ -1116,8 +1184,9 @@ S2.define('select2/results',[
1116
1184
 
1117
1185
  var currentIndex = $options.index($highlighted);
1118
1186
 
1119
- // If we are already at te top, don't move further
1120
- if (currentIndex === 0) {
1187
+ // If we are already at the top, don't move further
1188
+ // If no options, currentIndex will be -1
1189
+ if (currentIndex <= 0) {
1121
1190
  return;
1122
1191
  }
1123
1192
 
@@ -1210,7 +1279,7 @@ S2.define('select2/results',[
1210
1279
  function (evt) {
1211
1280
  var $this = $(this);
1212
1281
 
1213
- var data = $this.data('data');
1282
+ var data = Utils.GetData(this, 'data');
1214
1283
 
1215
1284
  if ($this.attr('aria-selected') === 'true') {
1216
1285
  if (self.options.get('multiple')) {
@@ -1233,7 +1302,7 @@ S2.define('select2/results',[
1233
1302
 
1234
1303
  this.$results.on('mouseenter', '.select2-results__option[aria-selected]',
1235
1304
  function (evt) {
1236
- var data = $(this).data('data');
1305
+ var data = Utils.GetData(this, 'data');
1237
1306
 
1238
1307
  self.getHighlightedResults()
1239
1308
  .removeClass('select2-results__option--highlighted');
@@ -1348,8 +1417,8 @@ S2.define('select2/selection/base',[
1348
1417
 
1349
1418
  this._tabindex = 0;
1350
1419
 
1351
- if (this.$element.data('old-tabindex') != null) {
1352
- this._tabindex = this.$element.data('old-tabindex');
1420
+ if (Utils.GetData(this.$element[0], 'old-tabindex') != null) {
1421
+ this._tabindex = Utils.GetData(this.$element[0], 'old-tabindex');
1353
1422
  } else if (this.$element.attr('tabindex') != null) {
1354
1423
  this._tabindex = this.$element.attr('tabindex');
1355
1424
  }
@@ -1408,8 +1477,10 @@ S2.define('select2/selection/base',[
1408
1477
  self.$selection.removeAttr('aria-activedescendant');
1409
1478
  self.$selection.removeAttr('aria-owns');
1410
1479
 
1411
- self.$selection.focus();
1412
-
1480
+ window.setTimeout(function () {
1481
+ self.$selection.focus();
1482
+ }, 0);
1483
+
1413
1484
  self._detachCloseHandler(container);
1414
1485
  });
1415
1486
 
@@ -1457,7 +1528,7 @@ S2.define('select2/selection/base',[
1457
1528
  return;
1458
1529
  }
1459
1530
 
1460
- var $element = $this.data('element');
1531
+ var $element = Utils.GetData(this, 'element');
1461
1532
 
1462
1533
  $element.select2('close');
1463
1534
  });
@@ -1518,7 +1589,10 @@ S2.define('select2/selection/single',[
1518
1589
 
1519
1590
  var id = container.id + '-container';
1520
1591
 
1521
- this.$selection.find('.select2-selection__rendered').attr('id', id);
1592
+ this.$selection.find('.select2-selection__rendered')
1593
+ .attr('id', id)
1594
+ .attr('role', 'textbox')
1595
+ .attr('aria-readonly', 'true');
1522
1596
  this.$selection.attr('aria-labelledby', id);
1523
1597
 
1524
1598
  this.$selection.on('mousedown', function (evt) {
@@ -1545,14 +1619,12 @@ S2.define('select2/selection/single',[
1545
1619
  self.$selection.focus();
1546
1620
  }
1547
1621
  });
1548
-
1549
- container.on('selection:update', function (params) {
1550
- self.update(params.data);
1551
- });
1552
1622
  };
1553
1623
 
1554
1624
  SingleSelection.prototype.clear = function () {
1555
- this.$selection.find('.select2-selection__rendered').empty();
1625
+ var $rendered = this.$selection.find('.select2-selection__rendered');
1626
+ $rendered.empty();
1627
+ $rendered.removeAttr('title'); // clear tooltip on empty
1556
1628
  };
1557
1629
 
1558
1630
  SingleSelection.prototype.display = function (data, container) {
@@ -1578,7 +1650,7 @@ S2.define('select2/selection/single',[
1578
1650
  var formatted = this.display(selection, $rendered);
1579
1651
 
1580
1652
  $rendered.empty().append(formatted);
1581
- $rendered.prop('title', selection.title || selection.text);
1653
+ $rendered.attr('title', selection.title || selection.text);
1582
1654
  };
1583
1655
 
1584
1656
  return SingleSelection;
@@ -1630,7 +1702,7 @@ S2.define('select2/selection/multiple',[
1630
1702
  var $remove = $(this);
1631
1703
  var $selection = $remove.parent();
1632
1704
 
1633
- var data = $selection.data('data');
1705
+ var data = Utils.GetData($selection[0], 'data');
1634
1706
 
1635
1707
  self.trigger('unselect', {
1636
1708
  originalEvent: evt,
@@ -1641,7 +1713,9 @@ S2.define('select2/selection/multiple',[
1641
1713
  };
1642
1714
 
1643
1715
  MultipleSelection.prototype.clear = function () {
1644
- this.$selection.find('.select2-selection__rendered').empty();
1716
+ var $rendered = this.$selection.find('.select2-selection__rendered');
1717
+ $rendered.empty();
1718
+ $rendered.removeAttr('title');
1645
1719
  };
1646
1720
 
1647
1721
  MultipleSelection.prototype.display = function (data, container) {
@@ -1679,9 +1753,9 @@ S2.define('select2/selection/multiple',[
1679
1753
  var formatted = this.display(selection, $selection);
1680
1754
 
1681
1755
  $selection.append(formatted);
1682
- $selection.prop('title', selection.title || selection.text);
1756
+ $selection.attr('title', selection.title || selection.text);
1683
1757
 
1684
- $selection.data('data', selection);
1758
+ Utils.StoreData($selection[0], 'data', selection);
1685
1759
 
1686
1760
  $selections.push($selection);
1687
1761
  }
@@ -1746,8 +1820,9 @@ S2.define('select2/selection/placeholder',[
1746
1820
 
1747
1821
  S2.define('select2/selection/allowClear',[
1748
1822
  'jquery',
1749
- '../keys'
1750
- ], function ($, KEYS) {
1823
+ '../keys',
1824
+ '../utils'
1825
+ ], function ($, KEYS, Utils) {
1751
1826
  function AllowClear () { }
1752
1827
 
1753
1828
  AllowClear.prototype.bind = function (decorated, container, $container) {
@@ -1789,10 +1864,22 @@ S2.define('select2/selection/allowClear',[
1789
1864
 
1790
1865
  evt.stopPropagation();
1791
1866
 
1792
- var data = $clear.data('data');
1867
+ var data = Utils.GetData($clear[0], 'data');
1868
+
1869
+ var previousVal = this.$element.val();
1870
+ this.$element.val(this.placeholder.id);
1871
+
1872
+ var unselectData = {
1873
+ data: data
1874
+ };
1875
+ this.trigger('clear', unselectData);
1876
+ if (unselectData.prevented) {
1877
+ this.$element.val(previousVal);
1878
+ return;
1879
+ }
1793
1880
 
1794
1881
  for (var d = 0; d < data.length; d++) {
1795
- var unselectData = {
1882
+ unselectData = {
1796
1883
  data: data[d]
1797
1884
  };
1798
1885
 
@@ -1802,11 +1889,12 @@ S2.define('select2/selection/allowClear',[
1802
1889
 
1803
1890
  // If the event was prevented, don't clear it out.
1804
1891
  if (unselectData.prevented) {
1892
+ this.$element.val(previousVal);
1805
1893
  return;
1806
1894
  }
1807
1895
  }
1808
1896
 
1809
- this.$element.val(this.placeholder.id).trigger('change');
1897
+ this.$element.trigger('change');
1810
1898
 
1811
1899
  this.trigger('toggle', {});
1812
1900
  };
@@ -1829,12 +1917,14 @@ S2.define('select2/selection/allowClear',[
1829
1917
  return;
1830
1918
  }
1831
1919
 
1920
+ var removeAll = this.options.get('translations').get('removeAllItems');
1921
+
1832
1922
  var $remove = $(
1833
- '<span class="select2-selection__clear">' +
1923
+ '<span class="select2-selection__clear" title="' + removeAll() +'">' +
1834
1924
  '&times;' +
1835
1925
  '</span>'
1836
1926
  );
1837
- $remove.data('data', data);
1927
+ Utils.StoreData($remove[0], 'data', data);
1838
1928
 
1839
1929
  this.$selection.find('.select2-selection__rendered').prepend($remove);
1840
1930
  };
@@ -1925,7 +2015,7 @@ S2.define('select2/selection/search',[
1925
2015
  .prev('.select2-selection__choice');
1926
2016
 
1927
2017
  if ($previousChoice.length > 0) {
1928
- var item = $previousChoice.data('data');
2018
+ var item = Utils.GetData($previousChoice[0], 'data');
1929
2019
 
1930
2020
  self.searchRemoveChoice(item);
1931
2021
 
@@ -2019,7 +2109,13 @@ S2.define('select2/selection/search',[
2019
2109
 
2020
2110
  this.resizeSearch();
2021
2111
  if (searchHadFocus) {
2022
- this.$search.focus();
2112
+ var isTagInput = this.$element.find('[data-select2-tag]').length;
2113
+ if (isTagInput) {
2114
+ // fix IE11 bug where tag input lost focus
2115
+ this.$element.focus();
2116
+ } else {
2117
+ this.$search.focus();
2118
+ }
2023
2119
  }
2024
2120
  };
2025
2121
 
@@ -2076,10 +2172,13 @@ S2.define('select2/selection/eventRelay',[
2076
2172
  'open', 'opening',
2077
2173
  'close', 'closing',
2078
2174
  'select', 'selecting',
2079
- 'unselect', 'unselecting'
2175
+ 'unselect', 'unselecting',
2176
+ 'clear', 'clearing'
2080
2177
  ];
2081
2178
 
2082
- var preventableEvents = ['opening', 'closing', 'selecting', 'unselecting'];
2179
+ var preventableEvents = [
2180
+ 'opening', 'closing', 'selecting', 'unselecting', 'clearing'
2181
+ ];
2083
2182
 
2084
2183
  decorated.call(this, container, $container);
2085
2184
 
@@ -2412,6 +2511,7 @@ S2.define('select2/diacritics',[
2412
2511
  '\u019F': 'O',
2413
2512
  '\uA74A': 'O',
2414
2513
  '\uA74C': 'O',
2514
+ '\u0152': 'OE',
2415
2515
  '\u01A2': 'OI',
2416
2516
  '\uA74E': 'OO',
2417
2517
  '\u0222': 'OU',
@@ -2821,6 +2921,7 @@ S2.define('select2/diacritics',[
2821
2921
  '\uA74B': 'o',
2822
2922
  '\uA74D': 'o',
2823
2923
  '\u0275': 'o',
2924
+ '\u0153': 'oe',
2824
2925
  '\u01A3': 'oi',
2825
2926
  '\u0223': 'ou',
2826
2927
  '\uA74F': 'oo',
@@ -2989,8 +3090,9 @@ S2.define('select2/diacritics',[
2989
3090
  '\u03CD': '\u03C5',
2990
3091
  '\u03CB': '\u03C5',
2991
3092
  '\u03B0': '\u03C5',
2992
- '\u03C9': '\u03C9',
2993
- '\u03C2': '\u03C3'
3093
+ '\u03CE': '\u03C9',
3094
+ '\u03C2': '\u03C3',
3095
+ '\u2019': '\''
2994
3096
  };
2995
3097
 
2996
3098
  return diacritics;
@@ -3158,7 +3260,7 @@ S2.define('select2/data/select',[
3158
3260
  // Remove anything added to child elements
3159
3261
  this.$element.find('*').each(function () {
3160
3262
  // Remove any custom data set by Select2
3161
- $.removeData(this, 'data');
3263
+ Utils.RemoveData(this);
3162
3264
  });
3163
3265
  };
3164
3266
 
@@ -3231,7 +3333,7 @@ S2.define('select2/data/select',[
3231
3333
  normalizedData.element = option;
3232
3334
 
3233
3335
  // Override the option's data with the combined data
3234
- $.data(option, 'data', normalizedData);
3336
+ Utils.StoreData(option, 'data', normalizedData);
3235
3337
 
3236
3338
  return $option;
3237
3339
  };
@@ -3239,7 +3341,7 @@ S2.define('select2/data/select',[
3239
3341
  SelectAdapter.prototype.item = function ($option) {
3240
3342
  var data = {};
3241
3343
 
3242
- data = $.data($option[0], 'data');
3344
+ data = Utils.GetData($option[0], 'data');
3243
3345
 
3244
3346
  if (data != null) {
3245
3347
  return data;
@@ -3277,13 +3379,13 @@ S2.define('select2/data/select',[
3277
3379
  data = this._normalizeItem(data);
3278
3380
  data.element = $option[0];
3279
3381
 
3280
- $.data($option[0], 'data', data);
3382
+ Utils.StoreData($option[0], 'data', data);
3281
3383
 
3282
3384
  return data;
3283
3385
  };
3284
3386
 
3285
3387
  SelectAdapter.prototype._normalizeItem = function (item) {
3286
- if (!$.isPlainObject(item)) {
3388
+ if (item !== Object(item)) {
3287
3389
  item = {
3288
3390
  id: item,
3289
3391
  text: item
@@ -3487,7 +3589,8 @@ S2.define('select2/data/ajax',[
3487
3589
  }, function () {
3488
3590
  // Attempt to detect if a request was aborted
3489
3591
  // Only works if the transport exposes a status property
3490
- if ($request.status && $request.status === '0') {
3592
+ if ('status' in $request &&
3593
+ ($request.status === 0 || $request.status === '0')) {
3491
3594
  return;
3492
3595
  }
3493
3596
 
@@ -3886,7 +3989,7 @@ S2.define('select2/dropdown',[
3886
3989
  };
3887
3990
 
3888
3991
  Dropdown.prototype.position = function ($dropdown, $container) {
3889
- // Should be implmented in subclasses
3992
+ // Should be implemented in subclasses
3890
3993
  };
3891
3994
 
3892
3995
  Dropdown.prototype.destroy = function () {
@@ -3959,6 +4062,7 @@ S2.define('select2/dropdown/search',[
3959
4062
  self.$search.attr('tabindex', -1);
3960
4063
 
3961
4064
  self.$search.val('');
4065
+ self.$search.blur();
3962
4066
  });
3963
4067
 
3964
4068
  container.on('focus', function () {
@@ -4224,14 +4328,14 @@ S2.define('select2/dropdown/attachBody',[
4224
4328
 
4225
4329
  var $watchers = this.$container.parents().filter(Utils.hasScroll);
4226
4330
  $watchers.each(function () {
4227
- $(this).data('select2-scroll-position', {
4331
+ Utils.StoreData(this, 'select2-scroll-position', {
4228
4332
  x: $(this).scrollLeft(),
4229
4333
  y: $(this).scrollTop()
4230
4334
  });
4231
4335
  });
4232
4336
 
4233
4337
  $watchers.on(scrollEvent, function (ev) {
4234
- var position = $(this).data('select2-scroll-position');
4338
+ var position = Utils.GetData(this, 'select2-scroll-position');
4235
4339
  $(this).scrollTop(position.y);
4236
4340
  });
4237
4341
 
@@ -4290,10 +4394,10 @@ S2.define('select2/dropdown/attachBody',[
4290
4394
  top: container.bottom
4291
4395
  };
4292
4396
 
4293
- // Determine what the parent element is to use for calciulating the offset
4397
+ // Determine what the parent element is to use for calculating the offset
4294
4398
  var $offsetParent = this.$dropdownParent;
4295
4399
 
4296
- // For statically positoned elements, we need to get the element
4400
+ // For statically positioned elements, we need to get the element
4297
4401
  // that is determining the offset
4298
4402
  if ($offsetParent.css('position') === 'static') {
4299
4403
  $offsetParent = $offsetParent.offsetParent();
@@ -4396,8 +4500,8 @@ S2.define('select2/dropdown/minimumResultsForSearch',[
4396
4500
  });
4397
4501
 
4398
4502
  S2.define('select2/dropdown/selectOnClose',[
4399
-
4400
- ], function () {
4503
+ '../utils'
4504
+ ], function (Utils) {
4401
4505
  function SelectOnClose () { }
4402
4506
 
4403
4507
  SelectOnClose.prototype.bind = function (decorated, container, $container) {
@@ -4428,7 +4532,7 @@ S2.define('select2/dropdown/selectOnClose',[
4428
4532
  return;
4429
4533
  }
4430
4534
 
4431
- var data = $highlightedResults.data('data');
4535
+ var data = Utils.GetData($highlightedResults[0], 'data');
4432
4536
 
4433
4537
  // Don't re-select already selected resulte
4434
4538
  if (
@@ -4523,6 +4627,9 @@ S2.define('select2/i18n/en',[],function () {
4523
4627
  },
4524
4628
  searching: function () {
4525
4629
  return 'Searching…';
4630
+ },
4631
+ removeAllItems: function () {
4632
+ return 'Remove all items';
4526
4633
  }
4527
4634
  };
4528
4635
  });
@@ -4894,6 +5001,7 @@ S2.define('select2/defaults',[
4894
5001
  maximumSelectionLength: 0,
4895
5002
  minimumResultsForSearch: 0,
4896
5003
  selectOnClose: false,
5004
+ scrollAfterSelect: false,
4897
5005
  sorter: function (data) {
4898
5006
  return data;
4899
5007
  },
@@ -4916,7 +5024,7 @@ S2.define('select2/defaults',[
4916
5024
 
4917
5025
  var convertedData = Utils._convertData(data);
4918
5026
 
4919
- $.extend(this.defaults, convertedData);
5027
+ $.extend(true, this.defaults, convertedData);
4920
5028
  };
4921
5029
 
4922
5030
  var defaults = new Defaults();
@@ -4981,7 +5089,7 @@ S2.define('select2/options',[
4981
5089
  $e.prop('disabled', this.options.disabled);
4982
5090
  $e.prop('multiple', this.options.multiple);
4983
5091
 
4984
- if ($e.data('select2Tags')) {
5092
+ if (Utils.GetData($e[0], 'select2Tags')) {
4985
5093
  if (this.options.debug && window.console && console.warn) {
4986
5094
  console.warn(
4987
5095
  'Select2: The `data-select2-tags` attribute has been changed to ' +
@@ -4990,11 +5098,11 @@ S2.define('select2/options',[
4990
5098
  );
4991
5099
  }
4992
5100
 
4993
- $e.data('data', $e.data('select2Tags'));
4994
- $e.data('tags', true);
5101
+ Utils.StoreData($e[0], 'data', Utils.GetData($e[0], 'select2Tags'));
5102
+ Utils.StoreData($e[0], 'tags', true);
4995
5103
  }
4996
5104
 
4997
- if ($e.data('ajaxUrl')) {
5105
+ if (Utils.GetData($e[0], 'ajaxUrl')) {
4998
5106
  if (this.options.debug && window.console && console.warn) {
4999
5107
  console.warn(
5000
5108
  'Select2: The `data-ajax-url` attribute has been changed to ' +
@@ -5003,21 +5111,45 @@ S2.define('select2/options',[
5003
5111
  );
5004
5112
  }
5005
5113
 
5006
- $e.attr('ajax--url', $e.data('ajaxUrl'));
5007
- $e.data('ajax--url', $e.data('ajaxUrl'));
5114
+ $e.attr('ajax--url', Utils.GetData($e[0], 'ajaxUrl'));
5115
+ Utils.StoreData($e[0], 'ajax-Url', Utils.GetData($e[0], 'ajaxUrl'));
5008
5116
  }
5009
5117
 
5010
5118
  var dataset = {};
5011
5119
 
5120
+ function upperCaseLetter(_, letter) {
5121
+ return letter.toUpperCase();
5122
+ }
5123
+
5124
+ // Pre-load all of the attributes which are prefixed with `data-`
5125
+ for (var attr = 0; attr < $e[0].attributes.length; attr++) {
5126
+ var attributeName = $e[0].attributes[attr].name;
5127
+ var prefix = 'data-';
5128
+
5129
+ if (attributeName.substr(0, prefix.length) == prefix) {
5130
+ // Get the contents of the attribute after `data-`
5131
+ var dataName = attributeName.substring(prefix.length);
5132
+
5133
+ // Get the data contents from the consistent source
5134
+ // This is more than likely the jQuery data helper
5135
+ var dataValue = Utils.GetData($e[0], dataName);
5136
+
5137
+ // camelCase the attribute name to match the spec
5138
+ var camelDataName = dataName.replace(/-([a-z])/g, upperCaseLetter);
5139
+
5140
+ // Store the data attribute contents into the dataset since
5141
+ dataset[camelDataName] = dataValue;
5142
+ }
5143
+ }
5144
+
5012
5145
  // Prefer the element's `dataset` attribute if it exists
5013
5146
  // jQuery 1.x does not correctly handle data attributes with multiple dashes
5014
5147
  if ($.fn.jquery && $.fn.jquery.substr(0, 2) == '1.' && $e[0].dataset) {
5015
- dataset = $.extend(true, {}, $e[0].dataset, $e.data());
5016
- } else {
5017
- dataset = $e.data();
5148
+ dataset = $.extend(true, {}, $e[0].dataset, dataset);
5018
5149
  }
5019
5150
 
5020
- var data = $.extend(true, {}, dataset);
5151
+ // Prefer our internal data cache if it exists
5152
+ var data = $.extend(true, {}, Utils.GetData($e[0]), dataset);
5021
5153
 
5022
5154
  data = Utils._convertData(data);
5023
5155
 
@@ -5054,8 +5186,8 @@ S2.define('select2/core',[
5054
5186
  './keys'
5055
5187
  ], function ($, Options, Utils, KEYS) {
5056
5188
  var Select2 = function ($element, options) {
5057
- if ($element.data('select2') != null) {
5058
- $element.data('select2').destroy();
5189
+ if (Utils.GetData($element[0], 'select2') != null) {
5190
+ Utils.GetData($element[0], 'select2').destroy();
5059
5191
  }
5060
5192
 
5061
5193
  this.$element = $element;
@@ -5071,7 +5203,7 @@ S2.define('select2/core',[
5071
5203
  // Set up the tabindex
5072
5204
 
5073
5205
  var tabindex = $element.attr('tabindex') || 0;
5074
- $element.data('old-tabindex', tabindex);
5206
+ Utils.StoreData($element[0], 'old-tabindex', tabindex);
5075
5207
  $element.attr('tabindex', '-1');
5076
5208
 
5077
5209
  // Set up containers and adapters
@@ -5132,6 +5264,9 @@ S2.define('select2/core',[
5132
5264
  // Synchronize any monitored attributes
5133
5265
  this._syncAttributes();
5134
5266
 
5267
+ Utils.StoreData($element[0], 'select2', this);
5268
+
5269
+ // Ensure backwards compatibility with $element.data('select2').
5135
5270
  $element.data('select2', this);
5136
5271
  };
5137
5272
 
@@ -5322,6 +5457,23 @@ S2.define('select2/core',[
5322
5457
 
5323
5458
  Select2.prototype._registerEvents = function () {
5324
5459
  var self = this;
5460
+
5461
+ this.on('focus', function () {
5462
+ self.$container.addClass('select2-container--focus');
5463
+
5464
+ if (!self.$container.hasClass('select2-container--disabled') &&
5465
+ !self.isOpen()) {
5466
+ if (self.options.get('multiple')) {
5467
+ window.setTimeout(function () {
5468
+ self.open();
5469
+ },
5470
+ self.options.get('ajax') ? 300 : 100);
5471
+ }
5472
+ else {
5473
+ self.open();
5474
+ }
5475
+ }
5476
+ });
5325
5477
 
5326
5478
  this.on('open', function () {
5327
5479
  self.$container.addClass('select2-container--open');
@@ -5466,7 +5618,8 @@ S2.define('select2/core',[
5466
5618
  'open': 'opening',
5467
5619
  'close': 'closing',
5468
5620
  'select': 'selecting',
5469
- 'unselect': 'unselecting'
5621
+ 'unselect': 'unselecting',
5622
+ 'clear': 'clearing'
5470
5623
  };
5471
5624
 
5472
5625
  if (args === undefined) {
@@ -5621,10 +5774,12 @@ S2.define('select2/core',[
5621
5774
  this._syncS = null;
5622
5775
 
5623
5776
  this.$element.off('.select2');
5624
- this.$element.attr('tabindex', this.$element.data('old-tabindex'));
5777
+ this.$element.attr('tabindex',
5778
+ Utils.GetData(this.$element[0], 'old-tabindex'));
5625
5779
 
5626
5780
  this.$element.removeClass('select2-hidden-accessible');
5627
5781
  this.$element.attr('aria-hidden', 'false');
5782
+ Utils.RemoveData(this.$element[0]);
5628
5783
  this.$element.removeData('select2');
5629
5784
 
5630
5785
  this.dataAdapter.destroy();
@@ -5652,7 +5807,7 @@ S2.define('select2/core',[
5652
5807
 
5653
5808
  this.$container.addClass('select2-container--' + this.options.get('theme'));
5654
5809
 
5655
- $container.data('element', this.$element);
5810
+ Utils.StoreData($container[0], 'element', this.$element);
5656
5811
 
5657
5812
  return $container;
5658
5813
  };
@@ -5672,8 +5827,9 @@ S2.define('jquery.select2',[
5672
5827
  'jquery-mousewheel',
5673
5828
 
5674
5829
  './select2/core',
5675
- './select2/defaults'
5676
- ], function ($, _, Select2, Defaults) {
5830
+ './select2/defaults',
5831
+ './select2/utils'
5832
+ ], function ($, _, Select2, Defaults, Utils) {
5677
5833
  if ($.fn.select2 == null) {
5678
5834
  // All methods that should return the element
5679
5835
  var thisMethods = ['open', 'close', 'destroy'];
@@ -5694,7 +5850,7 @@ S2.define('jquery.select2',[
5694
5850
  var args = Array.prototype.slice.call(arguments, 1);
5695
5851
 
5696
5852
  this.each(function () {
5697
- var instance = $(this).data('select2');
5853
+ var instance = Utils.GetData(this, 'select2');
5698
5854
 
5699
5855
  if (instance == null && window.console && console.error) {
5700
5856
  console.error(