Skip to content

Instantly share code, notes, and snippets.

@pramodjodhani
Created February 6, 2026 08:49
Show Gist options
  • Select an option

  • Save pramodjodhani/47c2fa9a8630efdd4053dc43cb1715f2 to your computer and use it in GitHub Desktop.

Select an option

Save pramodjodhani/47c2fa9a8630efdd4053dc43cb1715f2 to your computer and use it in GitHub Desktop.
Iconic WDS - reservation table not working with Popup Box
<?php
add_filter( 'iconic_wds_force_load_reservation_calendar_assets', '__return_true' );
/**
* Trigger custom event when .ays-pb-modal becomes visible.
*/
add_action( 'wp_footer', function() {
?>
<script type="text/javascript">
(function() {
document.addEventListener("DOMContentLoaded", function() {
let modal = document.querySelector('.ays-pb-modal');
let wasVisible = false;
function triggerEvent() {
// document.dispatchEvent( new CustomEvent( 'ays_pb_modal_shown', { detail: { modal: modal } } ) );
jQuery(document.body).trigger('iconic_wds_init_reservation_table');
}
function isElementVisible( el ) {
if ( ! el ) return false;
const style = window.getComputedStyle( el );
// Check for display: none
if ( style.display === 'none' ) return false;
// Check for visibility: hidden
if ( style.visibility === 'hidden' ) return false;
// Check for opacity: 0
if ( style.opacity === '0' ) return false;
// Check dimensions
if ( el.offsetWidth === 0 && el.offsetHeight === 0 && el.getClientRects().length === 0 ) return false;
return true;
}
function checkVisibility() {
if ( ! modal ) return;
const visible = isElementVisible( modal );
if ( visible && ! wasVisible ) {
triggerEvent();
}
wasVisible = visible;
}
function observeModal( element ) {
// Check immediately
checkVisibility();
const observer = new MutationObserver( function( mutations ) {
checkVisibility();
} );
observer.observe( element, { attributes: true, attributeFilter: ['style', 'class'] } );
}
// Initial setup if exists
if ( modal ) {
observeModal( modal );
}
// Watch body for dynamic addition or replacement of the modal
// This handles cases where the modal is injected via JS later
const bodyObserver = new MutationObserver( function( mutations ) {
const currentModal = document.querySelector('.ays-pb-modal');
// If we found a modal and it's different from what we had (or we had none)
if ( currentModal && currentModal !== modal ) {
modal = currentModal;
observeModal( modal );
}
} );
bodyObserver.observe( document.body, { childList: true, subtree: true } );
});
})();
</script>
<?php
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment