assets/js/theme/script/moveSearchIcon.js in kcc-gem-theme-0.7.37 vs assets/js/theme/script/moveSearchIcon.js in kcc-gem-theme-0.7.38

- old
+ new

@@ -1,5 +1,21 @@ +function checkXIcon() { + const checkXIconOnLoad = (function() { + let executed = false; + return function() { + if (!executed) { + executed = true; + // do checkXIconOnLoad + const icon = document.getElementById('xIcon'); + const xIsHidden = icon.getAttribute('style') === 'display: none;'; + xIsHidden ? removeClear() : clearXIcon(); + } + }; + })(); + checkXIconOnLoad(); // "do checkXIconOnLoad" happens +} + function clearXIcon() { const targetEl = document.querySelector('button.gsc-search-button-v2'); targetEl.classList.add('gsc-overrides__clear-x'); } @@ -22,11 +38,10 @@ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gcse, s); } function moveSearchIcon() { - let initSearchPromise = new Promise((resolve, reject) => { gscInit(); resolve(); }); initSearchPromise.then(() => { @@ -47,9 +62,10 @@ observer.observe(targetNode, config); // Later, you can stop observing //observer.disconnect(); }); addIdPromise.then(() => { + checkXIcon(); const targetNode = document.getElementById('xIcon'); const config = { attributes: true, childList: true, subtree: true }; const callback = function(mutationsList, observer) { for(const mutation of mutationsList) { if (mutation.type == 'attributes') {