@@ -15,7 +15,7 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s
15
15
placement : 'top' ,
16
16
animation : true ,
17
17
popupDelay : 0 ,
18
- popupCloseDelay : 500 ,
18
+ popupCloseDelay : 0 ,
19
19
useContentExp : false
20
20
} ;
21
21
@@ -135,7 +135,8 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s
135
135
var tooltip ;
136
136
var tooltipLinkedScope ;
137
137
var transitionTimeout ;
138
- var popupTimeout ;
138
+ var showTimeout ;
139
+ var hideTimeout ;
139
140
var positionTimeout ;
140
141
var appendToBody = angular . isDefined ( options . appendToBody ) ? options . appendToBody : false ;
141
142
var triggers = getTriggers ( undefined ) ;
@@ -196,27 +197,35 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s
196
197
if ( ttScope . popupDelay ) {
197
198
// Do nothing if the tooltip was already scheduled to pop-up.
198
199
// This happens if show is triggered multiple times before any hide is triggered.
199
- if ( ! popupTimeout ) {
200
- popupTimeout = $timeout ( show , ttScope . popupDelay , false ) ;
200
+ if ( ! showTimeout ) {
201
+ showTimeout = $timeout ( show , ttScope . popupDelay , false ) ;
201
202
}
202
203
} else {
203
204
show ( ) ;
204
205
}
205
206
}
206
207
207
208
function hideTooltipBind ( ) {
208
- hide ( ) ;
209
+ if ( ttScope . popupCloseDelay ) {
210
+ hideTimeout = $timeout ( hide , ttScope . popupCloseDelay , false ) ;
211
+ } else {
212
+ hide ( ) ;
213
+ }
209
214
}
210
215
211
216
// Show the tooltip popup element.
212
217
function show ( ) {
213
- if ( popupTimeout ) {
214
- $timeout . cancel ( popupTimeout ) ;
215
- popupTimeout = null ;
218
+ if ( showTimeout ) {
219
+ $timeout . cancel ( showTimeout ) ;
220
+ showTimeout = null ;
216
221
}
217
222
218
223
// If there is a pending remove transition, we must cancel it, lest the
219
224
// tooltip be mysteriously removed.
225
+ if ( hideTimeout ) {
226
+ $timeout . cancel ( hideTimeout ) ;
227
+ hideTimeout = null ;
228
+ }
220
229
if ( transitionTimeout ) {
221
230
$timeout . cancel ( transitionTimeout ) ;
222
231
transitionTimeout = null ;
@@ -232,10 +241,7 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s
232
241
// And show the tooltip.
233
242
ttScope . $evalAsync ( function ( ) {
234
243
ttScope . isOpen = true ;
235
- if ( isOpenParse && angular . isFunction ( isOpenParse . assign ) ) {
236
- isOpenParse . assign ( ttScope . origScope , ttScope . isOpen ) ;
237
- }
238
-
244
+ assignIsOpen ( true ) ;
239
245
positionTooltip ( ) ;
240
246
} ) ;
241
247
}
@@ -246,31 +252,33 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s
246
252
return ;
247
253
}
248
254
255
+ //if tooltip is going to be shown after delay, we must cancel this
256
+ if ( showTimeout ) {
257
+ $timeout . cancel ( showTimeout ) ;
258
+ showTimeout = null ;
259
+ }
260
+
261
+ if ( positionTimeout ) {
262
+ $timeout . cancel ( positionTimeout ) ;
263
+ positionTimeout = null ;
264
+ }
265
+
249
266
// First things first: we don't show it anymore.
250
267
ttScope . $evalAsync ( function ( ) {
251
268
ttScope . isOpen = false ;
252
- if ( isOpenParse && angular . isFunction ( isOpenParse . assign ) ) {
253
- isOpenParse . assign ( ttScope . origScope , ttScope . isOpen ) ;
269
+ assignIsOpen ( false ) ;
270
+ // And now we remove it from the DOM. However, if we have animation, we
271
+ // need to wait for it to expire beforehand.
272
+ // FIXME: this is a placeholder for a port of the transitions library.
273
+ // The fade transition in TWBS is 150ms.
274
+ if ( ttScope . animation ) {
275
+ if ( ! transitionTimeout ) {
276
+ transitionTimeout = $timeout ( removeTooltip , 150 , false ) ;
277
+ }
278
+ } else {
279
+ removeTooltip ( ) ;
254
280
}
255
281
} ) ;
256
-
257
- //if tooltip is going to be shown after delay, we must cancel this
258
- $timeout . cancel ( popupTimeout ) ;
259
- popupTimeout = null ;
260
-
261
- $timeout . cancel ( positionTimeout ) ;
262
- positionTimeout = null ;
263
-
264
- // And now we remove it from the DOM. However, if we have animation, we
265
- // need to wait for it to expire beforehand.
266
- // FIXME: this is a placeholder for a port of the transitions library.
267
- if ( ttScope . animation ) {
268
- if ( ! transitionTimeout ) {
269
- transitionTimeout = $timeout ( removeTooltip , ttScope . popupCloseDelay ) ;
270
- }
271
- } else {
272
- removeTooltip ( ) ;
273
- }
274
282
}
275
283
276
284
function createTooltip ( ) {
@@ -327,6 +335,12 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s
327
335
ttScope . popupCloseDelay = ! isNaN ( closeDelay ) ? closeDelay : options . popupCloseDelay ;
328
336
}
329
337
338
+ function assignIsOpen ( isOpen ) {
339
+ if ( isOpenParse && angular . isFunction ( isOpenParse . assign ) ) {
340
+ isOpenParse . assign ( scope , isOpen ) ;
341
+ }
342
+ }
343
+
330
344
ttScope . contentExp = function ( ) {
331
345
return ttScope . content ;
332
346
} ;
@@ -335,9 +349,9 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s
335
349
* Observe the relevant attributes.
336
350
*/
337
351
attrs . $observe ( 'disabled' , function ( val ) {
338
- if ( popupTimeout && val ) {
339
- $timeout . cancel ( popupTimeout ) ;
340
- popupTimeout = null ;
352
+ if ( showTimeout && val ) {
353
+ $timeout . cancel ( showTimeout ) ;
354
+ showTimeout = null ;
341
355
}
342
356
343
357
if ( val && ttScope . isOpen ) {
@@ -482,7 +496,8 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s
482
496
// Make sure tooltip is destroyed and removed.
483
497
scope . $on ( '$destroy' , function onDestroyTooltip ( ) {
484
498
$timeout . cancel ( transitionTimeout ) ;
485
- $timeout . cancel ( popupTimeout ) ;
499
+ $timeout . cancel ( showTimeout ) ;
500
+ $timeout . cancel ( hideTimeout ) ;
486
501
$timeout . cancel ( positionTimeout ) ;
487
502
unregisterTriggers ( ) ;
488
503
removeTooltip ( ) ;
0 commit comments