Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit bd70022

Browse files
j3skihansl
authored andcommitted
fix(tabs): ie10 MutationObserver issue (#9397)
1 parent b11441c commit bd70022

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

src/components/tabs/js/tabsDummyWrapperDirective.js

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,49 @@ angular
66
* @private
77
*
88
* @param $mdUtil
9+
* @param $window
910
* @returns {{require: string, link: link}}
1011
* @constructor
11-
*
12+
*
1213
* @ngInject
1314
*/
14-
function MdTabsDummyWrapper ($mdUtil) {
15+
function MdTabsDummyWrapper ($mdUtil, $window) {
1516
return {
1617
require: '^?mdTabs',
1718
link: function link (scope, element, attr, ctrl) {
1819
if (!ctrl) return;
1920

20-
var observer = new MutationObserver(function(mutations) {
21+
var observer;
22+
var disconnect;
23+
24+
var mutationCallback = function() {
2125
ctrl.updatePagination();
2226
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
3227
};
3328

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+
}
3548

3649
// Disconnect the observer
3750
scope.$on('$destroy', function() {
38-
if (observer) {
39-
observer.disconnect();
40-
}
51+
disconnect();
4152
});
4253
}
4354
};

0 commit comments

Comments
 (0)