(function($){
// Elementor frontend 초기화 이후 실행
if (window.elementorFrontend) {
elementorFrontend.hooks.addAction('frontend/element_ready/global', function(){
function getActivePanelId(){
var $p = $('.elementor-tab-content.elementor-active');
return $p.length ? $p.attr('id') : '';
}
function activateTab(id){
$('.e-n-tab-title[aria-controls="'+ id +'"]').trigger('click');
}
// 로드 시 해시 유지
var h = location.hash.slice(1);
if (h) {
activateTab(h);
history.replaceState(null, null, '#'+h);
}
// 탭 클릭 해시 갱신
$(document).on('click', '.e-n-tab-title', function(){
history.replaceState(null, null, '#'+ $(this).attr('aria-controls'));
});
// 페이지네이션 가로채기
$(document).on('click', '.kitify-products-pagination a', function(e){
e.preventDefault();
var pid = getActivePanelId(),
$a = $(this),
href= $a.attr('href').split('?')[0],
p = ($a.attr('href').match(/paged=(\d+)/)||[])[1]||1;
href += '?paged='+p + (pid?'&tab='+pid:'');
$.get(href, function(html){
var $tmp = $('').html(html);
$('.kitify-products-wrapper').html( $tmp.find('.kitify-products-wrapper').html() );
$('.kitify-products-pagination').html( $tmp.find('.kitify-products-pagination').html() );
if (pid) activateTab(pid);
});
});
// AJAX 완료 후 탭 재활성화
$(document).ajaxComplete(function(e,x,s){
if (s.url.indexOf('kitify_products')!==-1) {
var pid = getActivePanelId();
if (pid) activateTab(pid);
}
});
});
}
})(jQuery);