(function($){
'use strict';
let isInitialized=false;
let hoverTimeout=null;
let currentDropdown=null;
let isDesktop=false;
let isMobile=false;
let isDropdownLocked=false;
function getSkeletonLoader(){
const isDesktopView=window.innerWidth > 680;
if(isDesktopView){
return `
<div class="cekonay-skeleton-wrapper cekonay-desktop-skeleton">
<div class="cekonay-skeleton-avatar"></div>
<div class="cekonay-skeleton-text">
<div class="cekonay-skeleton-line cekonay-skeleton-greeting"></div>
</div>
</div>
`;
}else{
return `
<div class="cekonay-skeleton-wrapper cekonay-mobile-skeleton">
<div class="cekonay-skeleton-avatar"></div>
</div>
`;
}}
function initWhenReady(){
if(typeof cekonay_menu==='undefined'){
return;
}
if(isInitialized){
return;
}
initMenuAuth();
isInitialized=true;
}
if(document.readyState==='loading'){
document.addEventListener('DOMContentLoaded', initWhenReady);
}else{
initWhenReady();
}
function initMenuAuth(){
updateDeviceDetection();
initResponsiveInteractions();
initCartInteractions();
initCartUpdateListeners();
initGlobalEventListeners();
initResizeHandler();
}
function updateDeviceDetection(){
const width=window.innerWidth;
const hasHover=window.matchMedia('(hover: hover)').matches;
isDesktop=(width > 1024)||(width > 680&&hasHover);
isMobile = !isDesktop;
document.body.classList.toggle('cekonay-desktop-mode', isDesktop);
document.body.classList.toggle('cekonay-mobile-mode', isMobile);
document.body.classList.toggle('cekonay-tablet-mode', width >=681&&width <=1024);
}
function initResponsiveInteractions(){
if(isDesktop){
$(document).on('mouseenter.cekonay', '.cekonay-logged-in .cekonay-user-info', function (){
const $dropdown=$(this).find('.cekonay-dropdown-bubble');
if($dropdown.length){
showDesktopDropdown($dropdown);
}});
$(document).on('mouseenter.cekonay', '.cekonay-dropdown-bubble', function (){
clearTimeout(hoverTimeout);
});
$(document).on('mouseleave.cekonay', '.cekonay-dropdown-bubble', function (){
hideDesktopDropdown();
});
$(document).on('mouseleave.cekonay', '.cekonay-user-info', function (e){
if(!$(e.relatedTarget).closest('.cekonay-dropdown-bubble').length){
hideDesktopDropdown();
}});
$(document).off('click.cekonay', '.cekonay-avatar, .cekonay-user-info');
}else{
$(document).off('mouseenter.cekonay mouseleave.cekonay');
$(document).on('click.cekonay', '.cekonay-avatar, .cekonay-user-info', function (e){
e.preventDefault();
e.stopPropagation();
toggleMobileDropdown();
});
}}
function showDesktopDropdown($dropdown){
if(!isDesktop) return;
clearTimeout(hoverTimeout);
$('.cekonay-dropdown-bubble').not($dropdown).removeClass('active');
currentDropdown=$dropdown;
$dropdown.addClass('active').css('display', 'block');
setTimeout(()=> adjustDropdownPosition($dropdown), 10);
}
function hideDesktopDropdown(){
if(!isDesktop) return;
hoverTimeout=setTimeout(()=> {
if(currentDropdown){
currentDropdown.removeClass('active');
setTimeout(()=> {
if(!currentDropdown.hasClass('active')){
currentDropdown.css('display', 'none');
}}, 300);
currentDropdown=null;
}}, 600);
}
function toggleMobileDropdown(){
if(isDesktop) return;
const $dropdown=$('.cekonay-mobile-dropdown');
if($dropdown.hasClass('active')){
$dropdown.removeClass('active').slideUp(250);
isDropdownLocked=false;
$('body').removeClass('cekonay-dropdown-locked');
}else{
$('.cekonay-mobile-dropdown').removeClass('active').slideUp(200);
$dropdown.addClass('active').slideDown(250);
isDropdownLocked=true;
$('body').addClass('cekonay-dropdown-locked');
}}
function openMobileDropdown($dropdown){
if(isDesktop) return;
$('.cekonay-mobile-dropdown').not($dropdown).removeClass('active').slideUp(200);
$dropdown.addClass('active').slideDown(250);
isDropdownLocked=true;
$('body').addClass('cekonay-dropdown-locked');
}
function closeMobileDropdown($dropdown){
if(!$dropdown||!$dropdown.length){
$dropdown=$('.cekonay-mobile-dropdown.active');
}
$dropdown.removeClass('active').slideUp(250);
isDropdownLocked=false;
$('body').removeClass('cekonay-dropdown-locked');
}
function initCartInteractions(){
$(document).on('click.cekonay', '.cekonay-cart-icon, .mobile-cart', function(e){
e.stopPropagation();
if(typeof wc_add_to_cart_params!=='undefined'){
$('body').trigger('wc_fragment_refresh');
}});
}
function updateCartBadge(count){
const $badge=$('.cekonay-cart-badge');
if($badge.length){
$badge.attr('data-count', count).text(count);
}}
function initCartUpdateListeners(){
$(document.body).on('updated_wc_div updated_cart_totals added_to_cart removed_from_cart', function(){
if(typeof wc_cart_fragments_params!=='undefined'){
$.ajax({
url: wc_cart_fragments_params.wc_ajax_url.toString().replace('%%endpoint%%', 'get_refreshed_fragments'),
type: 'POST',
success: function(data){
if(data&&data.fragments){
const cartCount=$(data.fragments['div.widget_shopping_cart_content']).find('.cart-contents-count').text();
if(cartCount){
updateCartBadge(parseInt(cartCount)||0);
}}
}});
}});
$(document.body).on('adding_to_cart', function(){
});
}
function initGlobalEventListeners(){
$(document).on('click.cekonay', function (e){
const $target=$(e.target);
if(isDesktop) return;
if(isMobile&&isDropdownLocked){
if(!$target.closest('.cekonay-avatar, .cekonay-mobile-dropdown, .cekonay-user-info').length){
$('.cekonay-mobile-dropdown').removeClass('active').slideUp(200);
isDropdownLocked=false;
$('body').removeClass('cekonay-dropdown-locked');
}}
if($target.closest('.nav-section, .mobile-left, .cekonay-cart-icon, .hamburger').length){
$('.cekonay-mobile-dropdown').removeClass('active').slideUp(200);
isDropdownLocked=false;
$('body').removeClass('cekonay-dropdown-locked');
}});
$(document).on('keydown.cekonay', function (e){
if(e.key==='Escape'){
if(isDesktop){
hideDesktopDropdown();
}else if(isDropdownLocked){
$('.cekonay-mobile-dropdown').removeClass('active').slideUp(200);
isDropdownLocked=false;
$('body').removeClass('cekonay-dropdown-locked');
}}
});
}
function initResizeHandler(){
let resizeTimeout;
$(window).on('resize.cekonay', function (){
clearTimeout(resizeTimeout);
resizeTimeout=setTimeout(function (){
const oldIsDesktop=isDesktop;
updateDeviceDetection();
isDropdownLocked=false;
$('body').removeClass('cekonay-dropdown-locked');
if(oldIsDesktop!==isDesktop){
$(document).off('.cekonay');
$('.cekonay-dropdown-bubble, .cekonay-mobile-dropdown').removeClass('active').hide();
currentDropdown=null;
initResponsiveInteractions();
initGlobalEventListeners();
}}, 150);
});
}
function adjustDropdownPosition($dropdown){
if(!$dropdown.length||!isDesktop) return;
const dropdownRect=$dropdown[0].getBoundingClientRect();
const viewportWidth=window.innerWidth;
$dropdown.css({
'right': '0',
'left': 'auto'
});
if(dropdownRect.right > viewportWidth - 10){
const rightOffset=viewportWidth - dropdownRect.right - 10;
$dropdown.css({
'right': Math.max(0, -rightOffset) + 'px'
});
}
if(dropdownRect.left < 10){
$dropdown.css({
'left': '0',
'right': 'auto'
});
}}
function checkLoginState(){
const cookies=document.cookie.split(";");
let isLoggedIn=false;
for (let cookie of cookies){
const trimmed=cookie.trim();
if(trimmed.startsWith("wordpress_logged_in_") ||
trimmed.startsWith("woocommerce_")){
isLoggedIn=true;
break;
}}
const $widgets=$(".cekonay-not-logged");
if(isLoggedIn&&$widgets.length > 0){
const currentContent=$widgets.first().html();
if(currentContent.includes('cekonay-logged-in') ||
currentContent.includes('cekonay-avatar')){
return;
}
updateWidgetsToLoggedIn($widgets);
}}
function updateWidgetsToLoggedIn($widgets){
$widgets.each(function (){
const $widget=$(this);
$widget.html(getSkeletonLoader()).addClass('cekonay-refreshing');
$.ajax({
success: function (response){
if(response.success){
$widget.replaceWith(response.data);
initResponsiveInteractions();
}}
});
});
}
function updateWidgetsToLoggedIn($widgets){
$widgets.each(function(){
const $widget=$(this);
$widget.html(getSkeletonLoader()).addClass('cekonay-refreshing');
$.ajax({
url: cekonay_menu.ajax_url,
type: 'POST',
data: {
action: 'cekonay_obtenir_statut_connexion',
nonce: cekonay_menu.nonce
},
success: function(response){
if(response.success){
setTimeout(()=> {
$widget.replaceWith(response.data);
initResponsiveInteractions();
}, 500);
}else{
$widget.html(getFallbackConnectedHTML()).removeClass('cekonay-refreshing');
}},
error: function(){
$widget.html(getFallbackDisconnectedHTML()).removeClass('cekonay-refreshing');
}});
});
}
function detectUserChange(){
if(typeof Storage!=='undefined'&&window.localStorage){
const $avatar=$('.cekonay-avatar-initials');
const currentUserId=$avatar.length > 0&&$avatar.attr('data-initial') ?
'logged_' + $avatar.attr('data-initial'):'anonymous';
const storedUserId=localStorage.getItem('cekonay_user_id');
if(storedUserId&&storedUserId!==currentUserId){
$('.cekonay-menu-auth').each(function(){
$(this).html(getSkeletonLoader()).addClass('cekonay-refreshing');
});
setTimeout(()=> {
window.location.reload();
}, 800);
}
localStorage.setItem('cekonay_user_id', currentUserId);
}}
function getCartIconHTML(){
const cartUrl=cekonay_menu.cart_url||'/panier/';
const cartCount=0;
return `
<a href="${cartUrl}" class="cekonay-cart-icon" title="Voir mon panier" aria-label="Panier (${cartCount} articles)">
<svg width="19" height="19" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
<circle cx="9" cy="21" r="1" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
<circle cx="20" cy="21" r="1" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M1 1h4l2.68 13.39a2 2 0 0 0 2 1.61h9.72a2 2 0 0 0 2-1.61L23 6H6" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
<span class="cekonay-cart-badge" data-count="${cartCount}">${cartCount}</span>
</a>
`;
}
function getFallbackConnectedHTML(){
const isDesktopView=window.innerWidth > 680;
const cartHTML=getCartIconHTML();
if(isDesktopView){
return `
<div class="cekonay-header-cart-auth">
${cartHTML}
<div class="cekonay-menu-auth cekonay-logged-in">
<div class="cekonay-user-info">
<div class="cekonay-avatar">
<span class="cekonay-avatar-initials cekonay-color-1" style="width: 32px; height: 32px; background: #4299e1; color: white; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: 14px;">U</span>
</div>
<div class="cekonay-user-text">
<div class="cekonay-greeting">Bonjour, <strong>Utilisateur</strong></div>
</div>
</div>
<div class="cekonay-dropdown-bubble">
<a href="${cekonay_menu.myaccount_url}" class="cekonay-dropdown-item">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M20 21V19C20 17.9391 19.5786 16.9217 18.8284 16.1716C18.0783 15.4214 17.0609 15 16 15H8C6.93913 15 5.92172 15.4214 5.17157 16.1716C4.42143 16.9217 4 17.9391 4 19V21" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<circle cx="12" cy="7" r="4" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
Mon compte
</a>
<a href="#" class="cekonay-dropdown-item">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M9 21H5C4.46957 21 3.96086 20.7893 3.58579 20.4142C3.21071 20.0391 3 19.5304 3 19V5C3 4.46957 3.21071 3.96086 3.58579 3.58579C3.96086 3.21071 4.46957 3 5 3H9" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<polyline points="16,17 21,12 16,7" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<line x1="21" y1="12" x2="9" y2="12" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
</svg>
Se déconnecter
</a>
</div>
</div>
</div>
`;
}else{
return `
<div class="cekonay-header-cart-auth">
${cartHTML}
<div class="cekonay-menu-auth cekonay-logged-in">
<div class="cekonay-user-info">
<div class="cekonay-avatar" data-mobile-link="${cekonay_menu.myaccount_url}">
<span class="cekonay-avatar-initials cekonay-color-1" style="width: 36px; height: 36px; background: #4299e1; color: white; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: 15px;">U</span>
</div>
</div>
<div class="cekonay-mobile-dropdown">
<a href="${cekonay_menu.myaccount_url}" class="cekonay-mobile-dropdown-item">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M20 21V19C20 17.9391 19.5786 16.9217 18.8284 16.1716C18.0783 15.4214 17.0609 15 16 15H8C6.93913 15 5.92172 15.4214 5.17157 16.1716C4.42143 16.9217 4 17.9391 4 19V21" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<circle cx="12" cy="7" r="4" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
Mon compte
</a>
<a href="#" class="cekonay-mobile-dropdown-item">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M9 21H5C4.46957 21 3.96086 20.7893 3.58579 20.4142C3.21071 20.0391 3 19.5304 3 19V5C3 4.46957 3.21071 3.96086 3.58579 3.58579C3.96086 3.21071 4.46957 3 5 3H9" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<polyline points="16,17 21,12 16,7" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<line x1="21" y1="12" x2="9" y2="12" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
</svg>
Se déconnecter
</a>
</div>
</div>
</div>
`;
}}
function getFallbackDisconnectedHTML(){
const cartHTML=getCartIconHTML();
return `
<div class="cekonay-header-cart-auth">
${cartHTML}
<div class="cekonay-menu-auth cekonay-not-logged">
<a href="${cekonay_menu.login_url}" class="cekonay-login-link" title="S'identifier">
<div class="cekonay-login-icon">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M20 21V19C20 17.9391 19.5786 16.9217 18.8284 16.1716C18.0783 15.4214 17.0609 15 16 15H8C6.93913 15 5.92172 15.4214 5.17157 16.1716C4.42143 16.9217 4 17.9391 4 19V21" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<circle cx="12" cy="7" r="4" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</div>
<span class="cekonay-login-text">S'identifier</span>
</a>
</div>
`;
}
window.CekonayMenuAuth={
refresh: function(){
checkLoginState();
},
updateWidget: function(selector){
const $widget=$(selector);
if($widget.hasClass('cekonay-not-logged')){
updateWidgetsToLoggedIn($widget);
}},
showConnected: function(userData){
const avatarInitial=userData.name ? userData.name.charAt(0).toUpperCase():'U';
const colorClass=getColorClassFromInitial(avatarInitial);
const isDesktopView=window.innerWidth > 680;
const cartHTML=getCartIconHTML();
let html;
if(isDesktopView){
html=`
<div class="cekonay-header-cart-auth">
${cartHTML}
<div class="cekonay-menu-auth cekonay-logged-in">
<div class="cekonay-user-info">
<div class="cekonay-avatar">
<span class="cekonay-avatar-initials ${colorClass}"
style="width: 32px; height: 32px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; color: white; font-weight: 600; font-size: 14px;"
data-initial="${avatarInitial}">
${avatarInitial}
</span>
</div>
<div class="cekonay-user-text">
<div class="cekonay-greeting">
Bonjour, <strong>${userData.name||'Utilisateur'}</strong>
</div>
</div>
</div>
<div class="cekonay-dropdown-bubble">
<a href="${userData.account_url||cekonay_menu.myaccount_url}" class="cekonay-dropdown-item">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M20 21V19C20 17.9391 19.5786 16.9217 18.8284 16.1716C18.0783 15.4214 17.0609 15 16 15H8C6.93913 15 5.92172 15.4214 5.17157 16.1716C4.42143 16.9217 4 17.9391 4 19V21" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<circle cx="12" cy="7" r="4" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
Mon compte
</a>
<a href="${userData.logout_url||'#'}" class="cekonay-dropdown-item">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M9 21H5C4.46957 21 3.96086 20.7893 3.58579 20.4142C3.21071 20.0391 3 19.5304 3 19V5C3 4.46957 3.21071 3.96086 3.58579 3.58579C3.96086 3.21071 4.46957 3 5 3H9" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<polyline points="16,17 21,12 16,7" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<line x1="21" y1="12" x2="9" y2="12" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
</svg>
Se déconnecter
</a>
</div>
</div>
</div>
`;
}else{
html=`
<div class="cekonay-header-cart-auth">
${cartHTML}
<div class="cekonay-menu-auth cekonay-logged-in">
<div class="cekonay-user-info">
<div class="cekonay-avatar" data-mobile-link="${userData.account_url||cekonay_menu.myaccount_url}">
<span class="cekonay-avatar-initials ${colorClass}"
style="width: 36px; height: 36px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; color: white; font-weight: 600; font-size: 15px;"
data-initial="${avatarInitial}">
${avatarInitial}
</span>
</div>
</div>
<div class="cekonay-mobile-dropdown">
<a href="${userData.account_url||cekonay_menu.myaccount_url}" class="cekonay-mobile-dropdown-item">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M20 21V19C20 17.9391 19.5786 16.9217 18.8284 16.1716C18.0783 15.4214 17.0609 15 16 15H8C6.93913 15 5.92172 15.4214 5.17157 16.1716C4.42143 16.9217 4 17.9391 4 19V21" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<circle cx="12" cy="7" r="4" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
Mon compte
</a>
<a href="${userData.logout_url||'#'}" class="cekonay-mobile-dropdown-item">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M9 21H5C4.46957 21 3.96086 20.7893 3.58579 20.4142C3.21071 20.0391 3 19.5304 3 19V5C3 4.46957 3.21071 3.96086 3.58579 3.58579C3.96086 3.21071 4.46957 3 5 3H9" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<polyline points="16,17 21,12 16,7" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<line x1="21" y1="12" x2="9" y2="12" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
</svg>
Se déconnecter
</a>
</div>
</div>
</div>
`;
}
$('.cekonay-header-cart-auth').replaceWith(html);
initResponsiveInteractions();
},
showDisconnected: function(){
$('.cekonay-header-cart-auth').replaceWith(getFallbackDisconnectedHTML());
},
getCurrentMode: function(){
return isDesktop ? 'desktop':'mobile';
}};
function getColorClassFromInitial(initial){
const position=initial.charCodeAt(0) - 'A'.charCodeAt(0) + 1;
const colorIndex=(position - 1) % 5;
return `cekonay-color-${colorIndex + 1}`;
}
$(document).on('cekonay:login', function(e, userData){
window.CekonayMenuAuth.showConnected(userData);
});
$(document).on('cekonay:logout', function(){
window.CekonayMenuAuth.showDisconnected();
});
})(jQuery);
if(typeof jQuery==='undefined'){
document.addEventListener('DOMContentLoaded', function(){
const widgets=document.querySelectorAll('.cekonay-not-logged');
const isDesktop=window.innerWidth > 680;
function getVanillaSkeletonLoader(){
if(isDesktop){
return `
<div class="cekonay-skeleton-wrapper cekonay-desktop-skeleton">
<div class="cekonay-skeleton-avatar"></div>
<div class="cekonay-skeleton-text">
<div class="cekonay-skeleton-line cekonay-skeleton-greeting"></div>
<div class="cekonay-skeleton-line cekonay-skeleton-links"></div>
</div>
</div>
`;
}else{
return `
<div class="cekonay-skeleton-wrapper cekonay-mobile-skeleton">
<div class="cekonay-skeleton-avatar"></div>
</div>
`;
}}
const isLoggedIn=document.cookie.includes('wordpress_logged_in_') ||
document.cookie.includes('woocommerce_');
if(isLoggedIn&&widgets.length > 0){
widgets.forEach(widget=> {
widget.innerHTML=getVanillaSkeletonLoader();
widget.classList.add('cekonay-refreshing');
fetch(window.cekonay_menu?.ajax_url||'/wp-admin/admin-ajax.php', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: `action=cekonay_obtenir_statut_connexion&nonce=${window.cekonay_menu?.nonce||''}`
})
.then(response=> response.json())
.then(data=> {
if(data.success){
setTimeout(()=> {
widget.outerHTML=data.data;
}, 500);
}})
.catch(()=> {
widget.innerHTML=`<a href="/connexion/">S'identifier</a>`;
widget.classList.remove('cekonay-refreshing');
});
});
}
document.addEventListener('click', function(e){
const isDesktopMode=window.innerWidth > 680;
if(e.target.closest('.cekonay-cart-icon, .mobile-cart')){
e.stopPropagation();
}
if(!isDesktopMode&&e.target.closest('.cekonay-avatar-initials')){
const dropdown=document.querySelector('.cekonay-mobile-dropdown');
if(dropdown){
dropdown.classList.toggle('active');
}}
if(!isDesktopMode&&!e.target.closest('.cekonay-avatar, .cekonay-mobile-dropdown')){
const dropdowns=document.querySelectorAll('.cekonay-mobile-dropdown');
dropdowns.forEach(dd=> dd.classList.remove('active'));
}});
});
}
function cekonayMoveAuthButtonMobile(){
const isMobile=window.innerWidth <=980;
const authWrapper=document.querySelector('.cekonay-header-cart-auth');
if(!authWrapper) return;
if(isMobile&&!authWrapper.classList.contains('moved')){
const mainMenu=document.getElementById('cekonay-main-menu');
if(mainMenu){
const cartButton=mainMenu.querySelector('a[href*="/panier"]');
if(cartButton&&cartButton.parentElement){
cartButton.parentElement.insertBefore(authWrapper, cartButton);
authWrapper.classList.add('moved');
if(typeof initResponsiveInteractions==='function'){
$(document).off('.cekonay');
initResponsiveInteractions();
initGlobalEventListeners();
}}
}}else if(!isMobile&&authWrapper.classList.contains('moved')){
const textInner=document.querySelector('.et_pb_text_inner');
if(textInner){
textInner.appendChild(authWrapper);
authWrapper.classList.remove('moved');
if(typeof initResponsiveInteractions==='function'){
$(document).off('.cekonay');
initResponsiveInteractions();
initGlobalEventListeners();
}}
}}
document.addEventListener('DOMContentLoaded', function(){
cekonayMoveAuthButtonMobile();
});
let resizeTimer;
window.addEventListener('resize', function(){
clearTimeout(resizeTimer);
resizeTimer=setTimeout(cekonayMoveAuthButtonMobile, 250);
});
jQuery(function ($){
$(document).ready(function (){
$('.dropdown-menu-column').each(function (index){
var indexPlusOne=index + 1;
var $dropdownMenuItems=$(this).find('.dropdown-menu-item');
var $mainMenuItem=$('.first-level-' + indexPlusOne + '>a');
$dropdownMenuItems.wrapAll('<div class="dropdown-menu-container-' + indexPlusOne + '" />');
var $dropdownContainer=$('.dropdown-menu-container-' + indexPlusOne);
$dropdownContainer.insertAfter($mainMenuItem);
});
var $firstLevel=$('.et_mobile_menu .first-level > a');
var $allDropdowns=$('.et_mobile_menu [class*="dropdown-menu-container"]');
$firstLevel.off('click').on('click', function (e){
e.preventDefault();
var $thisDropdown=$(this).siblings();
$thisDropdown.slideToggle();
$(this).toggleClass('icon-switch');
if($(this).hasClass('first-level-open')){
$(this).removeClass('first-level-open').addClass('first-level-closed');
$firstLevel.not(this).css('height', '50px');
}else{
$(this).removeClass('first-level-closed').addClass('first-level-open');
$firstLevel.not(this).css('height', '50px');
}
if($firstLevel.filter('.first-level-open').length===0){
$firstLevel.css('height', 'calc((97vh - 80px)/3)');
}
var dropdownSiblings=$allDropdowns.not($thisDropdown);
dropdownSiblings.slideUp();
var $thisFirstLevel=$(this);
var $firstLevelSiblings=$firstLevel.not($thisFirstLevel);
$firstLevelSiblings.removeClass('icon-switch').removeClass('first-level-open').addClass('first-level-closed').removeClass('other-menu-open');
});
if($(window).width() <=980){
$firstLevel.each(function (index){
$(this).addClass('first-level-' + (index + 1));
});
$firstLevel.addClass('first-level-closed');
}});
});