|
82 | 82 | // The MutationObserver watches for when new elements are added to the DOM. |
83 | 83 | var observer = new MutationObserver(function (mutations) { |
84 | 84 | var matches = []; |
85 | | - function push(match) { |
86 | | - matches.push(match); |
87 | | - } |
88 | 85 |
|
89 | 86 | // For each mutation. |
90 | 87 | for (var m = 0; m < mutations.length; m++) { |
|
97 | 94 |
|
98 | 95 | // If the selector is fraternal, query siblings of the mutated node for matches. |
99 | 96 | if (msobserver.isFraternal) |
100 | | - mutations[m].target.parentElement.querySelectorAll(msobserver.selector).forEach(push); |
| 97 | + matches.push.apply(matches, mutations[m].target.parentElement.querySelectorAll(msobserver.selector)); |
101 | 98 | else |
102 | | - mutations[m].target.querySelectorAll(msobserver.selector).forEach(push); |
| 99 | + matches.push.apply(matches, mutations[m].target.querySelectorAll(msobserver.selector)); |
103 | 100 | } |
104 | 101 |
|
105 | 102 | // If this is an childList mutation, then inspect added nodes. |
|
115 | 112 |
|
116 | 113 | // If the selector is fraternal, query siblings for matches. |
117 | 114 | if (msobserver.isFraternal) |
118 | | - mutations[m].addedNodes[n].parentElement.querySelectorAll(msobserver.selector).forEach(push); |
| 115 | + matches.push.apply(matches, mutations[m].addedNodes[n].parentElement.querySelectorAll(msobserver.selector)); |
119 | 116 | else |
120 | | - mutations[m].addedNodes[n].querySelectorAll(msobserver.selector).forEach(push); |
| 117 | + matches.push.apply(matches, mutations[m].addedNodes[n].querySelectorAll(msobserver.selector)); |
121 | 118 | } |
122 | 119 | } |
123 | 120 | } |
124 | 121 |
|
125 | 122 | // For each match, call the callback using jQuery.each() to initialize the element (once only.) |
126 | | - matches.forEach(function(match) { |
127 | | - $(match).each(msobserver.callback); |
128 | | - }); |
| 123 | + for (var i = 0; i < matches.length; i++) |
| 124 | + $(matches[i]).each(msobserver.callback); |
129 | 125 | }); |
130 | 126 |
|
131 | 127 | // Observe the target element. |
|
0 commit comments