Inloggen voor Cursus: De oerknal van Europa

Cursus: De oerknal van Europa

(function () { function moveOption(select) { if (!select || select.tagName !== 'SELECT') return; const options = Array.from(select.options); // Zoek de optie met lege value (= "Nieuwe deelnemer") const newOption = options.find(option => option.value === ""); if (newOption && select.lastElementChild !== newOption) { select.appendChild(newOption); } } function handleSelect(select) { moveOption(select); // Observeer wijzigingen BINNEN deze select (options die veranderen) const selectObserver = new MutationObserver(() => { moveOption(select); }); selectObserver.observe(select, { childList: true }); } function init(context = document) { const dropdowns = context.querySelectorAll('.js-attendee-relation-element'); dropdowns.forEach(handleSelect); } // Initial load document.addEventListener('DOMContentLoaded', () => init()); // Observer voor dynamische content (nieuwe deelnemers) const observer = new MutationObserver((mutations) => { mutations.forEach(mutation => { mutation.addedNodes.forEach(node => { if (node.nodeType !== 1) return; if (node.matches && node.matches('.js-attendee-relation-element')) { handleSelect(node); } if (node.querySelectorAll) { init(node); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })();