| 1 |
jQuery(document).ready(function($) { |
| 2 |
'use strict'; |
| 3 |
|
| 4 |
// Handle pagination clicks |
| 5 |
$(document).on('click', '.yatra-activity-pagination a', function(e) { |
| 6 |
e.preventDefault(); |
| 7 |
|
| 8 |
var $link = $(this); |
| 9 |
var $container = $link.closest('.yatra-activity-shortcode'); |
| 10 |
var page = $link.data('page'); |
| 11 |
var atts = $container.data('atts'); |
| 12 |
|
| 13 |
if (!page || !atts) { |
| 14 |
return; |
| 15 |
} |
| 16 |
|
| 17 |
// Add loading state |
| 18 |
$container.addClass('yatra-loading'); |
| 19 |
|
| 20 |
// Debug: Log the data being sent |
| 21 |
window.YATRA_DEBUG && console.log('Loading activity page:', { |
| 22 |
page: page, |
| 23 |
atts: atts |
| 24 |
}); |
| 25 |
|
| 26 |
// AJAX request |
| 27 |
$.post(yatraActivityShortcode.ajaxurl, { |
| 28 |
action: 'yatra_activity_shortcode_load', |
| 29 |
nonce: yatraActivityShortcode.nonce, |
| 30 |
page: page, |
| 31 |
atts: atts |
| 32 |
}, function(response) { |
| 33 |
if (response.success) { |
| 34 |
// Update only the inner content, not the entire container to prevent nesting |
| 35 |
// The response should contain only the inner content (header, grid, pagination) |
| 36 |
var $innerContent = $('<div>').html(response.data.html); |
| 37 |
var newShortcodeElement = $innerContent.find('.yatra-activity-shortcode'); |
| 38 |
|
| 39 |
if (newShortcodeElement.length) { |
| 40 |
// Extract the inner content from the new shortcode element |
| 41 |
var newInnerContent = newShortcodeElement.html(); |
| 42 |
var newAtts = newShortcodeElement.data('atts'); |
| 43 |
|
| 44 |
// Update the existing container's inner content |
| 45 |
$container.html(newInnerContent); |
| 46 |
|
| 47 |
// Update container data attributes |
| 48 |
if (newAtts) { |
| 49 |
$container.data('atts', newAtts); |
| 50 |
} else { |
| 51 |
} |
| 52 |
} else { |
| 53 |
// Fallback: if no shortcode element found, replace directly |
| 54 |
$container.html(response.data.html); |
| 55 |
} |
| 56 |
|
| 57 |
// Scroll to top of container |
| 58 |
$('html, body').animate({ |
| 59 |
scrollTop: $container.offset().top - 100 |
| 60 |
}, 300); |
| 61 |
|
| 62 |
// Trigger custom event |
| 63 |
$(document).trigger('yatraActivityShortcodeUpdated', [response.data]); |
| 64 |
} else { |
| 65 |
} |
| 66 |
}).fail(function(xhr, status, error) { |
| 67 |
}).always(function() { |
| 68 |
// Remove loading state |
| 69 |
$container.removeClass('yatra-loading'); |
| 70 |
}); |
| 71 |
}); |
| 72 |
|
| 73 |
// Initialize shortcode data |
| 74 |
$('.yatra-activity-shortcode').each(function() { |
| 75 |
var $container = $(this); |
| 76 |
var atts = $container.data('atts'); |
| 77 |
|
| 78 |
// Debug: Log the stored attributes |
| 79 |
|
| 80 |
if (!atts) { |
| 81 |
} |
| 82 |
}); |
| 83 |
}); |
| 84 |
|