select2-rails 4.0.3 → 4.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +8 -2
  3. data/lib/select2-rails/version.rb +1 -1
  4. data/select2-rails.gemspec +1 -1
  5. data/vendor/assets/javascripts/select2-full.js +579 -266
  6. data/vendor/assets/javascripts/select2.js +575 -263
  7. data/vendor/assets/javascripts/select2_locale_af.js +3 -0
  8. data/vendor/assets/javascripts/select2_locale_ar.js +2 -2
  9. data/vendor/assets/javascripts/select2_locale_az.js +2 -2
  10. data/vendor/assets/javascripts/select2_locale_bg.js +2 -2
  11. data/vendor/assets/javascripts/select2_locale_bn.js +3 -0
  12. data/vendor/assets/javascripts/select2_locale_bs.js +3 -0
  13. data/vendor/assets/javascripts/select2_locale_ca.js +2 -2
  14. data/vendor/assets/javascripts/select2_locale_cs.js +2 -2
  15. data/vendor/assets/javascripts/select2_locale_da.js +2 -2
  16. data/vendor/assets/javascripts/select2_locale_de.js +2 -2
  17. data/vendor/assets/javascripts/select2_locale_dsb.js +3 -0
  18. data/vendor/assets/javascripts/select2_locale_el.js +2 -2
  19. data/vendor/assets/javascripts/select2_locale_en.js +2 -2
  20. data/vendor/assets/javascripts/select2_locale_es.js +2 -2
  21. data/vendor/assets/javascripts/select2_locale_et.js +2 -2
  22. data/vendor/assets/javascripts/select2_locale_eu.js +2 -2
  23. data/vendor/assets/javascripts/select2_locale_fa.js +2 -2
  24. data/vendor/assets/javascripts/select2_locale_fi.js +2 -2
  25. data/vendor/assets/javascripts/select2_locale_fr.js +2 -2
  26. data/vendor/assets/javascripts/select2_locale_gl.js +2 -2
  27. data/vendor/assets/javascripts/select2_locale_he.js +2 -2
  28. data/vendor/assets/javascripts/select2_locale_hi.js +2 -2
  29. data/vendor/assets/javascripts/select2_locale_hr.js +2 -2
  30. data/vendor/assets/javascripts/select2_locale_hsb.js +3 -0
  31. data/vendor/assets/javascripts/select2_locale_hu.js +2 -2
  32. data/vendor/assets/javascripts/select2_locale_hy.js +3 -0
  33. data/vendor/assets/javascripts/select2_locale_id.js +2 -2
  34. data/vendor/assets/javascripts/select2_locale_is.js +2 -2
  35. data/vendor/assets/javascripts/select2_locale_it.js +2 -2
  36. data/vendor/assets/javascripts/select2_locale_ja.js +2 -2
  37. data/vendor/assets/javascripts/select2_locale_ka.js +3 -0
  38. data/vendor/assets/javascripts/select2_locale_km.js +2 -2
  39. data/vendor/assets/javascripts/select2_locale_ko.js +2 -2
  40. data/vendor/assets/javascripts/select2_locale_lt.js +2 -2
  41. data/vendor/assets/javascripts/select2_locale_lv.js +2 -2
  42. data/vendor/assets/javascripts/select2_locale_mk.js +2 -2
  43. data/vendor/assets/javascripts/select2_locale_ms.js +2 -2
  44. data/vendor/assets/javascripts/select2_locale_nb.js +2 -2
  45. data/vendor/assets/javascripts/select2_locale_ne.js +3 -0
  46. data/vendor/assets/javascripts/select2_locale_nl.js +2 -2
  47. data/vendor/assets/javascripts/select2_locale_pl.js +2 -2
  48. data/vendor/assets/javascripts/select2_locale_ps.js +3 -0
  49. data/vendor/assets/javascripts/select2_locale_pt-BR.js +2 -2
  50. data/vendor/assets/javascripts/select2_locale_pt.js +2 -2
  51. data/vendor/assets/javascripts/select2_locale_ro.js +2 -2
  52. data/vendor/assets/javascripts/select2_locale_ru.js +2 -2
  53. data/vendor/assets/javascripts/select2_locale_sk.js +2 -2
  54. data/vendor/assets/javascripts/select2_locale_sl.js +3 -0
  55. data/vendor/assets/javascripts/select2_locale_sq.js +3 -0
  56. data/vendor/assets/javascripts/select2_locale_sr-Cyrl.js +2 -2
  57. data/vendor/assets/javascripts/select2_locale_sr.js +2 -2
  58. data/vendor/assets/javascripts/select2_locale_sv.js +2 -2
  59. data/vendor/assets/javascripts/select2_locale_th.js +2 -2
  60. data/vendor/assets/javascripts/select2_locale_tk.js +3 -0
  61. data/vendor/assets/javascripts/select2_locale_tr.js +2 -2
  62. data/vendor/assets/javascripts/select2_locale_uk.js +2 -2
  63. data/vendor/assets/javascripts/select2_locale_vi.js +2 -2
  64. data/vendor/assets/javascripts/select2_locale_zh-CN.js +2 -2
  65. data/vendor/assets/javascripts/select2_locale_zh-TW.js +2 -2
  66. data/vendor/assets/stylesheets/select2.css +8 -11
  67. metadata +18 -8
@@ -1,27 +1,41 @@
1
1
  /*!
2
- * Select2 4.0.3
2
+ * Select2 4.0.10
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);
12
- } else if (typeof exports === 'object') {
12
+ } else if (typeof module === 'object' && module.exports) {
13
13
  // Node/CommonJS
14
- factory(require('jquery'));
14
+ module.exports = function (root, jQuery) {
15
+ if (jQuery === undefined) {
16
+ // require('jQuery') returns a factory that requires window to
17
+ // build a jQuery instance, we normalize how we use modules
18
+ // that require this pattern but the window provided is a noop
19
+ // if it's defined (how jquery works)
20
+ if (typeof window !== 'undefined') {
21
+ jQuery = require('jquery');
22
+ }
23
+ else {
24
+ jQuery = require('jquery')(root);
25
+ }
26
+ }
27
+ factory(jQuery);
28
+ return jQuery;
29
+ };
15
30
  } else {
16
31
  // Browser globals
17
32
  factory(jQuery);
18
33
  }
19
- }(function (jQuery) {
34
+ } (function (jQuery) {
20
35
  // This is needed so we can catch the AMD loader configuration and use it
21
36
  // The inner file should be wrapped (by `banner.start.js`) in a function that
22
37
  // returns the AMD loader references.
23
- var S2 =
24
- (function () {
38
+ var S2 =(function () {
25
39
  // Restore the Select2 AMD loader so it can be used
26
40
  // Needed mostly in the language files, where the loader is not inserted
27
41
  if (jQuery && jQuery.fn && jQuery.fn.select2 && jQuery.fn.select2.amd) {
@@ -30,13 +44,11 @@
30
44
  var S2;(function () { if (!S2 || !S2.requirejs) {
31
45
  if (!S2) { S2 = {}; } else { require = S2; }
32
46
  /**
33
- * @license almond 0.3.1 Copyright (c) 2011-2014, The Dojo Foundation All Rights Reserved.
34
- * Available via the MIT or new BSD license.
35
- * see: http://github.com/jrburke/almond for details
47
+ * @license almond 0.3.3 Copyright jQuery Foundation and other contributors.
48
+ * Released under MIT license, http://github.com/requirejs/almond/LICENSE
36
49
  */
37
50
  //Going sloppy to avoid 'use strict' string cost, but strict practices should
38
51
  //be followed.
39
- /*jslint sloppy: true */
40
52
  /*global setTimeout: false */
41
53
 
42
54
  var requirejs, require, define;
@@ -64,60 +76,58 @@ var requirejs, require, define;
64
76
  */
