1
0
mirror of synced 2025-02-09 16:49:24 +03:00

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.
This commit is contained in:
Kevin Brown 2015-04-02 10:34:30 -04:00
parent da1ec4e028
commit 01160f29d8
5 changed files with 36 additions and 6 deletions

View File

@ -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 one or more lines are too long

12
dist/js/select2.js vendored
View File

@ -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 one or more lines are too long

View File

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