aboutsummaryrefslogtreecommitdiffstats
path: root/ui/widget.js
diff options
context:
space:
mode:
authorScott González <scott.gonzalez@gmail.com>2016-08-04 09:04:16 -0400
committerScott González <scott.gonzalez@gmail.com>2016-08-04 09:04:49 -0400
commit3dd8a09b441d65445f2b6a7c73e72af65445d5da (patch)
treefd2061f01c4222be98395c6e6772bc95056e9ffa /ui/widget.js
parent57537d09a42ed53d6244d9222d954e107b2b44d0 (diff)
downloadjquery-ui-3dd8a09b441d65445f2b6a7c73e72af65445d5da.tar.gz
jquery-ui-3dd8a09b441d65445f2b6a7c73e72af65445d5da.zip
Widget: `instance()` should return `undefined` for empty sets
Fixes #15019
Diffstat (limited to 'ui/widget.js')
-rw-r--r--ui/widget.js55
1 files changed, 31 insertions, 24 deletions
diff --git a/ui/widget.js b/ui/widget.js
index c82b95326..06a3ce88e 100644
--- a/ui/widget.js
+++ b/ui/widget.js
@@ -215,35 +215,42 @@ $.widget.bridge = function( name, object ) {
var returnValue = this;
if ( isMethodCall ) {
- this.each( function() {
- var methodValue;
- var instance = $.data( this, fullName );
- if ( options === "instance" ) {
- returnValue = instance;
- return false;
- }
+ // If this is an empty collection, we need to have the instance method
+ // return undefined instead of the jQuery instance
+ if ( !this.length && options === "instance" ) {
+ returnValue = undefined;
+ } else {
+ this.each( function() {
+ var methodValue;
+ var instance = $.data( this, fullName );
- if ( !instance ) {
- return $.error( "cannot call methods on " + name +
- " prior to initialization; " +
- "attempted to call method '" + options + "'" );
- }
+ if ( options === "instance" ) {
+ returnValue = instance;
+ return false;
+ }
- if ( !$.isFunction( instance[ options ] ) || options.charAt( 0 ) === "_" ) {
- return $.error( "no such method '" + options + "' for " + name +
- " widget instance" );
- }
+ if ( !instance ) {
+ return $.error( "cannot call methods on " + name +
+ " prior to initialization; " +
+ "attempted to call method '" + options + "'" );
+ }
- methodValue = instance[ options ].apply( instance, args );
+ if ( !$.isFunction( instance[ options ] ) || options.charAt( 0 ) === "_" ) {
+ return $.error( "no such method '" + options + "' for " + name +
+ " widget instance" );
+ }
- if ( methodValue !== instance && methodValue !== undefined ) {
- returnValue = methodValue && methodValue.jquery ?
- returnValue.pushStack( methodValue.get() ) :
- methodValue;
- return false;
- }
- } );
+ methodValue = instance[ options ].apply( instance, args );
+
+ if ( methodValue !== instance && methodValue !== undefined ) {
+ returnValue = methodValue && methodValue.jquery ?
+ returnValue.pushStack( methodValue.get() ) :
+ methodValue;
+ return false;
+ }
+ } );
+ }
} else {
// Allow multiple hashes to be passed on init