1
0
mirror of synced 2024-11-22 21:16:10 +03:00

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.
This commit is contained in:
Kevin Brown 2015-01-02 18:15:59 -05:00
parent 12f7ed93f8
commit f1e86470ca
7 changed files with 32 additions and 12 deletions

View File

@ -4065,13 +4065,17 @@ define('jquery.select2',[
if (typeof options === 'object') { if (typeof options === 'object') {
this.each(function () { this.each(function () {
var instance = new Select2($(this), options); var instanceOptions = $.extend({}, options, true);
var instance = new Select2($(this), instanceOptions);
}); });
return this;
} else if (typeof options === 'string') { } else if (typeof options === 'string') {
var instance = this.data('select2'); var instance = this.data('select2');
var args = Array.prototype.slice.call(arguments, 1); var args = Array.prototype.slice.call(arguments, 1);
instance[options](args); return instance[options](args);
} else { } else {
throw new Error('Invalid arguments for Select2: ' + options); throw new Error('Invalid arguments for Select2: ' + options);
} }

View File

@ -4003,13 +4003,17 @@ define('jquery.select2',[
if (typeof options === 'object') { if (typeof options === 'object') {
this.each(function () { this.each(function () {
var instance = new Select2($(this), options); var instanceOptions = $.extend({}, options, true);
var instance = new Select2($(this), instanceOptions);
}); });
return this;
} else if (typeof options === 'string') { } else if (typeof options === 'string') {
var instance = this.data('select2'); var instance = this.data('select2');
var args = Array.prototype.slice.call(arguments, 1); var args = Array.prototype.slice.call(arguments, 1);
instance[options](args); return instance[options](args);
} else { } else {
throw new Error('Invalid arguments for Select2: ' + options); throw new Error('Invalid arguments for Select2: ' + options);
} }

View File

@ -13600,13 +13600,17 @@ define('jquery.select2',[
if (typeof options === 'object') { if (typeof options === 'object') {
this.each(function () { this.each(function () {
var instance = new Select2($(this), options); var instanceOptions = $.extend({}, options, true);
var instance = new Select2($(this), instanceOptions);
}); });
return this;
} else if (typeof options === 'string') { } else if (typeof options === 'string') {
var instance = this.data('select2'); var instance = this.data('select2');
var args = Array.prototype.slice.call(arguments, 1); var args = Array.prototype.slice.call(arguments, 1);
instance[options](args); return instance[options](args);
} else { } else {
throw new Error('Invalid arguments for Select2: ' + options); throw new Error('Invalid arguments for Select2: ' + options);
} }

File diff suppressed because one or more lines are too long

8
dist/js/select2.js vendored
View File

@ -4431,13 +4431,17 @@ define('jquery.select2',[
if (typeof options === 'object') { if (typeof options === 'object') {
this.each(function () { this.each(function () {
var instance = new Select2($(this), options); var instanceOptions = $.extend({}, options, true);
var instance = new Select2($(this), instanceOptions);
}); });
return this;
} else if (typeof options === 'string') { } else if (typeof options === 'string') {
var instance = this.data('select2'); var instance = this.data('select2');
var args = Array.prototype.slice.call(arguments, 1); var args = Array.prototype.slice.call(arguments, 1);
instance[options](args); return instance[options](args);
} else { } else {
throw new Error('Invalid arguments for Select2: ' + options); throw new Error('Invalid arguments for Select2: ' + options);
} }

File diff suppressed because one or more lines are too long

View File

@ -8,13 +8,17 @@ define([
if (typeof options === 'object') { if (typeof options === 'object') {
this.each(function () { this.each(function () {
var instance = new Select2($(this), options); var instanceOptions = $.extend({}, options, true);
var instance = new Select2($(this), instanceOptions);
}); });
return this;
} else if (typeof options === 'string') { } else if (typeof options === 'string') {
var instance = this.data('select2'); var instance = this.data('select2');
var args = Array.prototype.slice.call(arguments, 1); var args = Array.prototype.slice.call(arguments, 1);
instance[options](args); return instance[options](args);
} else { } else {
throw new Error('Invalid arguments for Select2: ' + options); throw new Error('Invalid arguments for Select2: ' + options);
} }