@@ -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 } ) ;
106
122
107
- scope . $watch ( 'direction' , updatePosition ) ;
123
+ if ( attr . hasOwnProperty ( 'mdVisible' ) ) // build watcher only if mdVisible is being used
124
+ scope . visibleWatcher = scope . $watch ( 'visible' , onVisibleChanged ) ;
125
+
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 ( ) {
0 commit comments