Skip to content

Commit 16342ab

Browse files
author
Дэмиен Безбородов
authored
Merge pull request #28 from pie6k/feature/remove-foreach
Resolve .forEach() Compatibility Issues (feature/remove-foreach)
2 parents 53df365 + 0c8ce97 commit 16342ab

2 files changed

Lines changed: 7 additions & 11 deletions

File tree

jquery.initialize.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,6 @@
8282
// The MutationObserver watches for when new elements are added to the DOM.
8383
var observer = new MutationObserver(function (mutations) {
8484
var matches = [];
85-
function push(match) {
86-
matches.push(match);
87-
}
8885

8986
// For each mutation.
9087
for (var m = 0; m < mutations.length; m++) {
@@ -97,9 +94,9 @@
9794

9895
// If the selector is fraternal, query siblings of the mutated node for matches.
9996
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));
10198
else
102-
mutations[m].target.querySelectorAll(msobserver.selector).forEach(push);
99+
matches.push.apply(matches, mutations[m].target.querySelectorAll(msobserver.selector));
103100
}
104101

105102
// If this is an childList mutation, then inspect added nodes.
@@ -115,17 +112,16 @@
115112

116113
// If the selector is fraternal, query siblings for matches.
117114
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));
119116
else
120-
mutations[m].addedNodes[n].querySelectorAll(msobserver.selector).forEach(push);
117+
matches.push.apply(matches, mutations[m].addedNodes[n].querySelectorAll(msobserver.selector));
121118
}
122119
}
123120
}
124121

125122
// 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);
129125
});
130126

131127
// Observe the target element.

jquery.initialize.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)