@@ -47,52 +47,40 @@ class MutationBasedRemovalTracker {
47
47
48
48
this . observer = null
49
49
this . inited = false
50
- this . trackedElements = null
51
50
}
52
51
53
52
init ( ) {
54
53
if ( this . inited ) {
55
54
this . unbind ( )
56
55
}
57
-
58
- this . trackedElements = [ ]
56
+ this . inited = true
59
57
60
58
const MutationObserver = getMutationObserverClass ( )
61
- if ( MutationObserver ) {
62
- this . observer = new MutationObserver ( ( ) => {
63
- for ( const element of this . trackedElements ) {
64
- if ( this . isDetached ( element ) && element === this . tooltip . state . currentTarget ) {
59
+ if ( ! MutationObserver ) {
60
+ return
61
+ }
62
+
63
+ this . observer = new MutationObserver ( ( mutations ) => {
64
+ for ( const mutation of mutations ) {
65
+ for ( const element of mutation . removedNodes ) {
66
+ if ( element === this . tooltip . state . currentTarget ) {
65
67
this . tooltip . hideTooltip ( )
68
+ return
66
69
}
67
70
}
68
- } )
69
- this . observer . observe ( window . document , { childList : true , subtree : true } )
70
- }
71
+ }
72
+ } )
71
73
72
- this . inited = true
74
+ this . observer . observe ( window . document , { childList : true , subtree : true } )
73
75
}
74
76
75
77
unbind ( ) {
76
78
if ( this . observer ) {
77
79
this . observer . disconnect ( )
78
80
this . observer = null
79
- this . trackedElements = null
80
81
}
81
82
this . inited = false
82
83
}
83
-
84
- attach ( element ) {
85
- this . trackedElements . push ( element )
86
- }
87
-
88
- // http://stackoverflow.com/a/32726412/7571078
89
- isDetached ( element ) {
90
- if ( element . parentNode === window . document ) {
91
- return false
92
- }
93
- if ( element . parentNode == null ) return true
94
- return this . isDetached ( element . parentNode )
95
- }
96
84
}
97
85
98
86
export default function ( target ) {
@@ -106,7 +94,9 @@ export default function (target) {
106
94
}
107
95
108
96
target . prototype . attachRemovalTracker = function ( element ) {
109
- this . removalTracker . attach ( element )
97
+ if ( this . removalTracker . attach ) {
98
+ this . removalTracker . attach ( element )
99
+ }
110
100
}
111
101
112
102
target . prototype . unbindRemovalTracker = function ( ) {
0 commit comments