/** * 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(); initRules(); } /** * Initialize the conditional-rules table (add / remove rows) */ function initRules() { // Add rule: clone the last row and clear its inputs. $( '.noindex-seo-rule-add' ).on( 'click', function () { const $rows = $( '.noindex-seo-rule-rows' ); const max = parseInt( $rows.data( 'max-rules' ) || 20, 10 ); if ( $rows.find( '.noindex-seo-rule-row' ).length >= max ) { return; } const $clone = $rows.find( '.noindex-seo-rule-row' ).last().clone(); $clone.find( 'input' ).val( '' ); $rows.append( $clone ); } ); // Remove rule: drop the row, or clear it when it is the last one left. $( document ).on( 'click', '.noindex-seo-rule-remove', function () { const $row = $( this ).closest( '.noindex-seo-rule-row' ); const $rows = $( this ).closest( '.noindex-seo-rule-rows' ); if ( $rows.find( '.noindex-seo-rule-row' ).length > 1 ) { $row.remove(); } else { $row.find( 'input' ).val( '' ); } } ); } /** * 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 + '
' + '