/** * Noindex SEO - Admin Panel JavaScript * Version: 2.0.0 * Modern, interactive admin interface * * @package noindex-seo */ (function ($) { 'use strict'; /** * Initialize the admin panel */ function init() { initCollapsibleCards(); initSearch(); initStats(); initTooltips(); } /** * Initialize collapsible card sections */ function initCollapsibleCards() { $( '.noindex-seo-card-header' ).on( 'click', function () { const card = $( this ).closest( '.noindex-seo-card' ); card.toggleClass( 'collapsed' ); // Save collapsed state. const cardId = card.attr( 'id' ); const isCollapsed = card.hasClass( 'collapsed' ); let collapsedCards = {}; try { collapsedCards = JSON.parse( localStorage.getItem( 'noindexSeoCollapsed' ) || '{}' ); } catch (e) { // If localStorage is corrupted, reset to empty object. collapsedCards = {}; } collapsedCards[cardId] = isCollapsed; localStorage.setItem( 'noindexSeoCollapsed', JSON.stringify( collapsedCards ) ); } ); // Restore collapsed states. let collapsedCards = {}; try { collapsedCards = JSON.parse( localStorage.getItem( 'noindexSeoCollapsed' ) || '{}' ); } catch (e) { // If localStorage is corrupted, reset to empty object. collapsedCards = {}; } Object.keys( collapsedCards ).forEach( function (cardId) { if (collapsedCards[cardId]) { $( '#' + cardId ).addClass( 'collapsed' ); } } ); } /** * Initialize search/filter functionality */ function initSearch() { $( '.noindex-seo-search input' ).on( 'input', function () { const searchTerm = $( this ).val().toLowerCase(); $( '.noindex-seo-option' ).each( function () { const optionTitle = $( this ).find( '.noindex-seo-option-title' ).text().toLowerCase(); const optionDescription = $( this ).find( '.noindex-seo-option-description' ).text().toLowerCase(); const directivesText = $( this ).find( '.noindex-seo-directives' ).text().toLowerCase(); const combinedText = optionTitle + ' ' + optionDescription + ' ' + directivesText; const isMatch = combinedText.indexOf( searchTerm ) > -1; $( this ).toggle( isMatch ); } ); // Show/hide empty cards. $( '.noindex-seo-card' ).each( function () { const visibleOptions = $( this ).find( '.noindex-seo-option:visible' ).length; $( this ).toggle( visibleOptions > 0 ); } ); } ); } /** * Update statistics counters */ function initStats() { updateStats(); // Update stats when toggles change. $( 'input[type="checkbox"]' ).on( 'change', function () { updateStats(); } ); } /** * Update statistics display */ function updateStats() { const totalContexts = $( '.noindex-seo-option' ).not( '.disabled' ).length; const enabledCount = $( '.noindex-seo-directive-checkbox input[type="checkbox"]:checked' ).not( ':disabled' ).length; const totalDirectives = $( '.noindex-seo-directive-checkbox input[type="checkbox"]' ).not( ':disabled' ).length; $( '#noindex-seo-stat-total' ).text( totalDirectives ); $( '#noindex-seo-stat-enabled' ).text( enabledCount ); $( '#noindex-seo-stat-recommended' ).text( totalContexts ); } /** * Initialize tooltips (using native browser tooltips for now) */ function initTooltips() { // Tooltips are handled by title attributes. // Can be enhanced with a tooltip library if needed. } /** * Expand all cards */ function expandAll() { $( '.noindex-seo-card' ).removeClass( 'collapsed' ); localStorage.removeItem( 'noindexSeoCollapsed' ); } /** * Collapse all cards */ function collapseAll() { $( '.noindex-seo-card' ).addClass( 'collapsed' ); const collapsedCards = {}; $( '.noindex-seo-card' ).each( function () { collapsedCards[$( this ).attr( 'id' )] = true; } ); localStorage.setItem( 'noindexSeoCollapsed', JSON.stringify( collapsedCards ) ); } /** * Show success message */ function showSuccessMessage(message) { const successHtml = '
' + message + '
' + '