@@ -6,38 +6,49 @@ angular
6
6
* @private
7
7
*
8
8
* @param $mdUtil
9
+ * @param $window
9
10
* @returns {{require: string, link: link} }
10
11
* @constructor
11
- *
12
+ *
12
13
* @ngInject
13
14
*/
14
- function MdTabsDummyWrapper ( $mdUtil ) {
15
+ function MdTabsDummyWrapper ( $mdUtil , $window ) {
15
16
return {
16
17
require : '^?mdTabs' ,
17
18
link : function link ( scope , element , attr , ctrl ) {
18
19
if ( ! ctrl ) return ;
19
20
20
- var observer = new MutationObserver ( function ( mutations ) {
21
+ var observer ;
22
+ var disconnect ;
23
+
24
+ var mutationCallback = function ( ) {
21
25
ctrl . updatePagination ( ) ;
22
26
ctrl . updateInkBarStyles ( ) ;
23
- } ) ;
24
-
25
- var config = {
26
- childList : true ,
27
- subtree : true ,
28
- // Per https://bugzilla.mozilla.org/show_bug.cgi?id=1138368, browsers will not fire
29
- // the childList mutation, once a <span> element's innerText changes.
30
- // The characterData of the <span> element will change.
31
- characterData : true
32
27
} ;
33
28
34
- observer . observe ( element [ 0 ] , config ) ;
29
+ if ( 'MutationObserver' in $window ) {
30
+ var config = {
31
+ childList : true ,
32
+ subtree : true ,
33
+ // Per https://bugzilla.mozilla.org/show_bug.cgi?id=1138368, browsers will not fire
34
+ // the childList mutation, once a <span> element's innerText changes.
35
+ // The characterData of the <span> element will change.
36
+ characterData : true
37
+ } ;
38
+
39
+ observer = new MutationObserver ( mutationCallback ) ;
40
+ observer . observe ( element [ 0 ] , config ) ;
41
+ disconnect = observer . disconnect . bind ( observer ) ;
42
+ } else {
43
+ var debounced = $mdUtil . debounce ( mutationCallback , 15 , null , false ) ;
44
+
45
+ element . on ( 'DOMSubtreeModified' , debounced ) ;
46
+ disconnect = element . off . bind ( element , 'DOMSubtreeModified' , debounced ) ;
47
+ }
35
48
36
49
// Disconnect the observer
37
50
scope . $on ( '$destroy' , function ( ) {
38
- if ( observer ) {
39
- observer . disconnect ( ) ;
40
- }
51
+ disconnect ( ) ;
41
52
} ) ;
42
53
}
43
54
} ;
0 commit comments