jQuery(document).ready(function($) { // Loop through all the intentclicks tags and request their content $('.ta-intentclicks-section-config').each(function() { // Get data from shortcode output let attr = $(this).data('intentclicks-attributes'); let content = $(this).data('intentclicks-content'); let postid = $(this).data('intentclicks-postid'); // Make AJAX request to get rendered layout $.ajax({ url: intentclicks_ajax.url, type: 'POST', data: { 'action': 'intentclicks_build_layout', 'attr': JSON.stringify(attr), 'content': JSON.stringify(content), 'referrer': document.referrer, 'postid': parseInt(postid) }, success: (response) => { // Replace the placeholder with the result returned from AJAX $(this).replaceWith('\n' + response); }, error: (request, status, error) => { // Insert an error message in the placeholder, leaving the config attributes intact for review $(this).html(''); } }); }); // Open modal on button press $(document).on('click', '.icp-list-cta .cta-action-btn', function(e) { e.preventDefault(); let target = $(this).data('modal'); $(target).toggleClass('open'); // Force the embedded form height to update $(target + " iframe").css('height', 'auto'); }); // Close modal on close button or overlay click $(document).on('click', '.icp-list-modal > .icp-overlay, .icp-list-modal .modal-close', function(e) { e.preventDefault(); $(this).closest('.icp-list-modal').toggleClass('open'); }); });