65
77
  function normalize(name, baseName) {
66
78
  var nameParts, nameSegment, mapValue, foundMap, lastIndex,
67
- foundI, foundStarMap, starI, i, j, part,
79
+ foundI, foundStarMap, starI, i, j, part, normalizedBaseParts,
68
80
  baseParts = baseName && baseName.split("/"),
69
81
  map = config.map,
70
82
  starMap = (map && map['*']) || {};
71
83
 
72
84
  //Adjust any relative paths.
73
- if (name && name.charAt(0) === ".") {
74
- //If have a base name, try to normalize against it,
75
- //otherwise, assume it is a top-level require that will
76
- //be relative to baseUrl in the end.
77
- if (baseName) {
78
- name = name.split('/');
79
- lastIndex = name.length - 1;
80
-
81
- // Node .js allowance:
82
- if (config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) {
83
- name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, '');
84
- }
85
+ if (name) {
86
+ name = name.split('/');
87
+ lastIndex = name.length - 1;
88
+
89
+ // If wanting node ID compatibility, strip .js from end
90
+ // of IDs. Have to do this here, and not in nameToUrl
91
+ // because node allows either .js or non .js to map
92
+ // to same file.
93
+ if (config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) {
94
+ name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, '');
95
+ }
85
96
 
86
- //Lop off the last part of baseParts, so that . matches the
87
- //"directory" and not name of the baseName's module. For instance,
88
- //baseName of "one/two/three", maps to "one/two/three.js", but we
89
- //want the directory, "one/two" for this normalization.
90
- name = baseParts.slice(0, baseParts.length - 1).concat(name);
91
-
92
- //start trimDots
93
- for (i = 0; i < name.length; i += 1) {
94
- part = name[i];
95
- if (part === ".") {
96
- name.splice(i, 1);
97
- i -= 1;
98
- } else if (part === "..") {
99
- if (i === 1 && (name[2] === '..' || name[0] === '..')) {
100
- //End of the line. Keep at least one non-dot
101
- //path segment at the front so it can be mapped
102
- //correctly to disk. Otherwise, there is likely
103
- //no path mapping for a path starting with '..'.
104
- //This can still fail, but catches the most reasonable
105
- //uses of ..
106
- break;
107
- } else if (i > 0) {
108
- name.splice(i - 1, 2);
109
- i -= 2;
110
- }
97
+ // Starts with a '.' so need the baseName
98
+ if (name[0].charAt(0) === '.' && baseParts) {
99
+ //Convert baseName to array, and lop off the last part,
100
+ //so that . matches that 'directory' and not name of the baseName's
101
+ //module. For instance, baseName of 'one/two/three', maps to
102
+ //'one/two/three.js', but we want the directory, 'one/two' for
103
+ //this normalization.
104
+ normalizedBaseParts = baseParts.slice(0, baseParts.length - 1);
105
+ name = normalizedBaseParts.concat(name);
106
+ }
107
+
108
+ //start trimDots
109
+ for (i = 0; i < name.length; i++) {
110
+ part = name[i];
111
+ if (part === '.') {
112
+ name.splice(i, 1);
113
+ i -= 1;
114
+ } else if (part === '..') {
115
+ // If at the start, or previous value is still ..,
116
+ // keep them so that when converted to a path it may
117
+ // still work when converted to a path, even though
118
+ // as an ID it is less than ideal. In larger point
119
+ // releases, may be better to just kick out an error.
120
+ if (i === 0 || (i === 1 && name[2] === '..') || name[i - 1] === '..') {
121
+ continue;
122
+ } else if (i > 0) {
123
+ name.splice(i - 1, 2);
124
+ i -= 2;
111
125
  }
112
126
  }
113
- //end trimDots
114
-
115
- name = name.join("/");
116
- } else if (name.indexOf('./') === 0) {
117
- // No baseName, so this is ID is resolved relative
118
- // to baseUrl, pull off the leading dot.
119
- name = name.substring(2);
120
127
  }
128
+ //end trimDots
129
+
130
+ name = name.join('/');
121
131
  }
122
132
 
123
133
  //Apply map config if available.
@@ -230,32 +240,39 @@ var requirejs, require, define;
230
240
  return [prefix, name];
231
241
  }
232
242
 
243
+ //Creates a parts array for a relName where first part is plugin ID,
244
+ //second part is resource ID. Assumes relName has already been normalized.
245
+ function makeRelParts(relName) {
246
+ return relName ? splitPrefix(relName) : [];
247
+ }
248
+
233
249
  /**
234
250
  * Makes a name map, normalizing the name, and using a plugin
235
251
  * for normalization if necessary. Grabs a ref to plugin
236
252
  * too, as an optimization.
237
253
  */
238
- makeMap = function (name, relName) {
254
+ makeMap = function (name, relParts) {
239
255
  var plugin,
240
256
  parts = splitPrefix(name),
241
- prefix = parts[0];
257
+ prefix = parts[0],
258
+ relResourceName = relParts[1];
242
259
 
243
260
  name = parts[1];
244
261
 
245
262
  if (prefix) {
246
- prefix = normalize(prefix, relName);
263
+ prefix = normalize(prefix, relResourceName);
247
264
  plugin = callDep(prefix);
248
265
  }
249
266
 
250
267
  //Normalize according
251
268
  if (prefix) {
252
269
  if (plugin && plugin.normalize) {
253
- name = plugin.normalize(name, makeNormalize(relName));
270
+ name = plugin.normalize(name, makeNormalize(relResourceName));
254
271
  } else {
255
- name = normalize(name, relName);
272
+ name = normalize(name, relResourceName);
256
273
  }
257
274
  } else {
258
- name = normalize(name, relName);
275
+ name = normalize(name, relResourceName);
259
276
  parts = splitPrefix(name);
260
277
  prefix = parts[0];
261
278
  name = parts[1];
@@ -302,13 +319,14 @@ var requirejs, require, define;
302
319
  };
303
320
 
304
321
  main = function (name, deps, callback, relName) {
305
- var cjsModule, depName, ret, map, i,
322
+ var cjsModule, depName, ret, map, i, relParts,
306
323
  args = [],
307
324
  callbackType = typeof callback,
308
325
  usingExports;
309
326
 
310
327
  //Use name if no relName
311
328
  relName = relName || name;
329
+ relParts = makeRelParts(relName);
312
330
 
313
331
  //Call the callback to define the module, if necessary.
314
332
  if (callbackType === 'undefined' || callbackType === 'function') {
@@ -317,7 +335,7 @@ var requirejs, require, define;
317
335
  //Default to [require, exports, module] if no deps
318
336
  deps = !deps.length && callback.length ? ['require', 'exports', 'module'] : deps;
319
337
  for (i = 0; i < deps.length; i += 1) {
320
- map = makeMap(deps[i], relName);
338
+ map = makeMap(deps[i], relParts);
321
339
  depName = map.f;
322
340
 
323
341
  //Fast path CommonJS standard dependencies.
@@ -373,7 +391,7 @@ var requirejs, require, define;
373
391
  //deps arg is the module name, and second arg (if passed)
374
392
  //is just the relName.
375
393
  //Normalize module name, if it contains . or ..
376
- return callDep(makeMap(deps, callback).f);
394
+ return callDep(makeMap(deps, makeRelParts(callback)).f);
377
395
  } else if (!deps.splice) {
378
396
  //deps is a config object, not an array.
379
397
  config = deps;
@@ -556,10 +574,10 @@ S2.define('select2/utils',[
556
574
  DecoratedClass.prototype = new ctr();
557
575
 
558
576
  for (var m = 0; m < superMethods.length; m++) {
559
- var superMethod = superMethods[m];
577
+ var superMethod = superMethods[m];
560
578
 
561
- DecoratedClass.prototype[superMethod] =
562
- SuperClass.prototype[superMethod];
579
+ DecoratedClass.prototype[superMethod] =
580
+ SuperClass.prototype[superMethod];
563
581
  }
564
582
 
565
583
  var calledMethod = function (methodName) {
@@ -754,6 +772,70 @@ S2.define('select2/utils',[
754
772
  $element.append($nodes);
755
773
  };
756
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
+ element.removeAttribute('data-select2-id');
837
+ };
838
+
757
839
  return Utils;
758
840
  });
759
841
 
@@ -773,7 +855,7 @@ S2.define('select2/results',[
773
855
 
774
856
  Results.prototype.render = function () {
775
857
  var $results = $(
776
- '<ul class="select2-results__options" role="tree"></ul>'
858
+ '<ul class="select2-results__options" role="listbox"></ul>'
777
859
  );
778
860
 
779
861
  if (this.options.get('multiple')) {
@@ -796,7 +878,7 @@ S2.define('select2/results',[
796
878
  this.hideLoading();
797
879
 
798
880
  var $message = $(
799
- '<li role="treeitem" aria-live="assertive"' +
881
+ '<li role="alert" aria-live="assertive"' +
800
882
  ' class="select2-results__option"></li>'
801
883
  );
802
884
 
@@ -889,7 +971,7 @@ S2.define('select2/results',[
889
971
  $options.each(function () {
890
972
  var $option = $(this);
891
973
 
892
- var item = $.data(this, 'data');
974
+ var item = Utils.GetData(this, 'data');
893
975
 
894
976
  // id needs to be converted to a string when comparing
895
977
  var id = '' + item.id;
@@ -930,11 +1012,16 @@ S2.define('select2/results',[
930
1012
  option.className = 'select2-results__option';
931
1013
 
932
1014
  var attrs = {
933
- 'role': 'treeitem',
1015
+ 'role': 'option',
934
1016
  'aria-selected': 'false'
935
1017
  };
936
1018
 
937
- if (data.disabled) {
1019
+ var matches = window.Element.prototype.matches ||
1020
+ window.Element.prototype.msMatchesSelector ||
1021
+ window.Element.prototype.webkitMatchesSelector;
1022
+
1023
+ if ((data.element != null && matches.call(data.element, ':disabled')) ||
1024
+ (data.element == null && data.disabled)) {
938
1025
  delete attrs['aria-selected'];
939
1026
  attrs['aria-disabled'] = 'true';
940
1027
  }
@@ -994,7 +1081,7 @@ S2.define('select2/results',[
994
1081
  this.template(data, option);
995
1082
  }
996
1083
 
997
- $.data(option, 'data', data);
1084
+ Utils.StoreData(option, 'data', data);
998
1085
 
999
1086
  return option;
1000
1087
  };
@@ -1035,7 +1122,10 @@ S2.define('select2/results',[
1035
1122
  }
1036
1123
 
1037
1124
  self.setClasses();
1038
- self.highlightFirstItem();
1125
+
1126
+ if (self.options.get('scrollAfterSelect')) {
1127
+ self.highlightFirstItem();
1128
+ }
1039
1129
  });
1040
1130
 
1041
1131
  container.on('unselect', function () {
@@ -1044,7 +1134,10 @@ S2.define('select2/results',[
1044
1134
  }
1045
1135
 
1046
1136
  self.setClasses();
1047
- self.highlightFirstItem();
1137
+
1138
+ if (self.options.get('scrollAfterSelect')) {
1139
+ self.highlightFirstItem();
1140
+ }
1048
1141
  });
1049
1142
 
1050
1143
  container.on('open', function () {
@@ -1080,7 +1173,7 @@ S2.define('select2/results',[
1080
1173
  return;
1081
1174
  }
1082
1175
 
1083
- var data = $highlighted.data('data');
1176
+ var data = Utils.GetData($highlighted[0], 'data');
1084
1177
 
1085
1178
  if ($highlighted.attr('aria-selected') == 'true') {
1086
1179
  self.trigger('close', {});
@@ -1098,8 +1191,9 @@ S2.define('select2/results',[
1098
1191
 
1099
1192
  var currentIndex = $options.index($highlighted);
1100
1193
 
1101
- // If we are already at te top, don't move further
1102
- if (currentIndex === 0) {
1194
+ // If we are already at the top, don't move further
1195
+ // If no options, currentIndex will be -1
1196
+ if (currentIndex <= 0) {
1103
1197
  return;
1104
1198
  }
1105
1199
 
@@ -1192,7 +1286,7 @@ S2.define('select2/results',[
1192
1286
  function (evt) {
1193
1287
  var $this = $(this);
1194
1288
 
1195
- var data = $this.data('data');
1289
+ var data = Utils.GetData(this, 'data');
1196
1290
 
1197
1291
  if ($this.attr('aria-selected') === 'true') {
1198
1292
  if (self.options.get('multiple')) {
@@ -1215,7 +1309,7 @@ S2.define('select2/results',[
1215
1309
 
1216
1310
  this.$results.on('mouseenter', '.select2-results__option[aria-selected]',
1217
1311
  function (evt) {
1218
- var data = $(this).data('data');
1312
+ var data = Utils.GetData(this, 'data');
1219
1313
 
1220
1314
  self.getHighlightedResults()
1221
1315
  .removeClass('select2-results__option--highlighted');
@@ -1330,14 +1424,15 @@ S2.define('select2/selection/base',[
1330
1424
 
1331
1425
  this._tabindex = 0;
1332
1426
 
1333
- if (this.$element.data('old-tabindex') != null) {
1334
- this._tabindex = this.$element.data('old-tabindex');
1427
+ if (Utils.GetData(this.$element[0], 'old-tabindex') != null) {
1428
+ this._tabindex = Utils.GetData(this.$element[0], 'old-tabindex');
1335
1429
  } else if (this.$element.attr('tabindex') != null) {
1336
1430
  this._tabindex = this.$element.attr('tabindex');
1337
1431
  }
1338
1432
 
1339
1433
  $selection.attr('title', this.$element.attr('title'));
1340
1434
  $selection.attr('tabindex', this._tabindex);
1435
+ $selection.attr('aria-disabled', 'false');
1341
1436
 
1342
1437
  this.$selection = $selection;
1343
1438
 
@@ -1347,7 +1442,6 @@ S2.define('select2/selection/base',[
1347
1442
  BaseSelection.prototype.bind = function (container, $container) {
1348
1443
  var self = this;
1349
1444
 
1350
- var id = container.id + '-container';
1351
1445
  var resultsId = container.id + '-results';
1352
1446
 
1353
1447
  this.container = container;
@@ -1390,17 +1484,19 @@ S2.define('select2/selection/base',[
1390
1484
  self.$selection.removeAttr('aria-activedescendant');
1391
1485
  self.$selection.removeAttr('aria-owns');
1392
1486
 
1393
- self.$selection.focus();
1487
+ self.$selection.trigger('focus');
1394
1488
 
1395
1489
  self._detachCloseHandler(container);
1396
1490
  });
1397
1491
 
1398
1492
  container.on('enable', function () {
1399
1493
  self.$selection.attr('tabindex', self._tabindex);
1494
+ self.$selection.attr('aria-disabled', 'false');
1400
1495
  });
1401
1496
 
1402
1497
  container.on('disable', function () {
1403
1498
  self.$selection.attr('tabindex', '-1');
1499
+ self.$selection.attr('aria-disabled', 'true');
1404
1500
  });
1405
1501
  };
1406
1502
 
@@ -1423,7 +1519,6 @@ S2.define('select2/selection/base',[
1423
1519
  };
1424
1520
 
1425
1521
  BaseSelection.prototype._attachCloseHandler = function (container) {
1426
- var self = this;
1427
1522
 
1428
1523
  $(document.body).on('mousedown.select2.' + container.id, function (e) {
1429
1524
  var $target = $(e.target);
@@ -1433,13 +1528,11 @@ S2.define('select2/selection/base',[
1433
1528
  var $all = $('.select2.select2-container--open');
1434
1529
 
1435
1530
  $all.each(function () {
1436
- var $this = $(this);
1437
-
1438
1531
  if (this == $select[0]) {
1439
1532
  return;
1440
1533
  }
1441
1534
 
1442
- var $element = $this.data('element');
1535
+ var $element = Utils.GetData(this, 'element');
1443
1536
 
1444
1537
  $element.select2('close');
1445
1538
  });
@@ -1500,7 +1593,10 @@ S2.define('select2/selection/single',[
1500
1593
 
1501
1594
  var id = container.id + '-container';
1502
1595
 
1503
- this.$selection.find('.select2-selection__rendered').attr('id', id);
1596
+ this.$selection.find('.select2-selection__rendered')
1597
+ .attr('id', id)
1598
+ .attr('role', 'textbox')
1599
+ .attr('aria-readonly', 'true');
1504
1600
  this.$selection.attr('aria-labelledby', id);
1505
1601
 
1506
1602
  this.$selection.on('mousedown', function (evt) {
@@ -1524,17 +1620,15 @@ S2.define('select2/selection/single',[
1524
1620
 
1525
1621
  container.on('focus', function (evt) {
1526
1622
  if (!container.isOpen()) {
1527
- self.$selection.focus();
1623
+ self.$selection.trigger('focus');
1528
1624
  }
1529
1625
  });
1530
-
1531
- container.on('selection:update', function (params) {
1532
- self.update(params.data);
1533
- });
1534
1626
  };
1535
1627
 
1536
1628
  SingleSelection.prototype.clear = function () {
1537
- this.$selection.find('.select2-selection__rendered').empty();
1629
+ var $rendered = this.$selection.find('.select2-selection__rendered');
1630
+ $rendered.empty();
1631
+ $rendered.removeAttr('title'); // clear tooltip on empty
1538
1632
  };
1539
1633
 
1540
1634
  SingleSelection.prototype.display = function (data, container) {
@@ -1560,7 +1654,14 @@ S2.define('select2/selection/single',[
1560
1654
  var formatted = this.display(selection, $rendered);
1561
1655
 
1562
1656
  $rendered.empty().append(formatted);
1563
- $rendered.prop('title', selection.title || selection.text);
1657
+
1658
+ var title = selection.title || selection.text;
1659
+
1660
+ if (title) {
1661
+ $rendered.attr('title', title);
1662
+ } else {
1663
+ $rendered.removeAttr('title');
1664
+ }
1564
1665
  };
1565
1666
 
1566
1667
  return SingleSelection;
@@ -1612,7 +1713,7 @@ S2.define('select2/selection/multiple',[
1612
1713
  var $remove = $(this);
1613
1714
  var $selection = $remove.parent();
1614
1715
 
1615
- var data = $selection.data('data');
1716
+ var data = Utils.GetData($selection[0], 'data');
1616
1717
 
1617
1718
  self.trigger('unselect', {
1618
1719
  originalEvent: evt,
@@ -1623,7 +1724,9 @@ S2.define('select2/selection/multiple',[
1623
1724
  };
1624
1725
 
1625
1726
  MultipleSelection.prototype.clear = function () {
1626
- this.$selection.find('.select2-selection__rendered').empty();
1727
+ var $rendered = this.$selection.find('.select2-selection__rendered');
1728
+ $rendered.empty();
1729
+ $rendered.removeAttr('title');
1627
1730
  };
1628
1731
 
1629
1732
  MultipleSelection.prototype.display = function (data, container) {
@@ -1661,9 +1764,14 @@ S2.define('select2/selection/multiple',[
1661
1764
  var formatted = this.display(selection, $selection);
1662
1765
 
1663
1766
  $selection.append(formatted);
1664
- $selection.prop('title', selection.title || selection.text);
1665
1767
 
1666
- $selection.data('data', selection);
1768
+ var title = selection.title || selection.text;
1769
+
1770
+ if (title) {
1771
+ $selection.attr('title', title);
1772
+ }
1773
+
1774
+ Utils.StoreData($selection[0], 'data', selection);
1667
1775
 
1668
1776
  $selections.push($selection);
1669
1777
  }
@@ -1728,8 +1836,9 @@ S2.define('select2/selection/placeholder',[
1728
1836
 
1729
1837
  S2.define('select2/selection/allowClear',[
1730
1838
  'jquery',
1731
- '../keys'
1732
- ], function ($, KEYS) {
1839
+ '../keys',
1840
+ '../utils'
1841
+ ], function ($, KEYS, Utils) {
1733
1842
  function AllowClear () { }
1734
1843
 
1735
1844
  AllowClear.prototype.bind = function (decorated, container, $container) {
@@ -1771,10 +1880,22 @@ S2.define('select2/selection/allowClear',[
1771
1880
 
1772
1881
  evt.stopPropagation();
1773
1882
 
1774
- var data = $clear.data('data');
1883
+ var data = Utils.GetData($clear[0], 'data');
1884
+
1885
+ var previousVal = this.$element.val();
1886
+ this.$element.val(this.placeholder.id);
1887
+
1888
+ var unselectData = {
1889
+ data: data
1890
+ };
1891
+ this.trigger('clear', unselectData);
1892
+ if (unselectData.prevented) {
1893
+ this.$element.val(previousVal);
1894
+ return;
1895
+ }
1775
1896
 
1776
1897
  for (var d = 0; d < data.length; d++) {
1777
- var unselectData = {
1898
+ unselectData = {
1778
1899
  data: data[d]
1779
1900
  };
1780
1901
 
@@ -1784,11 +1905,12 @@ S2.define('select2/selection/allowClear',[
1784
1905
 
1785
1906
  // If the event was prevented, don't clear it out.
1786
1907
  if (unselectData.prevented) {
1908
+ this.$element.val(previousVal);
1787
1909
  return;
1788
1910
  }
1789
1911
  }
1790
1912
 
1791
- this.$element.val(this.placeholder.id).trigger('change');
1913
+ this.$element.trigger('change');
1792
1914
 
1793
1915
  this.trigger('toggle', {});
1794
1916
  };
@@ -1811,12 +1933,14 @@ S2.define('select2/selection/allowClear',[
1811
1933
  return;
1812
1934
  }
1813
1935
 
1936
+ var removeAll = this.options.get('translations').get('removeAllItems');
1937
+
1814
1938
  var $remove = $(
1815
- '<span class="select2-selection__clear">' +
1939
+ '<span class="select2-selection__clear" title="' + removeAll() +'">' +
1816
1940
  '&times;' +
1817
1941
  '</span>'
1818
1942
  );
1819
- $remove.data('data', data);
1943
+ Utils.StoreData($remove[0], 'data', data);
1820
1944
 
1821
1945
  this.$selection.find('.select2-selection__rendered').prepend($remove);
1822
1946
  };
@@ -1837,8 +1961,8 @@ S2.define('select2/selection/search',[
1837
1961
  var $search = $(
1838
1962
  '<li class="select2-search select2-search--inline">' +
1839
1963
  '<input class="select2-search__field" type="search" tabindex="-1"' +
1840
- ' autocomplete="off" autocorrect="off" autocapitalize="off"' +
1841
- ' spellcheck="false" role="textbox" aria-autocomplete="list" />' +
1964
+ ' autocomplete="off" autocorrect="off" autocapitalize="none"' +
1965
+ ' spellcheck="false" role="searchbox" aria-autocomplete="list" />' +
1842
1966
  '</li>'
1843
1967
  );
1844
1968
 
@@ -1855,14 +1979,18 @@ S2.define('select2/selection/search',[
1855
1979
  Search.prototype.bind = function (decorated, container, $container) {
1856
1980
  var self = this;
1857
1981
 
1982
+ var resultsId = container.id + '-results';
1983
+
1858
1984
  decorated.call(this, container, $container);
1859
1985
 
1860
1986
  container.on('open', function () {
1987
+ self.$search.attr('aria-controls', resultsId);
1861
1988
  self.$search.trigger('focus');
1862
1989
  });
1863
1990
 
1864
1991
  container.on('close', function () {
1865
1992
  self.$search.val('');
1993
+ self.$search.removeAttr('aria-controls');
1866
1994
  self.$search.removeAttr('aria-activedescendant');
1867
1995
  self.$search.trigger('focus');
1868
1996
  });
@@ -1882,7 +2010,11 @@ S2.define('select2/selection/search',[
1882
2010
  });
1883
2011
 
1884
2012
  container.on('results:focus', function (params) {
1885
- self.$search.attr('aria-activedescendant', params.id);
2013
+ if (params.data._resultId) {
2014
+ self.$search.attr('aria-activedescendant', params.data._resultId);
2015
+ } else {
2016
+ self.$search.removeAttr('aria-activedescendant');
2017
+ }
1886
2018
  });
1887
2019
 
1888
2020
  this.$selection.on('focusin', '.select2-search--inline', function (evt) {
@@ -1907,7 +2039,7 @@ S2.define('select2/selection/search',[
1907
2039
  .prev('.select2-selection__choice');
1908
2040
 
1909
2041
  if ($previousChoice.length > 0) {
1910
- var item = $previousChoice.data('data');
2042
+ var item = Utils.GetData($previousChoice[0], 'data');
1911
2043
 
1912
2044
  self.searchRemoveChoice(item);
1913
2045
 
@@ -1916,6 +2048,12 @@ S2.define('select2/selection/search',[
1916
2048
  }
1917
2049
  });
1918
2050
 
2051
+ this.$selection.on('click', '.select2-search--inline', function (evt) {
2052
+ if (self.$search.val()) {
2053
+ evt.stopPropagation();
2054
+ }
2055
+ });
2056
+
1919
2057
  // Try to detect the IE version should the `documentMode` property that
1920
2058
  // is stored on the document. This is only implemented in IE and is
1921
2059
  // slightly cleaner than doing a user agent check.
@@ -2001,7 +2139,7 @@ S2.define('select2/selection/search',[
2001
2139
 
2002
2140
  this.resizeSearch();
2003
2141
  if (searchHadFocus) {
2004
- this.$search.focus();
2142
+ this.$search.trigger('focus');
2005
2143
  }
2006
2144
  };
2007
2145
 
@@ -2034,7 +2172,7 @@ S2.define('select2/selection/search',[
2034
2172
  var width = '';
2035
2173
 
2036
2174
  if (this.$search.attr('placeholder') !== '') {
2037
- width = this.$selection.find('.select2-selection__rendered').innerWidth();
2175
+ width = this.$selection.find('.select2-selection__rendered').width();
2038
2176
  } else {
2039
2177
  var minimumWidth = this.$search.val().length + 1;
2040
2178
 
@@ -2058,10 +2196,13 @@ S2.define('select2/selection/eventRelay',[
2058
2196
  'open', 'opening',
2059
2197
  'close', 'closing',
2060
2198
  'select', 'selecting',
2061
- 'unselect', 'unselecting'
2199
+ 'unselect', 'unselecting',
2200
+ 'clear', 'clearing'
2062
2201
  ];
2063
2202
 
2064
- var preventableEvents = ['opening', 'closing', 'selecting', 'unselecting'];
2203
+ var preventableEvents = [
2204
+ 'opening', 'closing', 'selecting', 'unselecting', 'clearing'
2205
+ ];
2065
2206
 
2066
2207
  decorated.call(this, container, $container);
2067
2208
 
@@ -2394,6 +2535,7 @@ S2.define('select2/diacritics',[
2394
2535
  '\u019F': 'O',
2395
2536
  '\uA74A': 'O',
2396
2537
  '\uA74C': 'O',
2538
+ '\u0152': 'OE',
2397
2539
  '\u01A2': 'OI',
2398
2540
  '\uA74E': 'OO',
2399
2541
  '\u0222': 'OU',
@@ -2803,6 +2945,7 @@ S2.define('select2/diacritics',[
2803
2945
  '\uA74B': 'o',
2804
2946
  '\uA74D': 'o',
2805
2947
  '\u0275': 'o',
2948
+ '\u0153': 'oe',
2806
2949
  '\u01A3': 'oi',
2807
2950
  '\u0223': 'ou',
2808
2951
  '\uA74F': 'oo',
@@ -2971,8 +3114,9 @@ S2.define('select2/diacritics',[
2971
3114
  '\u03CD': '\u03C5',
2972
3115
  '\u03CB': '\u03C5',
2973
3116
  '\u03B0': '\u03C5',
2974
- '\u03C9': '\u03C9',
2975
- '\u03C2': '\u03C3'
3117
+ '\u03CE': '\u03C9',
3118
+ '\u03C2': '\u03C3',
3119
+ '\u2019': '\''
2976
3120
  };
2977
3121
 
2978
3122
  return diacritics;
@@ -3140,7 +3284,7 @@ S2.define('select2/data/select',[
3140
3284
  // Remove anything added to child elements
3141
3285
  this.$element.find('*').each(function () {
3142
3286
  // Remove any custom data set by Select2
3143
- $.removeData(this, 'data');
3287
+ Utils.RemoveData(this);
3144
3288
  });
3145
3289
  };
3146
3290
 
@@ -3191,7 +3335,7 @@ S2.define('select2/data/select',[
3191
3335
  }
3192
3336
  }
3193
3337
 
3194
- if (data.id) {
3338
+ if (data.id !== undefined) {
3195
3339
  option.value = data.id;
3196
3340
  }
3197
3341
 
@@ -3213,7 +3357,7 @@ S2.define('select2/data/select',[
3213
3357
  normalizedData.element = option;
3214
3358
 
3215
3359
  // Override the option's data with the combined data
3216
- $.data(option, 'data', normalizedData);
3360
+ Utils.StoreData(option, 'data', normalizedData);
3217
3361
 
3218
3362
  return $option;
3219
3363
  };
@@ -3221,7 +3365,7 @@ S2.define('select2/data/select',[
3221
3365
  SelectAdapter.prototype.item = function ($option) {
3222
3366
  var data = {};
3223
3367
 
3224
- data = $.data($option[0], 'data');
3368
+ data = Utils.GetData($option[0], 'data');
3225
3369
 
3226
3370
  if (data != null) {
3227
3371
  return data;
@@ -3259,13 +3403,13 @@ S2.define('select2/data/select',[
3259
3403
  data = this._normalizeItem(data);
3260
3404
  data.element = $option[0];
3261
3405
 
3262
- $.data($option[0], 'data', data);
3406
+ Utils.StoreData($option[0], 'data', data);
3263
3407
 
3264
3408
  return data;
3265
3409
  };
3266
3410
 
3267
3411
  SelectAdapter.prototype._normalizeItem = function (item) {
3268
- if (!$.isPlainObject(item)) {
3412
+ if (item !== Object(item)) {
3269
3413
  item = {
3270
3414
  id: item,
3271
3415
  text: item
@@ -3311,15 +3455,19 @@ S2.define('select2/data/array',[
3311
3455
  'jquery'
3312
3456
  ], function (SelectAdapter, Utils, $) {
3313
3457
  function ArrayAdapter ($element, options) {
3314
- var data = options.get('data') || [];
3458
+ this._dataToConvert = options.get('data') || [];
3315
3459
 
3316
3460
  ArrayAdapter.__super__.constructor.call(this, $element, options);
3317
-
3318
- this.addOptions(this.convertToOptions(data));
3319
3461
  }
3320
3462
 
3321
3463
  Utils.Extend(ArrayAdapter, SelectAdapter);
3322
3464
 
3465
+ ArrayAdapter.prototype.bind = function (container, $container) {
3466
+ ArrayAdapter.__super__.bind.call(this, container, $container);
3467
+
3468
+ this.addOptions(this.convertToOptions(this._dataToConvert));
3469
+ };
3470
+
3323
3471
  ArrayAdapter.prototype.select = function (data) {
3324
3472
  var $option = this.$element.find('option').filter(function (i, elm) {
3325
3473
  return elm.value == data.id.toString();
@@ -3469,7 +3617,8 @@ S2.define('select2/data/ajax',[
3469
3617
  }, function () {
3470
3618
  // Attempt to detect if a request was aborted
3471
3619
  // Only works if the transport exposes a status property
3472
- if ($request.status && $request.status === '0') {
3620
+ if ('status' in $request &&
3621
+ ($request.status === 0 || $request.status === '0')) {
3473
3622
  return;
3474
3623
  }
3475
3624
 
@@ -3550,7 +3699,10 @@ S2.define('select2/data/tags',[
3550
3699
  }, true)
3551
3700
  );
3552
3701
 
3553
- var checkText = option.text === params.term;
3702
+ var optionText = (option.text || '').toUpperCase();
3703
+ var paramsTerm = (params.term || '').toUpperCase();
3704
+
3705
+ var checkText = optionText === paramsTerm;
3554
3706
 
3555
3707
  if (checkText || checkChildren) {
3556
3708
  if (child) {
@@ -3605,8 +3757,6 @@ S2.define('select2/data/tags',[
3605
3757
  };
3606
3758
 
3607
3759
  Tags.prototype._removeOldTags = function (_) {
3608
- var tag = this._lastTag;
3609
-
3610
3760
  var $options = this.$element.find('option[data-select2-tag]');
3611
3761
 
3612
3762
  $options.each(function () {
@@ -3681,7 +3831,7 @@ S2.define('select2/data/tokenizer',[
3681
3831
  // Replace the search term if we have the search box
3682
3832
  if (this.$search.length) {
3683
3833
  this.$search.val(tokenData.term);
3684
- this.$search.focus();
3834
+ this.$search.trigger('focus');
3685
3835
  }
3686
3836
 
3687
3837
  params.term = tokenData.term;
@@ -3810,10 +3960,30 @@ S2.define('select2/data/maximumSelectionLength',[
3810
3960
  decorated.call(this, $e, options);
3811
3961
  }
3812
3962
 
3963
+ MaximumSelectionLength.prototype.bind =
3964
+ function (decorated, container, $container) {
3965
+ var self = this;
3966
+
3967
+ decorated.call(this, container, $container);
3968
+
3969
+ container.on('select', function () {
3970
+ self._checkIfMaximumSelected();
3971
+ });
3972
+ };
3973
+
3813
3974
  MaximumSelectionLength.prototype.query =
3814
3975
  function (decorated, params, callback) {
3815
3976
  var self = this;
3816
3977
 
3978
+ this._checkIfMaximumSelected(function () {
3979
+ decorated.call(self, params, callback);
3980
+ });
3981
+ };
3982
+
3983
+ MaximumSelectionLength.prototype._checkIfMaximumSelected =
3984
+ function (_, successCallback) {
3985
+ var self = this;
3986
+
3817
3987
  this.current(function (currentData) {
3818
3988
  var count = currentData != null ? currentData.length : 0;
3819
3989
  if (self.maximumSelectionLength > 0 &&
@@ -3826,7 +3996,10 @@ S2.define('select2/data/maximumSelectionLength',[
3826
3996
  });
3827
3997
  return;
3828
3998
  }
3829
- decorated.call(self, params, callback);
3999
+
4000
+ if (successCallback) {
4001
+ successCallback();
4002
+ }
3830
4003
  });
3831
4004
  };
3832
4005
 
@@ -3865,7 +4038,7 @@ S2.define('select2/dropdown',[
3865
4038
  };
3866
4039
 
3867
4040
  Dropdown.prototype.position = function ($dropdown, $container) {
3868
- // Should be implmented in subclasses
4041
+ // Should be implemented in subclasses
3869
4042
  };
3870
4043
 
3871
4044
  Dropdown.prototype.destroy = function () {
@@ -3888,8 +4061,8 @@ S2.define('select2/dropdown/search',[
3888
4061
  var $search = $(
3889
4062
  '<span class="select2-search select2-search--dropdown">' +
3890
4063
  '<input class="select2-search__field" type="search" tabindex="-1"' +
3891
- ' autocomplete="off" autocorrect="off" autocapitalize="off"' +
3892
- ' spellcheck="false" role="textbox" />' +
4064
+ ' autocomplete="off" autocorrect="off" autocapitalize="none"' +
4065
+ ' spellcheck="false" role="searchbox" aria-autocomplete="list" />' +
3893
4066
  '</span>'
3894
4067
  );
3895
4068
 
@@ -3904,6 +4077,8 @@ S2.define('select2/dropdown/search',[
3904
4077
  Search.prototype.bind = function (decorated, container, $container) {
3905
4078
  var self = this;
3906
4079
 
4080
+ var resultsId = container.id + '-results';
4081
+
3907
4082
  decorated.call(this, container, $container);
3908
4083
 
3909
4084
  this.$search.on('keydown', function (evt) {
@@ -3926,23 +4101,27 @@ S2.define('select2/dropdown/search',[
3926
4101
 
3927
4102
  container.on('open', function () {
3928
4103
  self.$search.attr('tabindex', 0);
4104
+ self.$search.attr('aria-controls', resultsId);
3929
4105
 
3930
- self.$search.focus();
4106
+ self.$search.trigger('focus');
3931
4107
 
3932
4108
  window.setTimeout(function () {
3933
- self.$search.focus();
4109
+ self.$search.trigger('focus');
3934
4110
  }, 0);
3935
4111
  });
3936
4112
 
3937
4113
  container.on('close', function () {
3938
4114
  self.$search.attr('tabindex', -1);
4115
+ self.$search.removeAttr('aria-controls');
4116
+ self.$search.removeAttr('aria-activedescendant');
3939
4117
 
3940
4118
  self.$search.val('');
4119
+ self.$search.trigger('blur');
3941
4120
  });
3942
4121
 
3943
4122
  container.on('focus', function () {
3944
- if (container.isOpen()) {
3945
- self.$search.focus();
4123
+ if (!container.isOpen()) {
4124
+ self.$search.trigger('focus');
3946
4125
  }
3947
4126
  });
3948
4127
 
@@ -3957,6 +4136,14 @@ S2.define('select2/dropdown/search',[
3957
4136
  }
3958
4137
  }
3959
4138
  });
4139
+
4140
+ container.on('results:focus', function (params) {
4141
+ if (params.data._resultId) {
4142
+ self.$search.attr('aria-activedescendant', params.data._resultId);
4143
+ } else {
4144
+ self.$search.removeAttr('aria-activedescendant');
4145
+ }
4146
+ });
3960
4147
  };
3961
4148
 
3962
4149
  Search.prototype.handleSearch = function (evt) {
@@ -4041,6 +4228,7 @@ S2.define('select2/dropdown/infiniteScroll',[
4041
4228
 
4042
4229
  if (this.showLoadingMore(data)) {
4043
4230
  this.$results.append(this.$loadingMore);
4231
+ this.loadMoreIfNeeded();
4044
4232
  }
4045
4233
  };
4046
4234
 
@@ -4059,25 +4247,27 @@ S2.define('select2/dropdown/infiniteScroll',[
4059
4247
  self.loading = true;
4060
4248
  });
4061
4249
 
4062
- this.$results.on('scroll', function () {
4063
- var isLoadMoreVisible = $.contains(
4064
- document.documentElement,
4065
- self.$loadingMore[0]
4066
- );
4250
+ this.$results.on('scroll', this.loadMoreIfNeeded.bind(this));
4251
+ };
4067
4252
 
4068
- if (self.loading || !isLoadMoreVisible) {
4069
- return;
4070
- }
4253
+ InfiniteScroll.prototype.loadMoreIfNeeded = function () {
4254
+ var isLoadMoreVisible = $.contains(
4255
+ document.documentElement,
4256
+ this.$loadingMore[0]
4257
+ );
4071
4258
 
4072
- var currentOffset = self.$results.offset().top +
4073
- self.$results.outerHeight(false);
4074
- var loadingMoreOffset = self.$loadingMore.offset().top +
4075
- self.$loadingMore.outerHeight(false);
4259
+ if (this.loading || !isLoadMoreVisible) {
4260
+ return;
4261
+ }
4076
4262
 
4077
- if (currentOffset + 50 >= loadingMoreOffset) {
4078
- self.loadMore();
4079
- }
4080
- });
4263
+ var currentOffset = this.$results.offset().top +
4264
+ this.$results.outerHeight(false);
4265
+ var loadingMoreOffset = this.$loadingMore.offset().top +
4266
+ this.$loadingMore.outerHeight(false);
4267
+
4268
+ if (currentOffset + 50 >= loadingMoreOffset) {
4269
+ this.loadMore();
4270
+ }
4081
4271
  };
4082
4272
 
4083
4273
  InfiniteScroll.prototype.loadMore = function () {
@@ -4098,7 +4288,7 @@ S2.define('select2/dropdown/infiniteScroll',[
4098
4288
  var $option = $(
4099
4289
  '<li ' +
4100
4290
  'class="select2-results__option select2-results__option--load-more"' +
4101
- 'role="treeitem" aria-disabled="true"></li>'
4291
+ 'role="option" aria-disabled="true"></li>'
4102
4292
  );
4103
4293
 
4104
4294
  var message = this.options.get('translations').get('loadingMore');
@@ -4116,7 +4306,7 @@ S2.define('select2/dropdown/attachBody',[
4116
4306
  '../utils'
4117
4307
  ], function ($, Utils) {
4118
4308
  function AttachBody (decorated, $element, options) {
4119
- this.$dropdownParent = options.get('dropdownParent') || $(document.body);
4309
+ this.$dropdownParent = $(options.get('dropdownParent') || document.body);
4120
4310
 
4121
4311
  decorated.call(this, $element, options);
4122
4312
  }
@@ -4124,27 +4314,14 @@ S2.define('select2/dropdown/attachBody',[
4124
4314
  AttachBody.prototype.bind = function (decorated, container, $container) {
4125
4315
  var self = this;
4126
4316
 
4127
- var setupResultsEvents = false;
4128
-
4129
4317
  decorated.call(this, container, $container);
4130
4318
 
4131
4319
  container.on('open', function () {
4132
4320
  self._showDropdown();
4133
4321
  self._attachPositioningHandler(container);
4134
4322
 
4135
- if (!setupResultsEvents) {
4136
- setupResultsEvents = true;
4137
-
4138
- container.on('results:all', function () {
4139
- self._positionDropdown();
4140
- self._resizeDropdown();
4141
- });
4142
-
4143
- container.on('results:append', function () {
4144
- self._positionDropdown();
4145
- self._resizeDropdown();
4146
- });
4147
- }
4323
+ // Must bind after the results handlers to ensure correct sizing
4324
+ self._bindContainerResultHandlers(container);
4148
4325
  });
4149
4326
 
4150
4327
  container.on('close', function () {
@@ -4193,6 +4370,44 @@ S2.define('select2/dropdown/attachBody',[
4193
4370
  this.$dropdownContainer.detach();
4194
4371
  };
4195
4372
 
4373
+ AttachBody.prototype._bindContainerResultHandlers =
4374
+ function (decorated, container) {
4375
+
4376
+ // These should only be bound once
4377
+ if (this._containerResultsHandlersBound) {
4378
+ return;
4379
+ }
4380
+
4381
+ var self = this;
4382
+
4383
+ container.on('results:all', function () {
4384
+ self._positionDropdown();
4385
+ self._resizeDropdown();
4386
+ });
4387
+
4388
+ container.on('results:append', function () {
4389
+ self._positionDropdown();
4390
+ self._resizeDropdown();
4391
+ });
4392
+
4393
+ container.on('results:message', function () {
4394
+ self._positionDropdown();
4395
+ self._resizeDropdown();
4396
+ });
4397
+
4398
+ container.on('select', function () {
4399
+ self._positionDropdown();
4400
+ self._resizeDropdown();
4401
+ });
4402
+
4403
+ container.on('unselect', function () {
4404
+ self._positionDropdown();
4405
+ self._resizeDropdown();
4406
+ });
4407
+
4408
+ this._containerResultsHandlersBound = true;
4409
+ };
4410
+
4196
4411
  AttachBody.prototype._attachPositioningHandler =
4197
4412
  function (decorated, container) {
4198
4413
  var self = this;
@@ -4203,14 +4418,14 @@ S2.define('select2/dropdown/attachBody',[
4203
4418
 
4204
4419
  var $watchers = this.$container.parents().filter(Utils.hasScroll);
4205
4420
  $watchers.each(function () {
4206
- $(this).data('select2-scroll-position', {
4421
+ Utils.StoreData(this, 'select2-scroll-position', {
4207
4422
  x: $(this).scrollLeft(),
4208
4423
  y: $(this).scrollTop()
4209
4424
  });
4210
4425
  });
4211
4426
 
4212
4427
  $watchers.on(scrollEvent, function (ev) {
4213
- var position = $(this).data('select2-scroll-position');
4428
+ var position = Utils.GetData(this, 'select2-scroll-position');
4214
4429
  $(this).scrollTop(position.y);
4215
4430
  });
4216
4431
 
@@ -4269,10 +4484,10 @@ S2.define('select2/dropdown/attachBody',[
4269
4484
  top: container.bottom
4270
4485
  };
4271
4486
 
4272
- // Determine what the parent element is to use for calciulating the offset
4487
+ // Determine what the parent element is to use for calculating the offset
4273
4488
  var $offsetParent = this.$dropdownParent;
4274
4489
 
4275
- // For statically positoned elements, we need to get the element
4490
+ // For statically positioned elements, we need to get the element
4276
4491
  // that is determining the offset
4277
4492
  if ($offsetParent.css('position') === 'static') {
4278
4493
  $offsetParent = $offsetParent.offsetParent();
@@ -4375,8 +4590,8 @@ S2.define('select2/dropdown/minimumResultsForSearch',[
4375
4590
  });
4376
4591
 
4377
4592
  S2.define('select2/dropdown/selectOnClose',[
4378
-
4379
- ], function () {
4593
+ '../utils'
4594
+ ], function (Utils) {
4380
4595
  function SelectOnClose () { }
4381
4596
 
4382
4597
  SelectOnClose.prototype.bind = function (decorated, container, $container) {
@@ -4407,7 +4622,7 @@ S2.define('select2/dropdown/selectOnClose',[
4407
4622
  return;
4408
4623
  }
4409
4624
 
4410
- var data = $highlightedResults.data('data');
4625
+ var data = Utils.GetData($highlightedResults[0], 'data');
4411
4626
 
4412
4627
  // Don't re-select already selected resulte
4413
4628
  if (
@@ -4448,7 +4663,7 @@ S2.define('select2/dropdown/closeOnSelect',[
4448
4663
  var originalEvent = evt.originalEvent;
4449
4664
 
4450
4665
  // Don't close if the control key is being held
4451
- if (originalEvent && originalEvent.ctrlKey) {
4666
+ if (originalEvent && (originalEvent.ctrlKey || originalEvent.metaKey)) {
4452
4667
  return;
4453
4668
  }
4454
4669
 
@@ -4502,6 +4717,9 @@ S2.define('select2/i18n/en',[],function () {
4502
4717
  },
4503
4718
  searching: function () {
4504
4719
  return 'Searching…';
4720
+ },
4721
+ removeAllItems: function () {
4722
+ return 'Remove all items';
4505
4723
  }
4506
4724
  };
4507
4725
  });
@@ -4740,66 +4958,29 @@ S2.define('select2/defaults',[
4740
4958
  );
4741
4959
  }
4742
4960
 
4743
- if (typeof options.language === 'string') {
4744
- // Check if the language is specified with a region
4745
- if (options.language.indexOf('-') > 0) {
4746
- // Extract the region information if it is included
4747
- var languageParts = options.language.split('-');
4748
- var baseLanguage = languageParts[0];
4961
+ // If the defaults were not previously applied from an element, it is
4962
+ // possible for the language option to have not been resolved
4963
+ options.language = this._resolveLanguage(options.language);
4749
4964
 
4750
- options.language = [options.language, baseLanguage];
4751
- } else {
4752
- options.language = [options.language];
4753
- }
4754
- }
4755
-
4756
- if ($.isArray(options.language)) {
4757
- var languages = new Translation();
4758
- options.language.push('en');
4965
+ // Always fall back to English since it will always be complete
4966
+ options.language.push('en');
4759
4967
 
4760
- var languageNames = options.language;
4968
+ var uniqueLanguages = [];
4761
4969
 
4762
- for (var l = 0; l < languageNames.length; l++) {
4763
- var name = languageNames[l];
4764
- var language = {};
4970
+ for (var l = 0; l < options.language.length; l++) {
4971
+ var language = options.language[l];
4765
4972
 
4766
- try {
4767
- // Try to load it with the original name
4768
- language = Translation.loadPath(name);
4769
- } catch (e) {
4770
- try {
4771
- // If we couldn't load it, check if it wasn't the full path
4772
- name = this.defaults.amdLanguageBase + name;
4773
- language = Translation.loadPath(name);
4774
- } catch (ex) {
4775
- // The translation could not be loaded at all. Sometimes this is
4776
- // because of a configuration problem, other times this can be
4777
- // because of how Select2 helps load all possible translation files.
4778
- if (options.debug && window.console && console.warn) {
4779
- console.warn(
4780
- 'Select2: The language file for "' + name + '" could not be ' +
4781
- 'automatically loaded. A fallback will be used instead.'
4782
- );
4783
- }
4784
-
4785
- continue;
4786
- }
4787
- }
4788
-
4789
- languages.extend(language);
4973
+ if (uniqueLanguages.indexOf(language) === -1) {
4974
+ uniqueLanguages.push(language);
4790
4975
  }
4976
+ }
4791
4977
 
4792
- options.translations = languages;
4793
- } else {
4794
- var baseTranslation = Translation.loadPath(
4795
- this.defaults.amdLanguageBase + 'en'
4796
- );
4797
- var customTranslation = new Translation(options.language);
4798
-
4799
- customTranslation.extend(baseTranslation);
4978
+ options.language = uniqueLanguages;
4800
4979
 
4801
- options.translations = customTranslation;
4802
- }
4980
+ options.translations = this._processTranslations(
4981
+ options.language,
4982
+ options.debug
4983
+ );
4803
4984
 
4804
4985
  return options;
4805
4986
  };
@@ -4866,13 +5047,14 @@ S2.define('select2/defaults',[
4866
5047
  debug: false,
4867
5048
  dropdownAutoWidth: false,
4868
5049
  escapeMarkup: Utils.escapeMarkup,
4869
- language: EnglishTranslation,
5050
+ language: {},
4870
5051
  matcher: matcher,
4871
5052
  minimumInputLength: 0,
4872
5053
  maximumInputLength: 0,
4873
5054
  maximumSelectionLength: 0,
4874
5055
  minimumResultsForSearch: 0,
4875
5056
  selectOnClose: false,
5057
+ scrollAfterSelect: false,
4876
5058
  sorter: function (data) {
4877
5059
  return data;
4878
5060
  },
@@ -4887,6 +5069,103 @@ S2.define('select2/defaults',[
4887
5069
  };
4888
5070
  };
4889
5071
 
5072
+ Defaults.prototype.applyFromElement = function (options, $element) {
5073
+ var optionLanguage = options.language;
5074
+ var defaultLanguage = this.defaults.language;
5075
+ var elementLanguage = $element.prop('lang');
5076
+ var parentLanguage = $element.closest('[lang]').prop('lang');
5077
+
5078
+ var languages = Array.prototype.concat.call(
5079
+ this._resolveLanguage(elementLanguage),
5080
+ this._resolveLanguage(optionLanguage),
5081
+ this._resolveLanguage(defaultLanguage),
5082
+ this._resolveLanguage(parentLanguage)
5083
+ );
5084
+
5085
+ options.language = languages;
5086
+
5087
+ return options;
5088
+ };
5089
+
5090
+ Defaults.prototype._resolveLanguage = function (language) {
5091
+ if (!language) {
5092
+ return [];
5093
+ }
5094
+
5095
+ if ($.isEmptyObject(language)) {
5096
+ return [];
5097
+ }
5098
+
5099
+ if ($.isPlainObject(language)) {
5100
+ return [language];
5101
+ }
5102
+
5103
+ var languages;
5104
+
5105
+ if (!$.isArray(language)) {
5106
+ languages = [language];
5107
+ } else {
5108
+ languages = language;
5109
+ }
5110
+
5111
+ var resolvedLanguages = [];
5112
+
5113
+ for (var l = 0; l < languages.length; l++) {
5114
+ resolvedLanguages.push(languages[l]);
5115
+
5116
+ if (typeof languages[l] === 'string' && languages[l].indexOf('-') > 0) {
5117
+ // Extract the region information if it is included
5118
+ var languageParts = languages[l].split('-');
5119
+ var baseLanguage = languageParts[0];
5120
+
5121
+ resolvedLanguages.push(baseLanguage);
5122
+ }
5123
+ }
5124
+
5125
+ return resolvedLanguages;
5126
+ };
5127
+
5128
+ Defaults.prototype._processTranslations = function (languages, debug) {
5129
+ var translations = new Translation();
5130
+
5131
+ for (var l = 0; l < languages.length; l++) {
5132
+ var languageData = new Translation();
5133
+
5134
+ var language = languages[l];
5135
+
5136
+ if (typeof language === 'string') {
5137
+ try {
5138
+ // Try to load it with the original name
5139
+ languageData = Translation.loadPath(language);
5140
+ } catch (e) {
5141
+ try {
5142
+ // If we couldn't load it, check if it wasn't the full path
5143
+ language = this.defaults.amdLanguageBase + language;
5144
+ languageData = Translation.loadPath(language);
5145
+ } catch (ex) {
5146
+ // The translation could not be loaded at all. Sometimes this is
5147
+ // because of a configuration problem, other times this can be
5148
+ // because of how Select2 helps load all possible translation files
5149
+ if (debug && window.console && console.warn) {
5150
+ console.warn(
5151
+ 'Select2: The language file for "' + language + '" could ' +
5152
+ 'not be automatically loaded. A fallback will be used instead.'
5153
+ );
5154
+ }
5155
+ }
5156
+ }
5157
+ } else if ($.isPlainObject(language)) {
5158
+ languageData = new Translation(language);
5159
+ } else {
5160
+ languageData = language;
5161
+ }
5162
+
5163
+ translations.extend(languageData);
5164
+ }
5165
+
5166
+ return translations;
5167
+ };
5168
+
4890
5169
  Defaults.prototype.set = function (key, value) {
4891
5170
  var camelKey = $.camelCase(key);
4892
5171
 
@@ -4895,7 +5174,7 @@ S2.define('select2/defaults',[
4895
5174
 
4896
5175
  var convertedData = Utils._convertData(data);
4897
5176
 
4898
- $.extend(this.defaults, convertedData);
5177
+ $.extend(true, this.defaults, convertedData);
4899
5178
  };
4900
5179
 
4901
5180
  var defaults = new Defaults();
@@ -4916,6 +5195,10 @@ S2.define('select2/options',[
4916
5195
  this.fromElement($element);
4917
5196
  }
4918
5197
 
5198
+ if ($element != null) {
5199
+ this.options = Defaults.applyFromElement(this.options, $element);
5200
+ }
5201
+
4919
5202
  this.options = Defaults.apply(this.options);
4920
5203
 
4921
5204
  if ($element && $element.is('input')) {
@@ -4939,14 +5222,6 @@ S2.define('select2/options',[
4939
5222
  this.options.disabled = $e.prop('disabled');
4940
5223
  }
4941
5224
 
4942
- if (this.options.language == null) {
4943
- if ($e.prop('lang')) {
4944
- this.options.language = $e.prop('lang').toLowerCase();
4945
- } else if ($e.closest('[lang]').prop('lang')) {
4946
- this.options.language = $e.closest('[lang]').prop('lang');
4947
- }
4948
- }
4949
-
4950
5225
  if (this.options.dir == null) {
4951
5226
  if ($e.prop('dir')) {
4952
5227
  this.options.dir = $e.prop('dir');
@@ -4960,7 +5235,7 @@ S2.define('select2/options',[
4960
5235
  $e.prop('disabled', this.options.disabled);
4961
5236
  $e.prop('multiple', this.options.multiple);
4962
5237
 
4963
- if ($e.data('select2Tags')) {
5238
+ if (Utils.GetData($e[0], 'select2Tags')) {
4964
5239
  if (this.options.debug && window.console && console.warn) {
4965
5240
  console.warn(
4966
5241
  'Select2: The `data-select2-tags` attribute has been changed to ' +
@@ -4969,11 +5244,11 @@ S2.define('select2/options',[
4969
5244
  );
4970
5245
  }
4971
5246
 
4972
- $e.data('data', $e.data('select2Tags'));
4973
- $e.data('tags', true);
5247
+ Utils.StoreData($e[0], 'data', Utils.GetData($e[0], 'select2Tags'));
5248
+ Utils.StoreData($e[0], 'tags', true);
4974
5249
  }
4975
5250
 
4976
- if ($e.data('ajaxUrl')) {
5251
+ if (Utils.GetData($e[0], 'ajaxUrl')) {
4977
5252
  if (this.options.debug && window.console && console.warn) {
4978
5253
  console.warn(
4979
5254
  'Select2: The `data-ajax-url` attribute has been changed to ' +
@@ -4982,21 +5257,45 @@ S2.define('select2/options',[
4982
5257
  );
4983
5258
  }
4984
5259
 
4985
- $e.attr('ajax--url', $e.data('ajaxUrl'));
4986
- $e.data('ajax--url', $e.data('ajaxUrl'));
5260
+ $e.attr('ajax--url', Utils.GetData($e[0], 'ajaxUrl'));
5261
+ Utils.StoreData($e[0], 'ajax-Url', Utils.GetData($e[0], 'ajaxUrl'));
4987
5262
  }
4988
5263
 
4989
5264
  var dataset = {};
4990
5265
 
5266
+ function upperCaseLetter(_, letter) {
5267
+ return letter.toUpperCase();
5268
+ }
5269
+
5270
+ // Pre-load all of the attributes which are prefixed with `data-`
5271
+ for (var attr = 0; attr < $e[0].attributes.length; attr++) {
5272
+ var attributeName = $e[0].attributes[attr].name;
5273
+ var prefix = 'data-';
5274
+
5275
+ if (attributeName.substr(0, prefix.length) == prefix) {
5276
+ // Get the contents of the attribute after `data-`
5277
+ var dataName = attributeName.substring(prefix.length);
5278
+
5279
+ // Get the data contents from the consistent source
5280
+ // This is more than likely the jQuery data helper
5281
+ var dataValue = Utils.GetData($e[0], dataName);
5282
+
5283
+ // camelCase the attribute name to match the spec
5284
+ var camelDataName = dataName.replace(/-([a-z])/g, upperCaseLetter);
5285
+
5286
+ // Store the data attribute contents into the dataset since
5287
+ dataset[camelDataName] = dataValue;
5288
+ }
5289
+ }
5290
+
4991
5291
  // Prefer the element's `dataset` attribute if it exists
4992
5292
  // jQuery 1.x does not correctly handle data attributes with multiple dashes
4993
5293
  if ($.fn.jquery && $.fn.jquery.substr(0, 2) == '1.' && $e[0].dataset) {
4994
- dataset = $.extend(true, {}, $e[0].dataset, $e.data());
4995
- } else {
4996
- dataset = $e.data();
5294
+ dataset = $.extend(true, {}, $e[0].dataset, dataset);
4997
5295
  }
4998
5296
 
4999
- var data = $.extend(true, {}, dataset);
5297
+ // Prefer our internal data cache if it exists
5298
+ var data = $.extend(true, {}, Utils.GetData($e[0]), dataset);
5000
5299
 
5001
5300
  data = Utils._convertData(data);
5002
5301
 
@@ -5033,8 +5332,8 @@ S2.define('select2/core',[
5033
5332
  './keys'
5034
5333
  ], function ($, Options, Utils, KEYS) {
5035
5334
  var Select2 = function ($element, options) {
5036
- if ($element.data('select2') != null) {
5037
- $element.data('select2').destroy();
5335
+ if (Utils.GetData($element[0], 'select2') != null) {
5336
+ Utils.GetData($element[0], 'select2').destroy();
5038
5337
  }
5039
5338
 
5040
5339
  this.$element = $element;
@@ -5050,7 +5349,7 @@ S2.define('select2/core',[
5050
5349
  // Set up the tabindex
5051
5350
 
5052
5351
  var tabindex = $element.attr('tabindex') || 0;
5053
- $element.data('old-tabindex', tabindex);
5352
+ Utils.StoreData($element[0], 'old-tabindex', tabindex);
5054
5353
  $element.attr('tabindex', '-1');
5055
5354
 
5056
5355
  // Set up containers and adapters
@@ -5111,6 +5410,9 @@ S2.define('select2/core',[
5111
5410
  // Synchronize any monitored attributes
5112
5411
  this._syncAttributes();
5113
5412
 
5413
+ Utils.StoreData($element[0], 'select2', this);
5414
+
5415
+ // Ensure backwards compatibility with $element.data('select2').
5114
5416
  $element.data('select2', this);
5115
5417
  };
5116
5418
 
@@ -5187,6 +5489,12 @@ S2.define('select2/core',[
5187
5489
  return null;
5188
5490
  }
5189
5491
 
5492
+ if (method == 'computedstyle') {
5493
+ var computedStyle = window.getComputedStyle($element[0]);
5494
+
5495
+ return computedStyle.width;
5496
+ }
5497
+
5190
5498
  return method;
5191
5499
  };
5192
5500
 
@@ -5445,7 +5753,8 @@ S2.define('select2/core',[
5445
5753
  'open': 'opening',
5446
5754
  'close': 'closing',
5447
5755
  'select': 'selecting',
5448
- 'unselect': 'unselecting'
5756
+ 'unselect': 'unselecting',
5757
+ 'clear': 'clearing'
5449
5758
  };
5450
5759
 
5451
5760
  if (args === undefined) {
@@ -5600,10 +5909,12 @@ S2.define('select2/core',[
5600
5909
  this._syncS = null;
5601
5910
 
5602
5911
  this.$element.off('.select2');
5603
- this.$element.attr('tabindex', this.$element.data('old-tabindex'));
5912
+ this.$element.attr('tabindex',
5913
+ Utils.GetData(this.$element[0], 'old-tabindex'));
5604
5914
 
5605
5915
  this.$element.removeClass('select2-hidden-accessible');
5606
5916
  this.$element.attr('aria-hidden', 'false');
5917
+ Utils.RemoveData(this.$element[0]);
5607
5918
  this.$element.removeData('select2');
5608
5919
 
5609
5920
  this.dataAdapter.destroy();
@@ -5631,7 +5942,7 @@ S2.define('select2/core',[
5631
5942
 
5632
5943
  this.$container.addClass('select2-container--' + this.options.get('theme'));
5633
5944
 
5634
- $container.data('element', this.$element);
5945
+ Utils.StoreData($container[0], 'element', this.$element);
5635
5946
 
5636
5947
  return $container;
5637
5948
  };
@@ -5841,8 +6152,9 @@ S2.define('select2/compat/initSelection',[
5841
6152
  });
5842
6153
 
5843
6154
  S2.define('select2/compat/inputData',[
5844
- 'jquery'
5845
- ], function ($) {
6155
+ 'jquery',
6156
+ '../utils'
6157
+ ], function ($, Utils) {
5846
6158
  function InputData (decorated, $element, options) {
5847
6159
  this._currentData = [];
5848
6160
  this._valueSeparator = options.get('valueSeparator') || ',';
@@ -5959,7 +6271,7 @@ S2.define('select2/compat/inputData',[
5959
6271
 
5960
6272
  InputData.prototype.addOptions = function (_, $options) {
5961
6273
  var options = $.map($options, function ($option) {
5962
- return $.data($option[0], 'data');
6274
+ return Utils.GetData($option[0], 'data');
5963
6275
  });
5964
6276
 
5965
6277
  this._currentData.push.apply(this._currentData, options);
@@ -6362,8 +6674,9 @@ S2.define('jquery.select2',[
6362
6674
  'jquery-mousewheel',
6363
6675
 
6364
6676
  './select2/core',
6365
- './select2/defaults'
6366
- ], function ($, _, Select2, Defaults) {
6677
+ './select2/defaults',
6678
+ './select2/utils'
6679
+ ], function ($, _, Select2, Defaults, Utils) {
6367
6680
  if ($.fn.select2 == null) {
6368
6681
  // All methods that should return the element
6369
6682
  var thisMethods = ['open', 'close', 'destroy'];
@@ -6384,7 +6697,7 @@ S2.define('jquery.select2',[
6384
6697
  var args = Array.prototype.slice.call(arguments, 1);
6385
6698
 
6386
6699
  this.each(function () {
6387
- var instance = $(this).data('select2');
6700
+ var instance = Utils.GetData(this, 'select2');
6388
6701
 
6389
6702
  if (instance == null && window.console && console.error) {
6390
6703
  console.error(