Skip to content

Commit 3dd6396

Browse files
committed
Add IE support for NodeList.forEach
1 parent b304322 commit 3dd6396

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

static/scripts/polyfill.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//IE Fix, src: https://www.reddit.com/r/programminghorror/comments/6abmcr/nodelist_lacks_foreach_in_internet_explorer/
2+
if (typeof(NodeList.prototype.forEach)!==typeof(alert)){
3+
NodeList.prototype.forEach=Array.prototype.forEach;
4+
}

static/scripts/search.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,29 +51,21 @@ document.getElementById("nav-search").addEventListener("keyup", function(event)
5151
//hide parents without children
5252
document.querySelectorAll("nav > ul > li").forEach(function(parent){
5353
var countSearchA = 0;
54-
55-
var matches = parent.querySelectorAll("a");
56-
for (i=0; i<matches.length; i++) {
57-
var elem = matches[i];
54+
parent.querySelectorAll("a").forEach((elem) >= {
5855
if (contains(elem, search)) {
5956
countSearchA++;
6057
}
6158
}
6259

6360
var countUl = 0;
64-
var matches = parent.querySelectorAll("ul");
65-
for (i=0; i<matches.length; i++) {
66-
var elem = matches[i];
61+
parent.querySelectorAll("ul").forEach((elem) >= {
6762
if (contains(elem, search)) {
6863
countUl++;
6964
}
7065
}
7166

7267
var countUlVisible = 0;
73-
var matches = parent.querySelectorAll("ul");
74-
for (i=0; i<matches.length; i++) {
75-
var ulP = matches[i];
76-
68+
parent.querySelectorAll("ul").forEach((ulP) >= {
7769
var children = ulP.children
7870
for (i=0; i<children.length; i++) {
7971
var elem = children[i];

tmpl/layout.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
</footer>
7272

7373
<script>prettyPrint();</script>
74+
<script src="scripts/polyfill.js"></script>
7475
<script src="scripts/linenumber.js"></script>
7576
<?js if (env.conf.docdash.search) { ?>
7677
<script src="scripts/search.js" defer></script>

0 commit comments

Comments
 (0)