Skip to content

Commit 62c4f63

Browse files
committed
Merge branch 'master' of https://github.com/NadeemAfana/select2 into develop
2 parents 77acc56 + b6f0f3a commit 62c4f63

15 files changed

Lines changed: 145 additions & 47 deletions

File tree

src/js/jquery.select2.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ define([
33
'jquery-mousewheel',
44

55
'./select2/core',
6-
'./select2/defaults'
7-
], function ($, _, Select2, Defaults) {
6+
'./select2/defaults',
7+
'./select2/utils'
8+
], function ($, _, Select2, Defaults, Utils) {
89
if ($.fn.select2 == null) {
910
// All methods that should return the element
1011
var thisMethods = ['open', 'close', 'destroy'];
@@ -25,7 +26,7 @@ define([
2526
var args = Array.prototype.slice.call(arguments, 1);
2627

2728
this.each(function () {
28-
var instance = $(this).data('select2');
29+
var instance = Utils.GetData(this, 'select2');
2930

3031
if (instance == null && window.console && console.error) {
3132
console.error(

src/js/select2/compat/inputData.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
define([
2-
'jquery'
3-
], function ($) {
2+
'jquery',
3+
'../utils'
4+
], function ($, Utils) {
45
function InputData (decorated, $element, options) {
56
this._currentData = [];
67
this._valueSeparator = options.get('valueSeparator') || ',';
@@ -117,7 +118,7 @@ define([
117118

118119
InputData.prototype.addOptions = function (_, $options) {
119120
var options = $.map($options, function ($option) {
120-
return $.data($option[0], 'data');
121+
return Utils.GetData($option[0], 'data');
121122
});
122123

123124
this._currentData.push.apply(this._currentData, options);

src/js/select2/core.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ define([
55
'./keys'
66
], function ($, Options, Utils, KEYS) {
77
var Select2 = function ($element, options) {
8-
if ($element.data('select2') != null) {
9-
$element.data('select2').destroy();
8+
if (Utils.GetData($element[0], 'select2') != null) {
9+
Utils.GetData($element[0], 'select2').destroy();
1010
}
1111

1212
this.$element = $element;
@@ -22,7 +22,7 @@ define([
2222
// Set up the tabindex
2323

2424
var tabindex = $element.attr('tabindex') || 0;
25-
$element.data('old-tabindex', tabindex);
25+
Utils.StoreData($element[0], 'old-tabindex', tabindex);
2626
$element.attr('tabindex', '-1');
2727

2828
// Set up containers and adapters
@@ -83,7 +83,7 @@ define([
8383
// Synchronize any monitored attributes
8484
this._syncAttributes();
8585

86-
$element.data('select2', this);
86+
Utils.StoreData($element[0], 'select2', this);
8787
};
8888

8989
Utils.Extend(Select2, Utils.Observable);
@@ -573,11 +573,12 @@ define([
573573
this._syncS = null;
574574

575575
this.$element.off('.select2');
576-
this.$element.attr('tabindex', this.$element.data('old-tabindex'));
576+
this.$element.attr('tabindex',
577+
Utils.GetData(this.$element[0], 'old-tabindex'));
577578

578579
this.$element.removeClass('select2-hidden-accessible');
579580
this.$element.attr('aria-hidden', 'false');
580-
this.$element.removeData('select2');
581+
Utils.RemoveData(this.$element[0]);
581582

582583
this.dataAdapter.destroy();
583584
this.selection.destroy();
@@ -604,7 +605,7 @@ define([
604605

605606
this.$container.addClass('select2-container--' + this.options.get('theme'));
606607

607-
$container.data('element', this.$element);
608+
Utils.StoreData($container[0], 'element', this.$element);
608609

609610
return $container;
610611
};

src/js/select2/data/select.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ define([
119119
// Remove anything added to child elements
120120
this.$element.find('*').each(function () {
121121
// Remove any custom data set by Select2
122-
$.removeData(this, 'data');
122+
Utils.RemoveData(this);
123123
});
124124
};
125125

@@ -192,15 +192,15 @@ define([
192192
normalizedData.element = option;
193193

194194
// Override the option's data with the combined data
195-
$.data(option, 'data', normalizedData);
195+
Utils.StoreData(option, 'data', normalizedData);
196196

197197
return $option;
198198
};
199199

200200
SelectAdapter.prototype.item = function ($option) {
201201
var data = {};
202202

203-
data = $.data($option[0], 'data');
203+
data = Utils.GetData($option[0], 'data');
204204

205205
if (data != null) {
206206
return data;
@@ -238,7 +238,7 @@ define([
238238
data = this._normalizeItem(data);
239239
data.element = $option[0];
240240

241-
$.data($option[0], 'data', data);
241+
Utils.StoreData($option[0], 'data', data);
242242

243243
return data;
244244
};

src/js/select2/dropdown/attachBody.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ define([
9090

9191
var $watchers = this.$container.parents().filter(Utils.hasScroll);
9292
$watchers.each(function () {
93-
$(this).data('select2-scroll-position', {
93+
Utils.StoreData(this, 'select2-scroll-position', {
9494
x: $(this).scrollLeft(),
9595
y: $(this).scrollTop()
9696
});
9797
});
9898

9999
$watchers.on(scrollEvent, function (ev) {
100-
var position = $(this).data('select2-scroll-position');
100+
var position = Utils.GetData(this, 'select2-scroll-position');
101101
$(this).scrollTop(position.y);
102102
});
103103

src/js/select2/dropdown/selectOnClose.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
define([
2-
3-
], function () {
2+
'../utils'
3+
], function (Utils) {
44
function SelectOnClose () { }
55

66
SelectOnClose.prototype.bind = function (decorated, container, $container) {
@@ -31,7 +31,7 @@ define([
3131
return;
3232
}
3333

34-
var data = $highlightedResults.data('data');
34+
var data = Utils.GetData($highlightedResults[0], 'data');
3535

3636
// Don't re-select already selected resulte
3737
if (

src/js/select2/options.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ define([
5555
$e.prop('disabled', this.options.disabled);
5656
$e.prop('multiple', this.options.multiple);
5757

58-
if ($e.data('select2Tags')) {
58+
if (Utils.GetData($e[0], 'select2Tags')) {
5959
if (this.options.debug && window.console && console.warn) {
6060
console.warn(
6161
'Select2: The `data-select2-tags` attribute has been changed to ' +
@@ -64,11 +64,11 @@ define([
6464
);
6565
}
6666

67-
$e.data('data', $e.data('select2Tags'));
68-
$e.data('tags', true);
67+
Utils.StoreData($e[0], 'data', Utils.GetData($e[0], 'select2Tags'));
68+
Utils.StoreData($e[0], 'tags', true);
6969
}
7070

71-
if ($e.data('ajaxUrl')) {
71+
if (Utils.GetData($e[0], 'ajaxUrl')) {
7272
if (this.options.debug && window.console && console.warn) {
7373
console.warn(
7474
'Select2: The `data-ajax-url` attribute has been changed to ' +
@@ -77,18 +77,19 @@ define([
7777
);
7878
}
7979

80-
$e.attr('ajax--url', $e.data('ajaxUrl'));
81-
$e.data('ajax--url', $e.data('ajaxUrl'));
80+
$e.attr('ajax--url', Utils.GetData($e[0], 'ajaxUrl'));
81+
Utils.StoreData($e[0], 'ajax-Url', Utils.GetData($e[0], 'ajaxUrl'));
82+
8283
}
8384

8485
var dataset = {};
8586

8687
// Prefer the element's `dataset` attribute if it exists
8788
// jQuery 1.x does not correctly handle data attributes with multiple dashes
8889
if ($.fn.jquery && $.fn.jquery.substr(0, 2) == '1.' && $e[0].dataset) {
89-
dataset = $.extend(true, {}, $e[0].dataset, $e.data());
90+
dataset = $.extend(true, {}, $e[0].dataset, Utils.GetData($e[0]));
9091
} else {
91-
dataset = $e.data();
92+
dataset = Utils.GetData($e[0]);
9293
}
9394

9495
var data = $.extend(true, {}, dataset);

src/js/select2/results.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ define([
130130
$options.each(function () {
131131
var $option = $(this);
132132

133-
var item = $.data(this, 'data');
133+
var item = Utils.GetData(this, 'data');
134134

135135
// id needs to be converted to a string when comparing
136136
var id = '' + item.id;
@@ -235,7 +235,7 @@ define([
235235
this.template(data, option);
236236
}
237237

238-
$.data(option, 'data', data);
238+
Utils.StoreData(option, 'data', data);
239239

240240
return option;
241241
};
@@ -321,7 +321,7 @@ define([
321321
return;
322322
}
323323

324-
var data = $highlighted.data('data');
324+
var data = Utils.GetData($highlighted[0], 'data');
325325

326326
if ($highlighted.attr('aria-selected') == 'true') {
327327
self.trigger('close', {});
@@ -433,7 +433,7 @@ define([
433433
function (evt) {
434434
var $this = $(this);
435435

436-
var data = $this.data('data');
436+
var data = Utils.GetData(this, 'data');
437437

438438
if ($this.attr('aria-selected') === 'true') {
439439
if (self.options.get('multiple')) {
@@ -456,7 +456,7 @@ define([
456456

457457
this.$results.on('mouseenter', '.select2-results__option[aria-selected]',
458458
function (evt) {
459-
var data = $(this).data('data');
459+
var data = Utils.GetData(this, 'data');
460460

461461
self.getHighlightedResults()
462462
.removeClass('select2-results__option--highlighted');

src/js/select2/selection/allowClear.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
define([
22
'jquery',
3-
'../keys'
4-
], function ($, KEYS) {
3+
'../keys',
4+
'../utils'
5+
], function ($, KEYS, Utils) {
56
function AllowClear () { }
67

78
AllowClear.prototype.bind = function (decorated, container, $container) {
@@ -43,7 +44,7 @@ define([
4344

4445
evt.stopPropagation();
4546

46-
var data = $clear.data('data');
47+
var data = Utils.GetData($clear[0], 'data');
4748

4849
var previousVal = this.$element.val();
4950
this.$element.val(this.placeholder.id);
@@ -101,7 +102,7 @@ define([
101102
'×' +
102103
'</span>'
103104
);
104-
$remove.data('data', data);
105+
Utils.StoreData($remove[0], 'data', data);
105106

106107
this.$selection.find('.select2-selection__rendered').prepend($remove);
107108
};

src/js/select2/selection/base.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ define([
2121

2222
this._tabindex = 0;
2323

24-
if (this.$element.data('old-tabindex') != null) {
25-
this._tabindex = this.$element.data('old-tabindex');
24+
if (Utils.GetData(this.$element[0], 'old-tabindex') != null) {
25+
this._tabindex = Utils.GetData(this.$element[0], 'old-tabindex');
2626
} else if (this.$element.attr('tabindex') != null) {
2727
this._tabindex = this.$element.attr('tabindex');
2828
}
@@ -130,7 +130,7 @@ define([
130130
return;
131131
}
132132

133-
var $element = $this.data('element');
133+
var $element = Utils.GetData(this, 'element');
134134

135135
$element.select2('close');
136136
});

0 commit comments

Comments
 (0)