Skip to content

Commit

Permalink
fix(browser support): Replacing instances of forEach with regular for…
Browse files Browse the repository at this point in the history
… loops for better browser suppo
  • Loading branch information
Portugal, Marcelo authored and Portugal, Marcelo committed Nov 21, 2016
1 parent 445b999 commit 20b9d7f
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 36 deletions.
34 changes: 22 additions & 12 deletions example/example-report.html
Original file line number Diff line number Diff line change
Expand Up @@ -1365,19 +1365,22 @@ <h3 class="page-header">All Rules</h3>
}

// accordion
lintResults.forEach(function setUpAccordion(result) {
for(var i = 0; i < lintResults.length; i++) {
var result = lintResults[i];

result.addEventListener('click', handleResultClick);
result.addEventListener('keydown', function onKeydown(event) {
if (event.which === 13) {
handleResultClick.apply(this);
}
});
});
}

function handleResultClick() {
if (!this.className.includes('bg-success')) {
toggleAccordion.apply(this);
}
// TODO: Comment this back in when I can support it in example page
// window.location.href = '#' + this.getAttribute('id');
}

Expand All @@ -1389,30 +1392,37 @@ <h3 class="page-header">All Rules</h3>
}

// filter
filters.forEach(function addChangeListener(filter) {
filter.addEventListener('change', filterResults);
});
for(var j = 0; j < filters.length; j++) {
filters[j].addEventListener('change', filterResults);
}

function filterResults() {
var filterValue = document.querySelector('input[name="filters"]:checked').value;

lintResults.forEach(function filterByClass(result) {

for(var i = 0; i < lintResults.length; i++) {
var result = lintResults[i];

result.style.display = result.className.includes(filterValue) ? 'table-row' : 'none';
});
}
}

// tabs
tabs.forEach(function addClickListener(tab) {
tab.addEventListener('click', activateTab);
});
for(var k = 0; k < lintResults.length; k++) {
tabs[k].addEventListener('click', activateTab);
}

function activateTab() {
var currentTabs = document.querySelectorAll(this.getAttribute('data-parent') + ' .nav-tabs > li'),
tabPanes = document.querySelectorAll(this.getAttribute('data-parent') + ' .tab-pane'),
tabContent = document.getElementById(this.getAttribute('data-content'));

currentTabs.forEach(disableTabs);
tabPanes.forEach(hideElement);
for(var i = 0; i < currentTabs.length; i++) {
disableTabs(currentTabs[i]);
}
for(var j = 0; j < tabPanes.length; j++) {
hideElement(tabPanes[j]);
}
this.parentNode.className = 'active';
toggleDisplay(tabContent);
}
Expand Down
34 changes: 22 additions & 12 deletions example/success-report.html
Original file line number Diff line number Diff line change
Expand Up @@ -387,19 +387,22 @@ <h2 class="page-header">Details</h2>
}

// accordion
lintResults.forEach(function setUpAccordion(result) {
for(var i = 0; i < lintResults.length; i++) {
var result = lintResults[i];

result.addEventListener('click', handleResultClick);
result.addEventListener('keydown', function onKeydown(event) {
if (event.which === 13) {
handleResultClick.apply(this);
}
});
});
}

function handleResultClick() {
if (!this.className.includes('bg-success')) {
toggleAccordion.apply(this);
}
// TODO: Comment this back in when I can support it in example page
// window.location.href = '#' + this.getAttribute('id');
}

Expand All @@ -411,30 +414,37 @@ <h2 class="page-header">Details</h2>
}

// filter
filters.forEach(function addChangeListener(filter) {
filter.addEventListener('change', filterResults);
});
for(var j = 0; j < filters.length; j++) {
filters[j].addEventListener('change', filterResults);
}

function filterResults() {
var filterValue = document.querySelector('input[name="filters"]:checked').value;

lintResults.forEach(function filterByClass(result) {

for(var i = 0; i < lintResults.length; i++) {
var result = lintResults[i];

result.style.display = result.className.includes(filterValue) ? 'table-row' : 'none';
});
}
}

// tabs
tabs.forEach(function addClickListener(tab) {
tab.addEventListener('click', activateTab);
});
for(var k = 0; k < lintResults.length; k++) {
tabs[k].addEventListener('click', activateTab);
}

function activateTab() {
var currentTabs = document.querySelectorAll(this.getAttribute('data-parent') + ' .nav-tabs > li'),
tabPanes = document.querySelectorAll(this.getAttribute('data-parent') + ' .tab-pane'),
tabContent = document.getElementById(this.getAttribute('data-content'));

currentTabs.forEach(disableTabs);
tabPanes.forEach(hideElement);
for(var i = 0; i < currentTabs.length; i++) {
disableTabs(currentTabs[i]);
}
for(var j = 0; j < tabPanes.length; j++) {
hideElement(tabPanes[j]);
}
this.parentNode.className = 'active';
toggleDisplay(tabContent);
}
Expand Down
34 changes: 22 additions & 12 deletions lib/helpers/scripts.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,22 @@
}

// accordion
lintResults.forEach(function setUpAccordion(result) {
for(var i = 0; i < lintResults.length; i++) {
var result = lintResults[i];

result.addEventListener('click', handleResultClick);
result.addEventListener('keydown', function onKeydown(event) {
if (event.which === 13) {
handleResultClick.apply(this);
}
});
});
}

function handleResultClick() {
if (!this.className.includes('bg-success')) {
toggleAccordion.apply(this);
}
// TODO: Comment this back in when I can support it in example page
// window.location.href = '#' + this.getAttribute('id');
}

Expand All @@ -37,30 +40,37 @@
}

// filter
filters.forEach(function addChangeListener(filter) {
filter.addEventListener('change', filterResults);
});
for(var j = 0; j < filters.length; j++) {
filters[j].addEventListener('change', filterResults);
}

function filterResults() {
var filterValue = document.querySelector('input[name="filters"]:checked').value;

lintResults.forEach(function filterByClass(result) {

for(var i = 0; i < lintResults.length; i++) {
var result = lintResults[i];

result.style.display = result.className.includes(filterValue) ? 'table-row' : 'none';
});
}
}

// tabs
tabs.forEach(function addClickListener(tab) {
tab.addEventListener('click', activateTab);
});
for(var k = 0; k < lintResults.length; k++) {
tabs[k].addEventListener('click', activateTab);
}

function activateTab() {
var currentTabs = document.querySelectorAll(this.getAttribute('data-parent') + ' .nav-tabs > li'),
tabPanes = document.querySelectorAll(this.getAttribute('data-parent') + ' .tab-pane'),
tabContent = document.getElementById(this.getAttribute('data-content'));

currentTabs.forEach(disableTabs);
tabPanes.forEach(hideElement);
for(var i = 0; i < currentTabs.length; i++) {
disableTabs(currentTabs[i]);
}
for(var j = 0; j < tabPanes.length; j++) {
hideElement(tabPanes[j]);
}
this.parentNode.className = 'active';
toggleDisplay(tabContent);
}
Expand Down

0 comments on commit 20b9d7f

Please sign in to comment.