Browse Source

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.
Kevin Brown 10 years ago
parent
commit
f1e86470ca

+ 6 - 2
dist/js/select2.amd.full.js

@@ -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);
       }
       }

+ 6 - 2
dist/js/select2.amd.js

@@ -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);
       }
       }

+ 6 - 2
dist/js/select2.full.js

@@ -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 it is too large
+ 0 - 0
dist/js/select2.full.min.js


+ 6 - 2
dist/js/select2.js

@@ -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 it is too large
+ 0 - 0
dist/js/select2.min.js


+ 6 - 2
src/js/jquery.select2.js

@@ -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);
       }
       }

Some files were not shown because too many files changed in this diff