let dropdownOpen = false; const widgetContainer = document.querySelector(".trustpilot__widget"); let trustpilotFrame = null; let isTrustPilotOnThisPage = document.querySelector(".trustpilot__bloc"); if (isTrustPilotOnThisPage) { // Resize the iframe depends on the global width function resizeWidget() { let screenWidth = window.innerWidth if (screenWidth < 1145 && dropdownOpen == false) { closeDropDown() } else if (screenWidth >= 1145) { closeDropDown() widgetContainer.style.height = "270px" } } const maxAttempts = 10 let attempt = 0 function iframeLoaded() { trustpilotFrame = document.querySelector('iframe[title="Customer reviews powered by Trustpilot"]'); if (trustpilotFrame) { trustpilotFrame.style.height = "400px" //We are modifying the height at the start to avoid problems in mobile resizeWidget(); } else if (attempt < maxAttempts) { setTimeout(function () { attempt += 1 iframeLoaded() }, 200); } else { console.log("Retry limit reached, iframe not found") } } window.addEventListener('resize', resizeWidget) document.addEventListener('DOMContentLoaded', function () { iframeLoaded(); }); const arrow = document.querySelector(".trustpilot__arrow"); arrow.addEventListener('click', function () { if (dropdownOpen == false) { openDropDown() } else { closeDropDown() } }) function closeDropDown() { widgetContainer.style.height = '200px'; dropdownOpen = false; arrow.style.transform = "rotate(270deg)" } function openDropDown() { widgetContainer.style.height = '360px'; dropdownOpen = true; arrow.style.transform = "rotate(90deg)" } }