Greetings,
I've made a small customisation regarding using the search part of the site as two states, one for not logged in users ( normal search functionality with a search icon buton , and other one for logged in users with a different icon and a different module in search position ) I managed to check and change the icon for logged in and not logged in users and change the modules in search position, BUT ... the script made that should trigger the click that open the search pop-up lost it ... could you take a look and advice about my script to fix this issue ? <script>
document.addEventListener("DOMContentLoaded", function () {
function updateIcon(attempts = 10) {
const icon = document.querySelector("#gkSearch .fa-search, #gkSearch .fa-pen");
if (!icon) {
console.log(⛔ Icon not found (retries left: ${attempts})`);
if (attempts > 0) setTimeout(() => updateIcon(attempts - 1), 100);
return;
}
console.log("✅ Icon found:", icon);
const isLoggedIn = document.body.classList.contains("logged-in");
icon.className = "fa"; // reset safely
icon.classList.add(isLoggedIn ? "fa-pen" : "fa-search", "flashing-icon");
icon.style.visibility = "visible";
bindPopupClick(); // hook popup click once icon is ready
}
function bindPopupClick() {
const $ = jQuery;
const $trigger = $('#gkSearch');
const $popup = $('#gkPopupSearch');
const $overlay = $('#gkOverlay');
if ($trigger.length && $popup.length && $overlay.length) {
console.log(" Binding popup opener to #gkSearch");
$trigger.off('click.gkPopup').on('click.gkPopup', function (e) {
e.preventDefault();
e.stopPropagation();
$overlay.css({ display: 'block', opacity: 0 });
$popup.css({ display: 'block', opacity: 0, top: '40%' });
setTimeout(function () {
$overlay.css({ opacity: 0.9, 'background-color': '#222' });
$popup.css({ opacity: 1 });
$popup.find('.search-query').focus();
}, 50);
});
} else {
console.warn(' Missing elements for popup:', {
gkSearch: $trigger.length,
gkPopupSearch: $popup.length,
gkOverlay: $overlay.length
});
}
}
updateIcon();
});
</script>
' - the script loads into a custom module in debug position
thank you in advance for your help.