This commit is contained in:
Javier Casares 2026-11-03 17:04:31 +00:00
commit 0ec665db60

View file

@ -13,43 +13,10 @@
* Initialize the admin panel
*/
function init() {
initTabs();
initCollapsibleCards();
initSearch();
initStats();
initTooltips();
initMethodDependentFields();
}
/**
* Initialize tabs functionality
*/
function initTabs() {
$( '.noindex-seo-tab' ).on(
'click',
function (e) {
e.preventDefault();
const tabId = $( this ).data( 'tab' );
// Update active tab.
$( '.noindex-seo-tab' ).removeClass( 'active' );
$( this ).addClass( 'active' );
// Update active content.
$( '.noindex-seo-tab-content' ).removeClass( 'active' );
$( '#' + tabId ).addClass( 'active' );
// Save last active tab to localStorage.
localStorage.setItem( 'noindexSeoActiveTab', tabId );
}
);
// Restore last active tab.
const lastTab = localStorage.getItem( 'noindexSeoActiveTab' );
if (lastTab && $( '#' + lastTab ).length) {
$( '.noindex-seo-tab[data-tab="' + lastTab + '"]' ).click();
}
}
/**
@ -163,63 +130,6 @@
// Can be enhanced with a tooltip library if needed.
}
/**
* Initialize method-dependent field states
* Some fields only work with HTTP headers, not HTML meta tags
*/
function initMethodDependentFields() {
const methodSelect = $( '#noindex_seo_config_method' );
if (methodSelect.length === 0) {
return;
}
/**
* Update field states based on selected implementation method
*/
function updateFieldStates() {
const method = methodSelect.val();
const isHeaderEnabled = (method === 'header' || method === 'both');
// Contexts that ONLY work with HTTP headers (non-HTML content).
const headerOnlyContexts = [
'attachment', // Attachment pages (may contain PDFs, images, etc.).
'feed', // RSS/Atom feeds (XML, not HTML).
'comment_feed' // Comment feeds (XML, not HTML).
];
headerOnlyContexts.forEach(
function (context) {
// Find all directive checkboxes for this context.
const directiveCheckboxes = $( 'input[name$="_seo_' + context + '"]' );
const option = directiveCheckboxes.first().closest( '.noindex-seo-option' );
if ( ! isHeaderEnabled) {
// Disable all directives for this context.
directiveCheckboxes.prop( 'disabled', true );
directiveCheckboxes.prop( 'checked', false );
option.addClass( 'disabled' );
option.attr( 'title', 'This option only works with HTTP Headers implementation method' );
} else {
// Enable all directives for this context.
directiveCheckboxes.prop( 'disabled', false );
option.removeClass( 'disabled' );
option.removeAttr( 'title' );
}
}
);
// Update stats after changing field states.
updateStats();
}
// Listen for method changes.
methodSelect.on( 'change', updateFieldStates );
// Execute on page load.
updateFieldStates();
}
/**
* Expand all cards
*/
@ -325,9 +235,15 @@
if (urlParams.get( 'updated' ) === 'true') {
showSuccessMessage( noindexSeoAdmin.successMessage || 'Settings saved successfully!' );
// Remove the parameter from URL without reload.
const newUrl = window.location.pathname + window.location.hash;
window.history.replaceState( {}, document.title, newUrl );
// Remove only the success flag, keeping the page and tab
// parameters intact (tabs are URL-based since 3.3.0).
urlParams.delete( 'updated' );
const remaining = urlParams.toString();
window.history.replaceState(
{},
document.title,
window.location.pathname + ( remaining ? '?' + remaining : '' )
);
}
}
);