/** * Palmetto Contact Modal — MicroModal init. * * Loaded when a page needs the contact modal: either it contains a * `palmetto-modal-trigger` button, OR the header-trigger feature is on * (forced site-wide in PHP so the global header CTA can open the modal). * * Configures MicroModal to use BASED's existing trigger conventions * (`data-custom-open` / `data-custom-close` + class `is-open`) so any * inline triggers that haven't been migrated yet keep working until the * A4 migration replaces them with proper blocks. */ (function () { 'use strict'; if ( typeof window.MicroModal === 'undefined' ) { return; } var CFG = window.ppbContactModal || {}; var MODAL_ID = CFG.modalId || 'palmetto-contact-modal'; // ----------------------------------------------------------------------- // Header CTA → modal trigger. // // The header button is added via Kadence's header builder, so it can't // carry our `palmetto-modal-trigger` marker className (no field for it). // Instead we adopt any HEADER button-class anchor whose href is exactly // "#" as a modal trigger: tag it with `data-custom-open` BEFORE // MicroModal.init() so MicroModal's own click binding picks it up (it // queries `[data-custom-open]` at init time). // // Scoped to the header (incl. mobile drawer) + requires a button-ish class // (`.button` / `.kb-button` / `.header-button` / `.wp-block-button__link`) // + href exactly "#", and skips menu mechanics / drawer + popup toggles — // so it reliably hits the CTA without hijacking other "#" links. // ----------------------------------------------------------------------- if ( CFG.headerTrigger !== false ) { var scopes = document.querySelectorAll( '#masthead, .site-header, header, #mobile-drawer' ); Array.prototype.forEach.call( scopes, function ( scope ) { var anchors = scope.querySelectorAll( 'a[href="#"]' ); Array.prototype.forEach.call( anchors, function ( a ) { if ( a.hasAttribute( 'data-custom-open' ) ) { return; } // already a trigger if ( a.closest( '.ubermenu' ) ) { return; } // mega-menu mechanics if ( a.hasAttribute( 'data-toggle-target' ) ) { return; } // drawer/search toggles if ( a.getAttribute( 'aria-haspopup' ) ) { return; } // submenu / popup toggles if ( ( a.className || '' ).indexOf( 'button' ) === -1 ) { return; } // require a button class a.setAttribute( 'data-custom-open', MODAL_ID ); if ( ! a.getAttribute( 'role' ) ) { a.setAttribute( 'role', 'button' ); } } ); } ); } window.MicroModal.init( { openTrigger: 'data-custom-open', closeTrigger: 'data-custom-close', openClass: 'is-open', disableScroll: true, disableFocus: false, awaitOpenAnimation: false, awaitCloseAnimation: true, } ); // Our modal triggers are (the render_block filter forces that // href so the link is focusable + has button semantics; the header CTA is // already "#"). MicroModal opens the modal on click but does NOT cancel the // anchor's default action, so the "#" navigation jumps the page to the top. // Suppress that here — delegated so it also covers any triggers added after // init — while leaving the modal-open behaviour to MicroModal. The page // stays exactly where the user clicked. document.addEventListener( 'click', function ( event ) { if ( event.target.closest( '[data-custom-open]' ) ) { event.preventDefault(); } } ); })();