Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix indentation based on PR suggestion
  • Loading branch information
theangryhobbit committed Apr 1, 2021
commit 2be423e3d7ed77d9ae5a6aff140f225a31fb5d3f
50 changes: 25 additions & 25 deletions assets/js/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,41 @@ const removeActiveClasses = function (ulElement) {
Array.prototype.forEach.call(lis, function(li) {
li.classList.remove('active');
});
}
}

const getChildPosition = function (element) {
var parent = element.parentNode;
var i = 0;
for (var i = 0; i < parent.children.length; i++) {
if (parent.children[i] === element) {
return i;
}
const getChildPosition = function (element) {
var parent = element.parentNode;
var i = 0;
for (var i = 0; i < parent.children.length; i++) {
if (parent.children[i] === element) {
return i;
}

throw new Error('No parent found');
}

throw new Error('No parent found');
}

window.addEventListener('load', function () {
const tabLinks = document.querySelectorAll('ul.tab li a');

Array.prototype.forEach.call(tabLinks, function(link) {
link.addEventListener('click', function (event) {
event.preventDefault();
link.addEventListener('click', function (event) {
event.preventDefault();

liTab = link.parentNode;
ulTab = liTab.parentNode;
position = getChildPosition(liTab);
if (liTab.className.includes('active')) {
return;
}
liTab = link.parentNode;
ulTab = liTab.parentNode;
position = getChildPosition(liTab);
if (liTab.className.includes('active')) {
return;
}

removeActiveClasses(ulTab);
tabContentId = ulTab.getAttribute('data-tab');
tabContentElement = document.getElementById(tabContentId);
removeActiveClasses(tabContentElement);
removeActiveClasses(ulTab);
tabContentId = ulTab.getAttribute('data-tab');
tabContentElement = document.getElementById(tabContentId);
removeActiveClasses(tabContentElement);

tabContentElement.querySelectorAll('li')[position].classList.add('active');
liTab.classList.add('active');
}, false);
tabContentElement.querySelectorAll('li')[position].classList.add('active');
liTab.classList.add('active');
}, false);
});
});