| 1 |
function initializeDropdown(){document.querySelectorAll(".srfm-dropdown-common").forEach(o=>{if(o){let e={};"true"===o.getAttribute("data-multiple")&&(e={maxItems:null,hideSelected:!1});var t={maxOptions:null,hidePlaceholder:!0,plugins:["remove_button","clear_button"],onChange(e){Array.isArray(e)?e.forEach(e=>{wp.a11y.speak(e)}):wp.a11y.speak(e);var t=o.closest(".srfm-dropdown-block").querySelector(".srfm-input-dropdown-hidden");t&&t.setAttribute("value",Array.isArray(e)?e.join(","):e)},onItemAdd(){handleInputState(o)},onItemRemove(){handleInputState(o)},...e="false"===o.getAttribute("data-searchable")?{...e,controlInput:null}:e,render:{option(e,t){return`<div>${e.icon} <span>${t(e.text)}</span></div>`},item(e,t){return`<div>${e.icon} ${t(e.text)}</div>`}}},n=(new TomSelect(o,t),o.closest(".srfm-dropdown-block").querySelector(".ts-control")),r=(n.querySelector(".clear-button").innerHTML='<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12 4L4 12" stroke="currentColor" stroke-opacity="0.65" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/><path d="M4 4L12 12" stroke="currentColor" stroke-opacity="0.65" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/></svg>',document.createElement("div"));r.classList.add("ts-dropdown-icon"),r.innerHTML='<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M4 6L8 10L12 6" stroke="currentColor" stroke-opacity="0.65" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" /></svg>',n.appendChild(r),null===t.controlInput&&(r=o.closest(".srfm-dropdown-block").querySelector(".srfm-dropdown-placeholder"),(t=document.createElement("span")).classList.add("ts-control-placeholder"),t.textContent=r.textContent,n.prepend(t)),o.disabled=!0}})}function handleInputState(e){var e=e.closest(".srfm-dropdown-block").querySelector(".ts-control"),t=e?.parentElement,e=e?.querySelector("input");e&&(t.classList.contains("full")?e.setAttribute("readonly",""):e.removeAttribute("readonly"))}window.srfmInitializeDropdown=initializeDropdown,document.addEventListener("DOMContentLoaded",initializeDropdown); |