1
1
/*!
2
- * jQuery UI Widget master
2
+ * jQuery UI Widget 1.12.1
3
3
* http://jqueryui.com
4
4
*
5
5
* Copyright jQuery Foundation and other contributors
@@ -215,35 +215,42 @@ $.widget.bridge = function( name, object ) {
215
215
var returnValue = this ;
216
216
217
217
if ( isMethodCall ) {
218
- this . each ( function ( ) {
219
- var methodValue ;
220
- var instance = $ . data ( this , fullName ) ;
221
218
222
- if ( options === "instance" ) {
223
- returnValue = instance ;
224
- return false ;
225
- }
219
+ // If this is an empty collection, we need to have the instance method
220
+ // return undefined instead of the jQuery instance
221
+ if ( ! this . length && options === "instance" ) {
222
+ returnValue = undefined ;
223
+ } else {
224
+ this . each ( function ( ) {
225
+ var methodValue ;
226
+ var instance = $ . data ( this , fullName ) ;
226
227
227
- if ( ! instance ) {
228
- return $ . error ( "cannot call methods on " + name +
229
- " prior to initialization; " +
230
- "attempted to call method '" + options + "'" ) ;
231
- }
228
+ if ( options === "instance" ) {
229
+ returnValue = instance ;
230
+ return false ;
231
+ }
232
232
233
- if ( ! $ . isFunction ( instance [ options ] ) || options . charAt ( 0 ) === "_" ) {
234
- return $ . error ( "no such method '" + options + "' for " + name +
235
- " widget instance" ) ;
236
- }
233
+ if ( ! instance ) {
234
+ return $ . error ( "cannot call methods on " + name +
235
+ " prior to initialization; " +
236
+ "attempted to call method '" + options + "'" ) ;
237
+ }
237
238
238
- methodValue = instance [ options ] . apply ( instance , args ) ;
239
+ if ( ! $ . isFunction ( instance [ options ] ) || options . charAt ( 0 ) === "_" ) {
240
+ return $ . error ( "no such method '" + options + "' for " + name +
241
+ " widget instance" ) ;
242
+ }
239
243
240
- if ( methodValue !== instance && methodValue !== undefined ) {
241
- returnValue = methodValue && methodValue . jquery ?
242
- returnValue . pushStack ( methodValue . get ( ) ) :
243
- methodValue ;
244
- return false ;
245
- }
246
- } ) ;
244
+ methodValue = instance [ options ] . apply ( instance , args ) ;
245
+
246
+ if ( methodValue !== instance && methodValue !== undefined ) {
247
+ returnValue = methodValue && methodValue . jquery ?
248
+ returnValue . pushStack ( methodValue . get ( ) ) :
249
+ methodValue ;
250
+ return false ;
251
+ }
252
+ } ) ;
253
+ }
247
254
} else {
248
255
249
256
// Allow multiple hashes to be passed on init
@@ -507,6 +514,10 @@ $.Widget.prototype = {
507
514
}
508
515
}
509
516
517
+ this . _on ( options . element , {
518
+ "remove" : "_untrackClassesElement"
519
+ } ) ;
520
+
510
521
if ( options . keys ) {
511
522
processClassString ( options . keys . match ( / \S + / g ) || [ ] , true ) ;
512
523
}
@@ -517,6 +528,15 @@ $.Widget.prototype = {
517
528
return full . join ( " " ) ;
518
529
} ,
519
530
531
+ _untrackClassesElement : function ( event ) {
532
+ var that = this ;
533
+ $ . each ( that . classesElementLookup , function ( key , value ) {
534
+ if ( $ . inArray ( event . target , value ) !== - 1 ) {
535
+ that . classesElementLookup [ key ] = $ ( value . not ( event . target ) . get ( ) ) ;
536
+ }
537
+ } ) ;
538
+ } ,
539
+
520
540
_removeClass : function ( element , keys , extra ) {
521
541
return this . _toggleClass ( element , keys , extra , false ) ;
522
542
} ,
0 commit comments