@@ -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 ;
@@ -137,7 +140,7 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
137
140
if ( scope . tt_popupDelay ) {
138
141
popupTimeout = $timeout ( show , scope . tt_popupDelay ) ;
139
142
} else {
140
- scope . $apply ( show ) ;
143
+ show ( ) ;
141
144
}
142
145
}
143
146
@@ -159,6 +162,9 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
159
162
return ;
160
163
}
161
164
165
+ createTooltip ( ) ;
166
+ scope . $digest ( ) ;
167
+
162
168
// If there is a pending remove transition, we must cancel it, lest the
163
169
// tooltip be mysteriously removed.
164
170
if ( transitionTimeout ) {
@@ -220,6 +226,9 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
220
226
221
227
// And show the tooltip.
222
228
scope . tt_isOpen = true ;
229
+
230
+ // Apply changes
231
+ scope . $digest ( ) ;
223
232
}
224
233
225
234
// Hide the tooltip popup element.
@@ -234,11 +243,24 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
234
243
// need to wait for it to expire beforehand.
235
244
// FIXME: this is a placeholder for a port of the transitions library.
236
245
if ( scope . tt_animation ) {
237
- transitionTimeout = $timeout ( function ( ) {
238
- tooltip . remove ( ) ;
239
- } , 500 ) ;
246
+ transitionTimeout = $timeout ( removeTooltip , 500 ) ;
240
247
} else {
248
+ removeTooltip ( ) ;
249
+ }
250
+ }
251
+
252
+ function createTooltip ( ) {
253
+ // There can only be one tooltip element per directive shown at once.
254
+ if ( tooltip ) {
255
+ removeTooltip ( ) ;
256
+ }
257
+ tooltip = tooltipLinker ( scope , function ( ) { } ) ;
258
+ }
259
+
260
+ function removeTooltip ( ) {
261
+ if ( tooltip ) {
241
262
tooltip . remove ( ) ;
263
+ tooltip = null ;
242
264
}
243
265
}
244
266
@@ -313,10 +335,9 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
313
335
$timeout . cancel ( transitionTimeout ) ;
314
336
$timeout . cancel ( popupTimeout ) ;
315
337
unregisterTriggers ( ) ;
316
- tooltip . remove ( ) ;
317
- tooltip . unbind ( ) ;
318
- tooltip = null ;
338
+ removeTooltip ( ) ;
319
339
} ) ;
340
+ } ;
320
341
}
321
342
} ;
322
343
} ;
0 commit comments