(function($){
// Elementor frontend 로딩 후 실행
$(window).on('elementor/frontend/init', function(){
// 현재 활성 패널 ID 가져오기
function getActivePanelId(){
var $panel = $('.elementor-tab-content.elementor-active');
return $panel.length ? $panel.attr('id') : '';
}
// 탭 클릭 (aria-controls 기준)
function activateTab(id){
var $tab = $('.e-n-tab-title[aria-controls="'+ id +'"]');
if ($tab.length) {
$tab.trigger('click');
// 클릭된 탭 콘텐츠로 스크롤
var $panel = $('#'+id);
if ($panel.length) {
$('html, body').animate({ scrollTop: $panel.offset().top - 100 }, 300);
}
}
}
// 초기 해시 활성화
var initHash = location.hash.slice(1);
if (initHash) {
activateTab(initHash);
}
// 탭 클릭 시 해시 갱신
$(document).on('click', '.e-n-tab-title', function(){
var id = $(this).attr('aria-controls');
history.replaceState(null, null, '#'+id);
});
// 페이지네이션 가로채기
$(document).on('click', '.kitify-products-pagination a', function(e){
e.preventDefault();
var panelId = getActivePanelId(),
$a = $(this),
href = $a.attr('href').split('?')[0],
paged = ($a.attr('href').match(/paged=(\d+)/)||[])[1]||1;
href += '?paged='+paged + (panelId?'&tab='+panelId:'');
$.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 (panelId) activateTab(panelId);
});
});
// AJAX 완료 후 탭 재활성화 & 스크롤
$(document).ajaxComplete(function(e,x,s){
if (s.url.indexOf('kitify_products') !== -1) {
var panelId = getActivePanelId();
if (panelId) {
activateTab(panelId);
}
}
});
});
})(jQuery);