Skip to content

Commit f1e8647

Browse files
committed
Clone the options for group elements
This will always clone the options that are passed in when initializing Select2 on multiple objects (like `$("select")`) so it doesn't always assume that the configuration is the exact same. This prevents any reference-based tricks for modifying the data within Select2, but some would look at that as an upside.
1 parent 12f7ed9 commit f1e8647

7 files changed

Lines changed: 32 additions & 12 deletions

File tree

dist/js/select2.amd.full.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4065,13 +4065,17 @@ define('jquery.select2',[
40654065

40664066
if (typeof options === 'object') {
40674067
this.each(function () {
4068-
var instance = new Select2($(this), options);
4068+
var instanceOptions = $.extend({}, options, true);
4069+
4070+
var instance = new Select2($(this), instanceOptions);
40694071
});
4072+
4073+
return this;
40704074
} else if (typeof options === 'string') {
40714075
var instance = this.data('select2');
40724076
var args = Array.prototype.slice.call(arguments, 1);
40734077

4074-
instance[options](args);
4078+
return instance[options](args);
40754079
} else {
40764080
throw new Error('Invalid arguments for Select2: ' + options);
40774081
}

dist/js/select2.amd.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4003,13 +4003,17 @@ define('jquery.select2',[
40034003

40044004
if (typeof options === 'object') {
40054005
this.each(function () {
4006-
var instance = new Select2($(this), options);
4006+
var instanceOptions = $.extend({}, options, true);
4007+
4008+
var instance = new Select2($(this), instanceOptions);
40074009
});
4010+
4011+
return this;
40084012
} else if (typeof options === 'string') {
40094013
var instance = this.data('select2');
40104014
var args = Array.prototype.slice.call(arguments, 1);
40114015

4012-
instance[options](args);
4016+
return instance[options](args);
40134017
} else {
40144018
throw new Error('Invalid arguments for Select2: ' + options);
40154019
}

dist/js/select2.full.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13600,13 +13600,17 @@ define('jquery.select2',[
1360013600

1360113601
if (typeof options === 'object') {
1360213602
this.each(function () {
13603-
var instance = new Select2($(this), options);
13603+
var instanceOptions = $.extend({}, options, true);
13604+
13605+
var instance = new Select2($(this), instanceOptions);
1360413606
});
13607+
13608+
return this;
1360513609
} else if (typeof options === 'string') {
1360613610
var instance = this.data('select2');
1360713611
var args = Array.prototype.slice.call(arguments, 1);
1360813612

13609-
instance[options](args);
13613+
return instance[options](args);
1361013614
} else {
1361113615
throw new Error('Invalid arguments for Select2: ' + options);
1361213616
}

dist/js/select2.full.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/select2.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4431,13 +4431,17 @@ define('jquery.select2',[
44314431

44324432
if (typeof options === 'object') {
44334433
this.each(function () {
4434-
var instance = new Select2($(this), options);
4434+
var instanceOptions = $.extend({}, options, true);
4435+
4436+
var instance = new Select2($(this), instanceOptions);
44354437
});
4438+
4439+
return this;
44364440
} else if (typeof options === 'string') {
44374441
var instance = this.data('select2');
44384442
var args = Array.prototype.slice.call(arguments, 1);
44394443

4440-
instance[options](args);
4444+
return instance[options](args);
44414445
} else {
44424446
throw new Error('Invalid arguments for Select2: ' + options);
44434447
}

dist/js/select2.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/js/jquery.select2.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@ define([
88

99
if (typeof options === 'object') {
1010
this.each(function () {
11-
var instance = new Select2($(this), options);
11+
var instanceOptions = $.extend({}, options, true);
12+
13+
var instance = new Select2($(this), instanceOptions);
1214
});
15+
16+
return this;
1317
} else if (typeof options === 'string') {
1418
var instance = this.data('select2');
1519
var args = Array.prototype.slice.call(arguments, 1);
1620

17-
instance[options](args);
21+
return instance[options](args);
1822
} else {
1923
throw new Error('Invalid arguments for Select2: ' + options);
2024
}

0 commit comments

Comments
 (0)