@@ -108,8 +108,11 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
108
108
return {
109
109
restrict : 'EA' ,
110
110
scope : true ,
111
- link : function link ( scope , element , attrs ) {
112
- var tooltip = $compile ( template ) ( scope ) ;
111
+ compile : function ( tElem , tAttrs ) {
112
+ var tooltipLinker = $compile ( template ) ;
113
+
114
+ return function link ( scope , element , attrs ) {
115
+ var tooltip ;
113
116
var transitionTimeout ;
114
117
var popupTimeout ;
115
118
var appendToBody = angular . isDefined ( options . appendToBody ) ? options . appendToBody : false ;
@@ -184,10 +187,10 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
184
187
return ;
185
188
}
186
189
if ( scope . tt_popupDelay ) {
187
- popupTimeout = $timeout ( show , scope . tt_popupDelay ) ;
190
+ popupTimeout = $timeout ( show , scope . tt_popupDelay , false ) ;
188
191
popupTimeout . then ( function ( reposition ) { reposition ( ) ; } ) ;
189
192
} else {
190
- scope . $apply ( show ) ( ) ;
193
+ show ( ) ( ) ;
191
194
}
192
195
}
193
196
@@ -206,6 +209,8 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
206
209
return angular . noop ;
207
210
}
208
211
212
+ createTooltip ( ) ;
213
+
209
214
// If there is a pending remove transition, we must cancel it, lest the
210
215
// tooltip be mysteriously removed.
211
216
if ( transitionTimeout ) {
@@ -227,6 +232,7 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
227
232
228
233
// And show the tooltip.
229
234
scope . tt_isOpen = true ;
235
+ scope . $digest ( ) ; // digest required as $apply is not called
230
236
231
237
// Return positioning function as promise callback for correct
232
238
// positioning after draw.
@@ -245,11 +251,27 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
245
251
// need to wait for it to expire beforehand.
246
252
// FIXME: this is a placeholder for a port of the transitions library.
247
253
if ( scope . tt_animation ) {
248
- transitionTimeout = $timeout ( function ( ) {
249
- tooltip . remove ( ) ;
250
- } , 500 ) ;
254
+ transitionTimeout = $timeout ( removeTooltip , 500 ) ;
251
255
} else {
256
+ removeTooltip ( ) ;
257
+ }
258
+ }
259
+
260
+ function createTooltip ( ) {
261
+ // There can only be one tooltip element per directive shown at once.
262
+ if ( tooltip ) {
263
+ removeTooltip ( ) ;
264
+ }
265
+ tooltip = tooltipLinker ( scope , function ( ) { } ) ;
266
+
267
+ // Get contents rendered into the tooltip
268
+ scope . $digest ( ) ;
269
+ }
270
+
271
+ function removeTooltip ( ) {
272
+ if ( tooltip ) {
252
273
tooltip . remove ( ) ;
274
+ tooltip = null ;
253
275
}
254
276
}
255
277
@@ -322,10 +344,9 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
322
344
$timeout . cancel ( transitionTimeout ) ;
323
345
$timeout . cancel ( popupTimeout ) ;
324
346
unregisterTriggers ( ) ;
325
- tooltip . remove ( ) ;
326
- tooltip . unbind ( ) ;
327
- tooltip = null ;
347
+ removeTooltip ( ) ;
328
348
} ) ;
349
+ } ;
329
350
}
330
351
} ;
331
352
} ;
0 commit comments