Bladeren bron

Allow chaining of `.select2()`

`.select2("open")`, `.select2("close")`, and `.select2("destroy")`
can now be safely chained.

This closes https://github.com/select2/select2/issues/3221.
Kevin Brown 10 jaren geleden
bovenliggende
commit
01160f29d8
5 gewijzigde bestanden met toevoegingen van 33 en 3 verwijderingen
  1. 11 1
      dist/js/select2.full.js
  2. 0 0
      dist/js/select2.full.min.js
  3. 11 1
      dist/js/select2.js
  4. 0 0
      dist/js/select2.min.js
  5. 11 1
      src/js/jquery.select2.js

+ 11 - 1
dist/js/select2.full.js

@@ -5574,6 +5574,9 @@ S2.define('jquery.select2',[
   require('jquery.mousewheel');
 
   if ($.fn.select2 == null) {
+    // All methods that should return the element
+    var thisMethods = ['open', 'close', 'destroy'];
+
     $.fn.select2 = function (options) {
       options = options || {};
 
@@ -5589,7 +5592,14 @@ S2.define('jquery.select2',[
         var instance = this.data('select2');
         var args = Array.prototype.slice.call(arguments, 1);
 
-        return instance[options](args);
+        var ret = instance[options](args);
+
+        // Check if we should be returning `this`
+        if ($.inArray(options, thisMethods) > -1) {
+          return this;
+        }
+
+        return ret;
       } else {
         throw new Error('Invalid arguments for Select2: ' + options);
       }

File diff suppressed because it is too large
+ 0 - 0
dist/js/select2.full.min.js


+ 11 - 1
dist/js/select2.js

@@ -5236,6 +5236,9 @@ S2.define('jquery.select2',[
   require('jquery.mousewheel');
 
   if ($.fn.select2 == null) {
+    // All methods that should return the element
+    var thisMethods = ['open', 'close', 'destroy'];
+
     $.fn.select2 = function (options) {
       options = options || {};
 
@@ -5251,7 +5254,14 @@ S2.define('jquery.select2',[
         var instance = this.data('select2');
         var args = Array.prototype.slice.call(arguments, 1);
 
-        return instance[options](args);
+        var ret = instance[options](args);
+
+        // Check if we should be returning `this`
+        if ($.inArray(options, thisMethods) > -1) {
+          return this;
+        }
+
+        return ret;
       } else {
         throw new Error('Invalid arguments for Select2: ' + options);
       }

File diff suppressed because it is too large
+ 0 - 0
dist/js/select2.min.js


+ 11 - 1
src/js/jquery.select2.js

@@ -9,6 +9,9 @@ define([
   require('jquery.mousewheel');
 
   if ($.fn.select2 == null) {
+    // All methods that should return the element
+    var thisMethods = ['open', 'close', 'destroy'];
+
     $.fn.select2 = function (options) {
       options = options || {};
 
@@ -24,7 +27,14 @@ define([
         var instance = this.data('select2');
         var args = Array.prototype.slice.call(arguments, 1);
 
-        return instance[options](args);
+        var ret = instance[options](args);
+
+        // Check if we should be returning `this`
+        if ($.inArray(options, thisMethods) > -1) {
+          return this;
+        }
+
+        return ret;
       } else {
         throw new Error('Invalid arguments for Select2: ' + options);
       }

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