(function() { const observeSelector = '.js-onscreen'; // TODO - will the form ID ever change? const observedNodes = document.querySelectorAll(observeSelector); let observedCount = 0; let observedTotal = !!observeSelector ? observedNodes.length : 0; window.addEventListener('DOMContentLoaded', event => { // TODO this selector needs to be robuts const enquiryForm = document.querySelector('#wpcf7-f1041-o1 > form'); const intersectionSupport = !!window.IntersectionObserver; function updateObservedCount() { observedCount++; if (observedCount >= observedTotal) { document.body.classList.add('observe-done'); } } function onScreenHandler(entries) { entries.forEach(entry => { if (entry.intersectionRatio > 0) { entry.target.classList.add('is-showing', 'has-shown'); } else { entry.target.classList.remove('is-showing'); } }); } if (enquiryForm) { enquiryForm.action = '__URL__'; } document.body.classList.add('rwavw-custom'); observedNodes.forEach(el => { if (intersectionSupport) { const options = { rootMargin: '0px', threshold: [0, 1], }; const observer = new IntersectionObserver(onScreenHandler, options); observer.observe(el); el.classList.add('is-observed'); } updateObservedCount(); }); }); })();