@@ -86,6 +86,7 @@ return $.widget( "ui.tooltip", {
86
86
87
87
// IDs of generated tooltips, needed for destroy
88
88
this . tooltips = { } ;
89
+
89
90
// IDs of parent tooltips where we removed the title attribute
90
91
this . parents = { } ;
91
92
@@ -117,8 +118,8 @@ return $.widget( "ui.tooltip", {
117
118
this . _super ( key , value ) ;
118
119
119
120
if ( key === "content" ) {
120
- $ . each ( this . tooltips , function ( id , element ) {
121
- that . _updateContent ( element ) ;
121
+ $ . each ( this . tooltips , function ( id , tooltipData ) {
122
+ that . _updateContent ( tooltipData . element ) ;
122
123
} ) ;
123
124
}
124
125
} ,
@@ -127,9 +128,9 @@ return $.widget( "ui.tooltip", {
127
128
var that = this ;
128
129
129
130
// close open tooltips
130
- $ . each ( this . tooltips , function ( id , element ) {
131
+ $ . each ( this . tooltips , function ( id , tooltipData ) {
131
132
var event = $ . Event ( "blur" ) ;
132
- event . target = event . currentTarget = element [ 0 ] ;
133
+ event . target = event . currentTarget = tooltipData . element [ 0 ] ;
133
134
that . close ( event , true ) ;
134
135
} ) ;
135
136
@@ -231,7 +232,7 @@ return $.widget( "ui.tooltip", {
231
232
} ,
232
233
233
234
_open : function ( event , target , content ) {
234
- var tooltip , events , delayedShow , a11yContent ,
235
+ var tooltipData , tooltip , events , delayedShow , a11yContent ,
235
236
positionOption = $ . extend ( { } , this . options . position ) ;
236
237
237
238
if ( ! content ) {
@@ -240,9 +241,9 @@ return $.widget( "ui.tooltip", {
240
241
241
242
// Content can be updated multiple times. If the tooltip already
242
243
// exists, then just update the content and bail.
243
- tooltip = this . _find ( target ) ;
244
- if ( tooltip . length ) {
245
- tooltip . find ( ".ui-tooltip-content" ) . html ( content ) ;
244
+ tooltipData = this . _find ( target ) ;
245
+ if ( tooltipData ) {
246
+ tooltipData . tooltip . find ( ".ui-tooltip-content" ) . html ( content ) ;
246
247
return ;
247
248
}
248
249
@@ -261,7 +262,8 @@ return $.widget( "ui.tooltip", {
261
262
}
262
263
}
263
264
264
- tooltip = this . _tooltip ( target ) ;
265
+ tooltipData = this . _tooltip ( target ) ;
266
+ tooltip = tooltipData . tooltip ;
265
267
this . _addDescribedBy ( target , tooltip . attr ( "id" ) ) ;
266
268
tooltip . find ( ".ui-tooltip-content" ) . html ( content ) ;
267
269
@@ -296,8 +298,6 @@ return $.widget( "ui.tooltip", {
296
298
} , this . options . position ) ) ;
297
299
}
298
300
299
- this . hiding = false ;
300
- this . closing = false ;
301
301
tooltip . hide ( ) ;
302
302
303
303
this . _show ( tooltip , this . options . show ) ;
@@ -343,13 +343,21 @@ return $.widget( "ui.tooltip", {
343
343
} ,
344
344
345
345
close : function ( event ) {
346
- var that = this ,
346
+ var tooltip ,
347
+ that = this ,
347
348
target = $ ( event ? event . currentTarget : this . element ) ,
348
- tooltip = this . _find ( target ) ;
349
+ tooltipData = this . _find ( target ) ;
350
+
351
+ // The tooltip may already be closed
352
+ if ( ! tooltipData ) {
353
+ return ;
354
+ }
355
+
356
+ tooltip = tooltipData . tooltip ;
349
357
350
358
// disabling closes the tooltip, so we need to track when we're closing
351
359
// to avoid an infinite loop in case the tooltip becomes disabled on close
352
- if ( this . closing ) {
360
+ if ( tooltipData . closing ) {
353
361
return ;
354
362
}
355
363
@@ -364,12 +372,10 @@ return $.widget( "ui.tooltip", {
364
372
365
373
this . _removeDescribedBy ( target ) ;
366
374
367
- this . hiding = true ;
375
+ tooltipData . hiding = true ;
368
376
tooltip . stop ( true ) ;
369
377
this . _hide ( tooltip , this . options . hide , function ( ) {
370
378
that . _removeTooltip ( $ ( this ) ) ;
371
- this . hiding = false ;
372
- this . closing = false ;
373
379
} ) ;
374
380
375
381
target . removeData ( "ui-tooltip-open" ) ;
@@ -388,10 +394,10 @@ return $.widget( "ui.tooltip", {
388
394
} ) ;
389
395
}
390
396
391
- this . closing = true ;
397
+ tooltipData . closing = true ;
392
398
this . _trigger ( "close" , event , { tooltip : tooltip } ) ;
393
- if ( ! this . hiding ) {
394
- this . closing = false ;
399
+ if ( ! tooltipData . hiding ) {
400
+ tooltipData . closing = false ;
395
401
}
396
402
} ,
397
403
@@ -407,13 +413,16 @@ return $.widget( "ui.tooltip", {
407
413
. appendTo ( tooltip ) ;
408
414
409
415
tooltip . appendTo ( this . document [ 0 ] . body ) ;
410
- this . tooltips [ id ] = element ;
411
- return tooltip ;
416
+
417
+ return this . tooltips [ id ] = {
418
+ element : element ,
419
+ tooltip : tooltip
420
+ } ;
412
421
} ,
413
422
414
423
_find : function ( target ) {
415
424
var id = target . data ( "ui-tooltip-id" ) ;
416
- return id ? $ ( "#" + id ) : $ ( ) ;
425
+ return id ? this . tooltips [ id ] : null ;
417
426
} ,
418
427
419
428
_removeTooltip : function ( tooltip ) {
@@ -425,10 +434,11 @@ return $.widget( "ui.tooltip", {
425
434
var that = this ;
426
435
427
436
// close open tooltips
428
- $ . each ( this . tooltips , function ( id , element ) {
437
+ $ . each ( this . tooltips , function ( id , tooltipData ) {
429
438
// Delegate to close method to handle common cleanup
430
- var event = $ . Event ( "blur" ) ;
431
- event . target = event . currentTarget = element [ 0 ] ;
439
+ var event = $ . Event ( "blur" ) ,
440
+ element = tooltipData . element ;
441
+ event . target = event . currentTarget = element [ 0 ] ;
432
442
that . close ( event , true ) ;
433
443
434
444
// Remove immediately; destroying an open tooltip doesn't use the
0 commit comments