").addClass('saved theme_result_message');
var icon = $("").addClass('dashicons dashicons-yes');
$('.megamenu_submit .mega_left').append(success.html(icon).append(message.data));
} else if (message.success == false) { // Errors in scss
var error = $(" ").addClass('fail theme_result_message').html(megamenu_settings.theme_save_error + " ").append(megamenu_settings.theme_save_error_refresh).append(" ").addClass('fail theme_result_message').html(megamenu_settings.theme_save_error + " ").append(megamenu_settings.theme_save_error_exhausted + " ").append(megamenu_settings.theme_save_error_memory_limit + " ").append(memory_limit_link).append(" ").addClass('fail theme_result_message').html(megamenu_settings.theme_save_error + " ").addClass('fail theme_result_message').html(megamenu_settings.theme_save_error_500 + " ").append(megamenu_settings.theme_save_error_memory_limit + " ").append(memory_limit_link);
} else {
if (message.responseText == "-1") { // nonce check failed
var error = $(" ").addClass('fail theme_result_message').html(megamenu_settings.theme_save_error + " " + megamenu_settings.theme_save_error_nonce_failed );
}
}
$('.megamenu_submit').after(error);
},
complete: function() {
$("input#submit").removeClass('is-busy').attr('value', original_value);
}
});
});
$(".theme_editor").on("change", function(e) {
$(".theme_result_message").css('visibility', 'hidden');
});;
$('select#mega_css').on("change", function() {
var select = $(this);
var selected = $(this).val();
select.next().children().hide();
select.next().children('.' + selected).show();
});
// validate inputs once the user moves to the next setting
$( window ).scroll(function() {
$('.theme_editor input:focus').blur();
});
$('form.theme_editor label[data-validation]').each(function() {
var label = $(this);
var validation = label.attr('data-validation');
var error_message = label.siblings( '.mega-validation-message-' + label.attr('class') );
var input = $('input', label);
input.on('blur', function() {
var value = $(this).val();
if (label.hasClass('mega-flyout_width') && value == 'auto') {
label.removeClass('mega-error');
label.siblings( '.mega-validation-message-' + label.attr('class') ).hide();
return;
}
if ( ( validation == 'int' && Math.floor(value) != value )
|| ( validation == 'px' && ! ( value.substr(value.length - 2) == 'px' || value.substr(value.length - 2) == 'em' || value.substr(value.length - 2) == 'vh' || value.substr(value.length - 2) == 'vw' || value.substr(value.length - 2) == 'pt' || value == 'max-content' || value.substr(value.length - 3) == 'rem' || value.substr(value.length - 1) == '%' ) && value != 0 && value != 'normal' && value != 'inherit' )
|| ( validation == 'float' && ! $.isNumeric(value) ) ) {
label.addClass('mega-error');
error_message.show();
} else {
label.removeClass('mega-error');
label.siblings( '.mega-validation-message-' + label.attr('class') ).hide();
}
});
});
$(".mega-accordion-title").on('click', function(e) {
e.preventDefault();
e.stopPropagation();
var title = $(this);
var content = title.next('.mega-accordion-content');
if ( content.is(':hidden') ) {
content.slideDown('fast', function() {
title.addClass('mega-accordion-open');
});
} else {
content.slideUp('fast', function() {
title.removeClass('mega-accordion-open');
});
}
});
$(".mega-ellipsis").on('click', function(e) {
e.stopPropagation();
var ellipsis = $(this);
$(".mega-ellipsis").not(ellipsis).removeClass('mega-ellipsis-open');
if ( ellipsis.hasClass('mega-ellipsis-open') ) {
ellipsis.removeClass('mega-ellipsis-open');
} else {
ellipsis.addClass('mega-ellipsis-open');
}
});
$(document).on("click", function(e) { // hide menu when clicked away from
if ( ! $(e.target).closest(".mega-ellipsis").length ) {
$(".mega-ellipsis").removeClass('mega-ellipsis-open');
}
});
$('.megamenu-edit-theme').on("click", function() {
var url = $(this).siblings("select").find(":selected").attr('data-url');
window.location.href = url;
});
});
document.addEventListener('DOMContentLoaded', function() {
// Select relevant elements from the DOM
const navWrapper = document.querySelector('.nav-tab-wrapper');
const tabs = document.querySelectorAll('.mega-tab');
const slider = document.querySelector('.nav-tab-slider');
const activeTabContentDisplay = document.getElementById('active-tab-content');
// Find the initially active tab
let currentActiveTab = document.querySelector('.mega-tab.nav-tab-active');
// Function to position the slider under the active tab
function positionSlider(activeTab) {
if (!activeTab || !slider || !navWrapper) {
// If elements are missing, the new CSS :has rule will handle hiding the slider
// if no tab is active. If an activeTab is expected but missing,
// slider might not position correctly, but it won't be explicitly hidden by JS here.
return;
}
// Get the dimensions and position of the navigation wrapper and the active tab
const navWrapperRect = navWrapper.getBoundingClientRect();
const activeTabRect = activeTab.getBoundingClientRect();
// Calculate the slider's width and left position
// The left position is relative to the navWrapper
slider.style.width = activeTabRect.width + 'px';
slider.style.left = (activeTabRect.left - navWrapperRect.left) + 'px';
// Display the data-tab attribute of the active tab (for demonstration)
if (activeTabContentDisplay) {
activeTabContentDisplay.textContent = `Current active tab's data-tab: ${activeTab.getAttribute('data-tab')}`;
}
}
// Set the initial position of the slider if a tab is active
if (currentActiveTab) {
positionSlider(currentActiveTab);
}
// REMOVED: The 'else if' block that explicitly hid the slider using JS.
// CSS :has() now handles hiding the slider if no tab is initially active.
// Add click event listeners to each tab
tabs.forEach(tab => {
tab.addEventListener('click', function(event) {
event.preventDefault(); // Prevent default anchor link behavior
// Remove 'nav-tab-active' class from the previously active tab
if (currentActiveTab) {
currentActiveTab.classList.remove('nav-tab-active');
}
// Add 'nav-tab-active' class to the clicked tab
this.classList.add('nav-tab-active');
currentActiveTab = this; // Update the reference to the current active tab
// Move the slider to the newly active tab
positionSlider(this);
});
});
// Reposition the slider on window resize to maintain correct alignment
window.addEventListener('resize', function() {
if (currentActiveTab) {
positionSlider(currentActiveTab);
}
// If no tab is active during resize, the CSS :has rule keeps the slider hidden.
});
});
").append(message.data);
$('.megamenu_submit').after(error);
} else {
if (message.indexOf("exhausted") >= 0) {
var error = $("
").append(message);
} else {
var error = $("
").append(message);
}
$('.megamenu_submit').after(error);
}
},
error: function(message) {
if(message.status == 500) { // 500 error with no response from server
var error = $("