| 1 |
jQuery(document).ready(function($) { |
| 2 |
'use strict'; |
| 3 |
|
| 4 |
$(document).on('click', '.yatra-trip-category-shortcode .yatra-destination-pagination a', function(e) { |
| 5 |
e.preventDefault(); |
| 6 |
|
| 7 |
var $link = $(this); |
| 8 |
var $container = $link.closest('.yatra-trip-category-shortcode'); |
| 9 |
var page = $link.data('page'); |
| 10 |
var atts = $container.data('atts'); |
| 11 |
|
| 12 |
if (!page || !atts || typeof yatraTripCategoryShortcode === 'undefined') { |
| 13 |
return; |
| 14 |
} |
| 15 |
|
| 16 |
$container.addClass('yatra-loading'); |
| 17 |
|
| 18 |
$.post(yatraTripCategoryShortcode.ajaxurl, { |
| 19 |
action: 'yatra_trip_category_shortcode_load', |
| 20 |
nonce: yatraTripCategoryShortcode.nonce, |
| 21 |
page: page, |
| 22 |
atts: atts |
| 23 |
}, function(response) { |
| 24 |
if (response.success) { |
| 25 |
var $innerContent = $('<div>').html(response.data.html); |
| 26 |
var $newRoot = $innerContent.find('.yatra-trip-category-shortcode'); |
| 27 |
|
| 28 |
if ($newRoot.length) { |
| 29 |
var newInnerContent = $newRoot.html(); |
| 30 |
var newAtts = $newRoot.data('atts'); |
| 31 |
$container.html(newInnerContent); |
| 32 |
if (newAtts) { |
| 33 |
$container.data('atts', newAtts); |
| 34 |
} |
| 35 |
} else { |
| 36 |
$container.html(response.data.html); |
| 37 |
} |
| 38 |
|
| 39 |
$('html, body').animate({ |
| 40 |
scrollTop: $container.offset().top - 100 |
| 41 |
}, 300); |
| 42 |
|
| 43 |
$(document).trigger('yatraTripCategoryShortcodeUpdated', [response.data]); |
| 44 |
} |
| 45 |
}).always(function() { |
| 46 |
$container.removeClass('yatra-loading'); |
| 47 |
}); |
| 48 |
}); |
| 49 |
}); |
| 50 |
|