Files
2024-09-25 09:25:31 -04:00

1 line
4.2 KiB
JavaScript

function WPSPslideUp(e,t){e.style.transitionProperty="height, margin, padding",e.style.transitionDuration=t+"ms",e.style.boxSizing="border-box",e.style.height=e.offsetHeight+"px",e.style.overflow="hidden",e.style.height=0,e.style.paddingTop=0,e.style.paddingBottom=0,e.style.marginTop=0,e.style.marginBottom=0,window.setTimeout(function(){e.style.display="none",e.style.removeProperty("height"),e.style.removeProperty("padding-top"),e.style.removeProperty("padding-bottom"),e.style.removeProperty("margin-top"),e.style.removeProperty("margin-bottom"),e.style.removeProperty("overflow"),e.style.removeProperty("transition-duration"),e.style.removeProperty("transition-property")},t)}function WPSPslideDown(e,t){e.style.removeProperty("display");let s=window.getComputedStyle(e).display;"none"===s&&(s="block"),e.style.display=s;var a=e.offsetHeight;e.style.overflow="hidden",e.style.height=0,e.style.paddingTop=0,e.style.paddingBottom=0,e.style.marginTop=0,e.style.marginBottom=0,e.style.boxSizing="border-box",e.style.transitionProperty="height, margin, padding",e.style.transitionDuration=t+"ms",e.style.height=a+"px",e.style.removeProperty("padding-top"),e.style.removeProperty("padding-bottom"),e.style.removeProperty("margin-top"),e.style.removeProperty("margin-bottom"),window.setTimeout(function(){e.style.removeProperty("height"),e.style.removeProperty("overflow"),e.style.removeProperty("transition-duration"),e.style.removeProperty("transition-property")},t)}function setupFAQ(){var e=new RegExp("^[\\w\\-]+$"),t=window.location.hash.substring(1),s=document.getElementsByClassName("wpsp-faq-expand-first-true"),a=document.getElementsByClassName("wpsp-faq-inactive-other-false");if(void 0!==document.getElementById(t)&&null!==document.getElementById(t)&&""!==document.getElementById(t)&&e.test(t)){e=document.getElementById(t);void 0!==e.getElementsByClassName("wpsp-faq-item")[0]&&(e.getElementsByClassName("wpsp-faq-item")[0].classList.add("wpsp-faq-item-active"),e.getElementsByClassName("wpsp-faq-item")[0].setAttribute("aria-expanded",!0),WPSPslideDown(e.getElementsByClassName("wpsp-faq-content")[0],500))}else for(let e=0;e<s.length;e++)!0===s[e].classList.contains("wpsp-faq-layout-accordion")&&(s[e].querySelectorAll(".wpsp-faq-child__outer-wrap")[0].getElementsByClassName("wpsp-faq-item")[0].classList.add("wpsp-faq-item-active"),s[e].querySelectorAll(".wpsp-faq-child__outer-wrap")[0].getElementsByClassName("wpsp-faq-item")[0].setAttribute("aria-expanded",!0),s[e].querySelectorAll(".wpsp-faq-child__outer-wrap")[0].getElementsByClassName("wpsp-faq-item")[0].querySelectorAll(".wpsp-faq-content")[0].style.display="block");for(let e=0;e<a.length;e++)if(!0===a[e].classList.contains("wpsp-faq-layout-accordion")){var o=a[e].querySelectorAll(".wpsp-faq-child__outer-wrap");for(let e=0;e<o.length;e++)o[e].getElementsByClassName("wpsp-faq-item")[0].classList.add("wpsp-faq-item-active"),o[e].getElementsByClassName("wpsp-faq-item")[0].setAttribute("aria-expanded",!0),o[e].getElementsByClassName("wpsp-faq-item")[0].querySelectorAll(".wpsp-faq-content")[0].style.display="block"}}function WPSPfaqClick(t,s){if("A"!==t.target.tagName)if(t.preventDefault(),s.classList.contains("wpsp-faq-item-active"))s.classList.remove("wpsp-faq-item-active"),s.setAttribute("aria-expanded",!1),WPSPslideUp(s.getElementsByClassName("wpsp-faq-content")[0],500);else{t=t.currentTarget.closest(".wp-block-wpsp-faq");let e="true";if(t.classList.contains("wp-block-wpsp-faq")&&(e=t.getAttribute("data-faqtoggle")),s.classList.add("wpsp-faq-item-active"),s.setAttribute("aria-expanded",!0),WPSPslideDown(s.getElementsByClassName("wpsp-faq-content")[0],500),"true"===e){var a=t.querySelectorAll(".wpsp-faq-questions-button");for(let e=0;e<a.length;e++){var o=a[e].parentElement;o!==s&&(o.classList.remove("wpsp-faq-item-active"),o.setAttribute("aria-expanded",!1),WPSPslideUp(o.getElementsByClassName("wpsp-faq-content")[0],500))}}}}window.addEventListener("load",function(){setupFAQ();var t=document.getElementsByClassName("wpsp-faq-layout-accordion");for(let e=0;e<t.length;e++){var s=t[e].querySelectorAll(".wpsp-faq-questions-button");for(let e=0;e<s.length;e++)s[e].parentElement.addEventListener("click",function(e){WPSPfaqClick(e,this)}),s[e].parentElement.addEventListener("keypress",function(e){WPSPfaqClick(e,this)})}});