v3.0.3
This commit is contained in:
parent
57b74446bd
commit
1aa9f3ba2d
2 changed files with 7513 additions and 0 deletions
341
assets/js/admin.js
Normal file
341
assets/js/admin.js
Normal file
|
|
@ -0,0 +1,341 @@
|
|||
/**
|
||||
* 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() {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
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 = '<div class="noindex-seo-success">' +
|
||||
'<span class="dashicons dashicons-yes-alt"></span>' +
|
||||
'<p>' + message + '</p>' +
|
||||
'</div>';
|
||||
|
||||
$( '.noindex-seo-admin-wrap' ).prepend( successHtml );
|
||||
|
||||
// Auto-hide after 5 seconds.
|
||||
setTimeout(
|
||||
function () {
|
||||
$( '.noindex-seo-success' ).fadeOut(
|
||||
function () {
|
||||
$( this ).remove();
|
||||
}
|
||||
);
|
||||
},
|
||||
5000
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Highlight changes
|
||||
*/
|
||||
function highlightChanges() {
|
||||
$( 'input[type="checkbox"]' ).on(
|
||||
'change',
|
||||
function () {
|
||||
const option = $( this ).closest( '.noindex-seo-option' );
|
||||
option.addClass( 'noindex-seo-changed' );
|
||||
|
||||
setTimeout(
|
||||
function () {
|
||||
option.removeClass( 'noindex-seo-changed' );
|
||||
},
|
||||
2000
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add keyboard shortcuts
|
||||
*/
|
||||
function initKeyboardShortcuts() {
|
||||
$( document ).on(
|
||||
'keydown',
|
||||
function (e) {
|
||||
// Ctrl/Cmd + S to save.
|
||||
if ((e.ctrlKey || e.metaKey) && e.key === 's') {
|
||||
e.preventDefault();
|
||||
$( 'form' ).submit();
|
||||
}
|
||||
|
||||
// Ctrl/Cmd + F to focus search.
|
||||
if ((e.ctrlKey || e.metaKey) && e.key === 'f') {
|
||||
if ($( '.noindex-seo-search input' ).length) {
|
||||
e.preventDefault();
|
||||
$( '.noindex-seo-search input' ).focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize all features when DOM is ready
|
||||
*/
|
||||
$( document ).ready(
|
||||
function () {
|
||||
init();
|
||||
highlightChanges();
|
||||
initKeyboardShortcuts();
|
||||
|
||||
// Check for success parameter in URL.
|
||||
const urlParams = new URLSearchParams( window.location.search );
|
||||
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 );
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// Expose functions globally for potential external use.
|
||||
window.noindexSeoAdmin = window.noindexSeoAdmin || {};
|
||||
window.noindexSeoAdmin.expandAll = expandAll;
|
||||
window.noindexSeoAdmin.collapseAll = collapseAll;
|
||||
window.noindexSeoAdmin.updateStats = updateStats;
|
||||
|
||||
})( jQuery );
|
||||
271
assets/js/editor-sidebar.js
Normal file
271
assets/js/editor-sidebar.js
Normal file
|
|
@ -0,0 +1,271 @@
|
|||
/**
|
||||
* Noindex SEO - Gutenberg Sidebar Panel
|
||||
* Version: 2.0.0
|
||||
*
|
||||
* Provides a native Gutenberg sidebar panel for controlling robots directives
|
||||
* on individual posts and pages.
|
||||
*
|
||||
* @package noindex-seo
|
||||
*/
|
||||
|
||||
(function (wp) {
|
||||
const { registerPlugin } = wp.plugins;
|
||||
const { PluginDocumentSettingPanel } = wp.editPost;
|
||||
const { CheckboxControl, PanelRow } = wp.components;
|
||||
const { useSelect, useDispatch } = wp.data;
|
||||
const { createElement: el } = wp.element;
|
||||
const { __ } = wp.i18n;
|
||||
|
||||
/**
|
||||
* Robots Directives Sidebar Panel Component
|
||||
*/
|
||||
const NoindexSeoSidebarPanel = function () {
|
||||
// Get current post meta values.
|
||||
const postMeta = useSelect(
|
||||
function (select) {
|
||||
return select( 'core/editor' ).getEditedPostAttribute( 'meta' ) || {};
|
||||
}
|
||||
);
|
||||
|
||||
const { editPost } = useDispatch( 'core/editor' );
|
||||
|
||||
// Current values.
|
||||
const override = Boolean( postMeta._noindex_seo_override );
|
||||
const noindex = Boolean( postMeta._noindex_seo_noindex );
|
||||
const nofollow = Boolean( postMeta._noindex_seo_nofollow );
|
||||
const noarchive = Boolean( postMeta._noindex_seo_noarchive );
|
||||
const nosnippet = Boolean( postMeta._noindex_seo_nosnippet );
|
||||
const noimageindex = Boolean( postMeta._noindex_seo_noimageindex );
|
||||
|
||||
// Update meta function.
|
||||
const updateMeta = function (key, value) {
|
||||
const newMeta = {};
|
||||
newMeta[key] = value ? 1 : 0;
|
||||
editPost( { meta: newMeta } );
|
||||
};
|
||||
|
||||
// Clear all directive meta values.
|
||||
const clearAllDirectives = function () {
|
||||
const directives = ['noindex', 'nofollow', 'noarchive', 'nosnippet', 'noimageindex'];
|
||||
directives.forEach(
|
||||
function (directive) {
|
||||
updateMeta( '_noindex_seo_' + directive, false );
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
// Handle override toggle.
|
||||
const handleOverrideChange = function (value) {
|
||||
updateMeta( '_noindex_seo_override', value );
|
||||
|
||||
// If disabling override, clear all directives.
|
||||
if ( ! value) {
|
||||
clearAllDirectives();
|
||||
}
|
||||
};
|
||||
|
||||
// Get active directives for preview.
|
||||
const activeDirectives = [];
|
||||
if (override) {
|
||||
if (noindex) {
|
||||
activeDirectives.push( 'noindex' );
|
||||
}
|
||||
if (nofollow) {
|
||||
activeDirectives.push( 'nofollow' );
|
||||
}
|
||||
if (noarchive) {
|
||||
activeDirectives.push( 'noarchive' );
|
||||
}
|
||||
if (nosnippet) {
|
||||
activeDirectives.push( 'nosnippet' );
|
||||
}
|
||||
if (noimageindex) {
|
||||
activeDirectives.push( 'noimageindex' );
|
||||
}
|
||||
}
|
||||
|
||||
return el(
|
||||
PluginDocumentSettingPanel,
|
||||
{
|
||||
name: 'noindex-seo-panel',
|
||||
title: __( 'Search Engine Visibility', 'noindex-seo' ),
|
||||
icon: 'visibility',
|
||||
},
|
||||
[
|
||||
// Override checkbox.
|
||||
el(
|
||||
PanelRow,
|
||||
{ key: 'override-row' },
|
||||
el(
|
||||
CheckboxControl,
|
||||
{
|
||||
label: __( 'Override global settings', 'noindex-seo' ),
|
||||
help: __( 'Enable to set custom robots directives for this content', 'noindex-seo' ),
|
||||
checked: override,
|
||||
onChange: handleOverrideChange,
|
||||
}
|
||||
)
|
||||
),
|
||||
|
||||
// Directives (shown only if override is enabled).
|
||||
override && el(
|
||||
'div',
|
||||
{
|
||||
key: 'directives-container',
|
||||
style: {
|
||||
borderTop: '1px solid #ddd',
|
||||
paddingTop: '16px',
|
||||
marginTop: '8px',
|
||||
}
|
||||
},
|
||||
[
|
||||
el(
|
||||
'p',
|
||||
{
|
||||
key: 'directives-label',
|
||||
style: {
|
||||
fontSize: '12px',
|
||||
fontWeight: '600',
|
||||
marginBottom: '12px',
|
||||
color: '#1e1e1e',
|
||||
}
|
||||
},
|
||||
__( 'Robots Directives:', 'noindex-seo' )
|
||||
),
|
||||
|
||||
el(
|
||||
PanelRow,
|
||||
{ key: 'noindex-row' },
|
||||
el(
|
||||
CheckboxControl,
|
||||
{
|
||||
label: '🔍 ' + __( 'noindex', 'noindex-seo' ),
|
||||
help: __( 'Prevent search engines from indexing', 'noindex-seo' ),
|
||||
checked: noindex,
|
||||
onChange: function (value) {
|
||||
updateMeta( '_noindex_seo_noindex', value ); },
|
||||
}
|
||||
)
|
||||
),
|
||||
|
||||
el(
|
||||
PanelRow,
|
||||
{ key: 'nofollow-row' },
|
||||
el(
|
||||
CheckboxControl,
|
||||
{
|
||||
label: '🔗 ' + __( 'nofollow', 'noindex-seo' ),
|
||||
help: __( 'Prevent search engines from following links', 'noindex-seo' ),
|
||||
checked: nofollow,
|
||||
onChange: function (value) {
|
||||
updateMeta( '_noindex_seo_nofollow', value ); },
|
||||
}
|
||||
)
|
||||
),
|
||||
|
||||
el(
|
||||
PanelRow,
|
||||
{ key: 'noarchive-row' },
|
||||
el(
|
||||
CheckboxControl,
|
||||
{
|
||||
label: '💾 ' + __( 'noarchive', 'noindex-seo' ),
|
||||
help: __( 'Prevent cached versions in search results', 'noindex-seo' ),
|
||||
checked: noarchive,
|
||||
onChange: function (value) {
|
||||
updateMeta( '_noindex_seo_noarchive', value ); },
|
||||
}
|
||||
)
|
||||
),
|
||||
|
||||
el(
|
||||
PanelRow,
|
||||
{ key: 'nosnippet-row' },
|
||||
el(
|
||||
CheckboxControl,
|
||||
{
|
||||
label: '📄 ' + __( 'nosnippet', 'noindex-seo' ),
|
||||
help: __( 'Prevent text snippets in search results', 'noindex-seo' ),
|
||||
checked: nosnippet,
|
||||
onChange: function (value) {
|
||||
updateMeta( '_noindex_seo_nosnippet', value ); },
|
||||
}
|
||||
)
|
||||
),
|
||||
|
||||
el(
|
||||
PanelRow,
|
||||
{ key: 'noimageindex-row' },
|
||||
el(
|
||||
CheckboxControl,
|
||||
{
|
||||
label: '🖼️ ' + __( 'noimageindex', 'noindex-seo' ),
|
||||
help: __( 'Prevent image indexing', 'noindex-seo' ),
|
||||
checked: noimageindex,
|
||||
onChange: function (value) {
|
||||
updateMeta( '_noindex_seo_noimageindex', value ); },
|
||||
}
|
||||
)
|
||||
),
|
||||
|
||||
// Preview section.
|
||||
activeDirectives.length > 0 && el(
|
||||
'div',
|
||||
{
|
||||
key: 'preview-section',
|
||||
style: {
|
||||
marginTop: '16px',
|
||||
padding: '12px',
|
||||
background: '#f0f6fc',
|
||||
border: '1px solid #0969da',
|
||||
borderRadius: '4px',
|
||||
}
|
||||
},
|
||||
[
|
||||
el(
|
||||
'p',
|
||||
{
|
||||
key: 'preview-label',
|
||||
style: {
|
||||
fontSize: '11px',
|
||||
fontWeight: '600',
|
||||
marginBottom: '8px',
|
||||
color: '#0969da',
|
||||
textTransform: 'uppercase',
|
||||
}
|
||||
},
|
||||
__( 'Active Directives:', 'noindex-seo' )
|
||||
),
|
||||
el(
|
||||
'code',
|
||||
{
|
||||
key: 'preview-code',
|
||||
style: {
|
||||
fontSize: '12px',
|
||||
display: 'block',
|
||||
padding: '8px',
|
||||
background: '#fff',
|
||||
border: '1px solid #d0d7de',
|
||||
borderRadius: '3px',
|
||||
wordBreak: 'break-word',
|
||||
}
|
||||
},
|
||||
activeDirectives.join( ', ' )
|
||||
)
|
||||
]
|
||||
)
|
||||
]
|
||||
)
|
||||
]
|
||||
);
|
||||
};
|
||||
|
||||
// Register the plugin.
|
||||
registerPlugin(
|
||||
'noindex-seo-sidebar',
|
||||
{
|
||||
render: NoindexSeoSidebarPanel,
|
||||
}
|
||||
);
|
||||
|
||||
})( window.wp );
|
||||
Loading…
Reference in a new issue