@@ -14,7 +14,8 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
14
14
var defaultOptions = {
15
15
placement : 'top' ,
16
16
animation : true ,
17
- popupDelay : 0
17
+ popupDelay : 0 ,
18
+ useContentExp : false
18
19
} ;
19
20
20
21
// Default hide triggers for each show trigger
@@ -65,8 +66,8 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
65
66
* TODO support multiple triggers
66
67
*/
67
68
this . $get = [ '$window' , '$compile' , '$timeout' , '$document' , '$position' , '$interpolate' , function ( $window , $compile , $timeout , $document , $position , $interpolate ) {
68
- return function $tooltip ( type , prefix , defaultTriggerShow ) {
69
- var options = angular . extend ( { } , defaultOptions , globalOptions ) ;
69
+ return function $tooltip ( type , prefix , defaultTriggerShow , options ) {
70
+ options = angular . extend ( { } , defaultOptions , globalOptions , options ) ;
70
71
71
72
/**
72
73
* Returns an object of show and hide triggers.
@@ -98,8 +99,9 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
98
99
var template =
99
100
'<div ' + directiveName + '-popup ' +
100
101
'title="' + startSym + 'title' + endSym + '" ' +
101
- 'content="' + startSym + 'content' + endSym + '" ' +
102
- 'content-exp="contentExp()" ' +
102
+ ( options . useContentExp ?
103
+ 'content-exp="contentExp()" ' :
104
+ 'content="' + startSym + 'content' + endSym + '" ' ) +
103
105
'placement="' + startSym + 'placement' + endSym + '" ' +
104
106
'popup-class="' + startSym + 'popupClass' + endSym + '" ' +
105
107
'animation="animation" ' +
@@ -188,7 +190,7 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
188
190
}
189
191
190
192
// Don't show empty tooltips.
191
- if ( ! ttScope . content ) {
193
+ if ( ! ( options . useContentExp ? ttScope . contentExp ( ) : ttScope . content ) ) {
192
194
return angular . noop ;
193
195
}
194
196
@@ -247,6 +249,14 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
247
249
tooltipLinkedScope . $watch ( function ( ) {
248
250
$timeout ( positionTooltip , 0 , false ) ;
249
251
} ) ;
252
+
253
+ if ( options . useContentExp ) {
254
+ tooltipLinkedScope . $watch ( 'contentExp()' , function ( val ) {
255
+ if ( ! val && ttScope . isOpen ) {
256
+ hide ( ) ;
257
+ }
258
+ } ) ;
259
+ }
250
260
}
251
261
252
262
function removeTooltip ( ) {
@@ -274,13 +284,15 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
274
284
/**
275
285
* Observe the relevant attributes.
276
286
*/
277
- attrs . $observe ( type , function ( val ) {
278
- ttScope . content = val ;
287
+ if ( ! options . useContentExp ) {
288
+ attrs . $observe ( type , function ( val ) {
289
+ ttScope . content = val ;
279
290
280
- if ( ! val && ttScope . isOpen ) {
281
- hide ( ) ;
282
- }
283
- } ) ;
291
+ if ( ! val && ttScope . isOpen ) {
292
+ hide ( ) ;
293
+ }
294
+ } ) ;
295
+ }
284
296
285
297
attrs . $observe ( 'disabled' , function ( val ) {
286
298
if ( val && ttScope . isOpen ) {
@@ -466,14 +478,16 @@ function ($animate , $sce , $compile , $templateRequest) {
466
478
return {
467
479
restrict : 'EA' ,
468
480
replace : true ,
469
- scope : { title : '@' , content : '@ ' , placement : '@' , animation : '&' , isOpen : '&' ,
481
+ scope : { title : '@' , contentExp : '& ' , placement : '@' , animation : '&' , isOpen : '&' ,
470
482
originScope : '&' } ,
471
483
templateUrl : 'template/tooltip/tooltip-template-popup.html'
472
484
} ;
473
485
} )
474
486
475
487
. directive ( 'tooltipTemplate' , [ '$tooltip' , function ( $tooltip ) {
476
- return $tooltip ( 'tooltipTemplate' , 'tooltip' , 'mouseenter' ) ;
488
+ return $tooltip ( 'tooltipTemplate' , 'tooltip' , 'mouseenter' , {
489
+ useContentExp : true
490
+ } ) ;
477
491
} ] )
478
492
479
493
. directive ( 'tooltipHtmlPopup' , function ( ) {
0 commit comments