@@ -92,19 +92,42 @@ function MdTooltipDirective($timeout, $window, $$rAF, $document, $mdUtil, $mdThe
92
92
content . css ( 'transform-origin' , origin ) ;
93
93
}
94
94
95
+ function onVisibleChanged ( isVisible ) {
96
+ if ( isVisible ) showTooltip ( ) ;
97
+ else hideTooltip ( ) ;
98
+ }
99
+
95
100
function configureWatchers ( ) {
96
101
scope . $on ( '$destroy' , function ( ) {
97
102
scope . visible = false ;
98
103
element . remove ( ) ;
99
104
angular . element ( $window ) . off ( 'resize' , debouncedOnResize ) ;
100
105
} ) ;
101
106
102
- scope . $watch ( 'visible' , function ( isVisible ) {
103
- if ( isVisible ) showTooltip ( ) ;
104
- else hideTooltip ( ) ;
105
- } ) ;
107
+ if ( element [ 0 ] && 'MutationObserver' in $window ) {
108
+ var attributeObserver = new MutationObserver ( function ( mutations ) {
109
+ mutations
110
+ . forEach ( function ( mutation ) {
111
+ if ( mutation . attributeName === 'md-visible' ) {
112
+ if ( ! scope . visibleWatcher )
113
+ scope . visibleWatcher = scope . $watch ( 'visible' , onVisibleChanged ) ;
114
+ }
115
+ if ( mutation . attributeName === 'md-direction' ) {
116
+ updatePosition ( scope . direction ) ;
117
+ }
118
+ } ) ;
119
+ } ) ;
120
+
121
+ attributeObserver . observe ( element [ 0 ] , { attributes : true } ) ;
122
+
123
+ if ( attr . hasOwnProperty ( 'mdVisible' ) ) // build watcher only if mdVisible is being used
124
+ scope . visibleWatcher = scope . $watch ( 'visible' , onVisibleChanged ) ;
106
125
107
- scope . $watch ( 'direction' , updatePosition ) ;
126
+ }
127
+ else { // MutationObserver not supported
128
+ scope . visibleWatcher = scope . $watch ( 'visible' , onVisibleChanged ) ;
129
+ scope . $watch ( 'direction' , updatePosition ) ;
130
+ }
108
131
}
109
132
110
133
function addAriaLabel ( ) {
@@ -194,9 +217,15 @@ function MdTooltipDirective($timeout, $window, $$rAF, $document, $mdUtil, $mdThe
194
217
$timeout ( function ( ) {
195
218
scope . visible = setVisible . value ;
196
219
setVisible . queued = false ;
220
+ if ( ! scope . visibleWatcher )
221
+ onVisibleChanged ( scope . visible ) ;
197
222
} , scope . delay ) ;
198
223
} else {
199
- $mdUtil . nextTick ( function ( ) { scope . visible = false ; } ) ;
224
+ $mdUtil . nextTick ( function ( ) {
225
+ scope . visible = false ;
226
+ if ( ! scope . visibleWatcher )
227
+ onVisibleChanged ( false ) ;
228
+ } ) ;
200
229
}
201
230
}
202
231
}
0 commit comments