-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
53 lines (45 loc) · 1.87 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
let settings = {
'btnsClass': "info-header-tab", // Class name of control elements
'btnsParentClass': "info-header", // Parent of control elements
'tabsClass': "info-tabcontent", // Tabs, controlled by control elements
'showClass': "show", // Class that shows a tab
'hideClass': "hide" // Class that hides a tab
};
setClickSettings(settings);
function setClickSettings(settingsObj) {
let ctrlBtnClass = settingsObj.btnsClass,
ctrlBtnParent = settingsObj.btnsParentClass,
tabsClass = settingsObj.tabsClass,
show = settingsObj.showClass,
hide = settingsObj.hideClass;
window.addEventListener("DOMContentLoaded", ()=>{
let tab = document.querySelectorAll("." + ctrlBtnClass),
info = document.querySelector("." + ctrlBtnParent),
tabContent = document.querySelectorAll("." + tabsClass);
function hideTabContent(a) {
for (let i = a; i < tabContent.length; i++) {
tabContent[i].classList.remove(show);
tabContent[i].classList.add(hide);
}
}
hideTabContent(1);
function showTabContent(b) {
if (tabContent[b].classList.contains(hide)) {
tabContent[b].classList.remove(hide);
tabContent[b].classList.add(show);
}
}
info.addEventListener("click", (event)=>{
let target = event.target;
if (event.target && target.classList.contains(ctrlBtnClass)) {
for (let i = 0; i < tab.length; i++) {
if (target == tab[i]) {
hideTabContent(0);
showTabContent(i);
break;
}
}
}
});
});
}