From 655835c10c3bd55f865b0eb25c529e2cada9f81d Mon Sep 17 00:00:00 2001 From: Cristi Stoica Date: Thu, 10 Oct 2024 19:16:36 +0200 Subject: [PATCH 1/2] feat: added MutationObserver --- assets/js/input.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/assets/js/input.js b/assets/js/input.js index dd94dae..f123f72 100755 --- a/assets/js/input.js +++ b/assets/js/input.js @@ -30,6 +30,9 @@ var is_open = true; active_item = $(this); + // Remove any existing popups to prevent duplicates + jQuery(".acf-svg-icon-picker__popup-holder").remove(); + if (acfSvgIconPicker.svgs.length == 0) { var list = '

' + acfSvgIconPicker.no_icons_msg + '

'; } else { @@ -212,4 +215,24 @@ }); }); } + + // Use MutationObserver to detect changes in the DOM + const observer = new MutationObserver((mutations) => { + mutations.forEach((mutation) => { + if (mutation.addedNodes.length) { + $(mutation.addedNodes) + .find(".acf-svg-icon-picker") + .each(function () { + console.log("MutationObserver: Initializing field:", $(this)); + initialize_field($(this)); + }); + } + }); + }); + + // Start observing the document body for changes + observer.observe(document.body, { + childList: true, + subtree: true, + }); })(jQuery); From 1f21921faa9a65959e09cf8c3c6a40dd8592ac5c Mon Sep 17 00:00:00 2001 From: Cristi Stoica Date: Thu, 10 Oct 2024 19:28:48 +0200 Subject: [PATCH 2/2] mend --- assets/js/input.js | 1 - 1 file changed, 1 deletion(-) diff --git a/assets/js/input.js b/assets/js/input.js index f123f72..3ddc38d 100755 --- a/assets/js/input.js +++ b/assets/js/input.js @@ -223,7 +223,6 @@ $(mutation.addedNodes) .find(".acf-svg-icon-picker") .each(function () { - console.log("MutationObserver: Initializing field:", $(this)); initialize_field($(this)); }); }