mirror of
https://github.com/kevinveenbirkenbach/homepage.veen.world.git
synced 2025-02-24 20:01:53 +01:00
Refactored alternatives and options js
This commit is contained in:
parent
0360c443b7
commit
a0664691e6
@ -52,49 +52,32 @@ function openDynamicPopup(subitem) {
|
|||||||
linkBox.classList.add('d-none');
|
linkBox.classList.add('d-none');
|
||||||
linkHref.href = '#';
|
linkHref.href = '#';
|
||||||
}
|
}
|
||||||
|
function populateSection(sectionId, listId, items, onClickHandler) {
|
||||||
|
const section = document.getElementById(sectionId);
|
||||||
|
const list = document.getElementById(listId);
|
||||||
|
list.innerHTML = '';
|
||||||
|
|
||||||
const alternativesSection = document.getElementById('dynamicAlternativesSection');
|
if (items && items.length > 0) {
|
||||||
const alternativesList = document.getElementById('dynamicAlternativesList');
|
section.classList.remove('d-none');
|
||||||
alternativesList.innerHTML = '';
|
items.forEach(item => {
|
||||||
if (subitem.alternatives && subitem.alternatives.length > 0) {
|
|
||||||
alternativesSection.classList.remove('d-none');
|
|
||||||
subitem.alternatives.forEach(alt => {
|
|
||||||
const listItem = document.createElement('li');
|
const listItem = document.createElement('li');
|
||||||
listItem.classList.add('list-group-item', 'd-flex', 'justify-content-between', 'align-items-center');
|
listItem.classList.add('list-group-item', 'd-flex', 'justify-content-between', 'align-items-center');
|
||||||
listItem.innerHTML = `
|
listItem.innerHTML = `
|
||||||
<span>
|
<span>
|
||||||
<i class="${alt.icon.class}"></i> ${alt.name}
|
<i class="${item.icon.class}"></i> ${item.name}
|
||||||
</span>
|
</span>
|
||||||
<button class="btn btn-outline-secondary btn-sm">Open</button>
|
<button class="btn btn-outline-secondary btn-sm">Open</button>
|
||||||
`;
|
`;
|
||||||
listItem.querySelector('button').addEventListener('click', () => openDynamicPopup(alt));
|
listItem.querySelector('button').addEventListener('click', () => onClickHandler(item));
|
||||||
alternativesList.appendChild(listItem);
|
list.appendChild(listItem);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
alternativesSection.classList.add('d-none');
|
section.classList.add('d-none');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const childrenSection = document.getElementById('dynamicChildrenSection');
|
populateSection('dynamicAlternativesSection', 'dynamicAlternativesList', subitem.alternatives, openDynamicPopup);
|
||||||
const childrenList = document.getElementById('dynamicChildrenList');
|
populateSection('dynamicChildrenSection', 'dynamicChildrenList', subitem.children, openDynamicPopup);
|
||||||
childrenList.innerHTML = '';
|
|
||||||
if (subitem.children && subitem.children.length > 0) {
|
|
||||||
childrenSection.classList.remove('d-none');
|
|
||||||
subitem.children.forEach(child => {
|
|
||||||
const listItem = document.createElement('li');
|
|
||||||
listItem.classList.add('list-group-item', 'd-flex', 'justify-content-between', 'align-items-center');
|
|
||||||
listItem.innerHTML = `
|
|
||||||
<span>
|
|
||||||
<i class="${child.icon.class}"></i> ${child.name}
|
|
||||||
</span>
|
|
||||||
<button class="btn btn-outline-secondary btn-sm">Open</button>
|
|
||||||
`;
|
|
||||||
listItem.querySelector('button').addEventListener('click', () => openDynamicPopup(child));
|
|
||||||
childrenList.appendChild(listItem);
|
|
||||||
});
|
|
||||||
document.querySelector('.modal-body').appendChild(childrenSection);
|
|
||||||
} else {
|
|
||||||
childrenSection.classList.add('d-none');
|
|
||||||
}
|
|
||||||
|
|
||||||
const copyButton = document.getElementById('dynamicCopyButton');
|
const copyButton = document.getElementById('dynamicCopyButton');
|
||||||
copyButton.onclick = () => {
|
copyButton.onclick = () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user