Initial import of 404 Enhacer

This commit is contained in:
2026-11-16 12:24:05 -05:00
commit cf03c388c3
15 changed files with 1724 additions and 0 deletions
+143
View File
@@ -0,0 +1,143 @@
/* 404 Enhancer front-end styles. Scoped under .fe-404 to avoid theme collisions. */
.fe-404 {
max-width: 1100px;
margin: 0 auto;
padding: 2rem 1.25rem 4rem;
}
.fe-sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
/* Hero */
.fe-404-hero {
display: flex;
flex-wrap: wrap;
gap: 2rem;
align-items: center;
margin-bottom: 3rem;
}
.fe-404-hero-image {
flex: 0 1 320px;
}
.fe-404-hero-image img {
max-width: 100%;
height: auto;
display: block;
}
.fe-404-hero-text {
flex: 1 1 320px;
}
.fe-404-heading {
margin-top: 0;
}
.fe-404-requested code {
background: rgba(0, 0, 0, 0.06);
padding: 0.1em 0.4em;
border-radius: 3px;
word-break: break-all;
}
.fe-404-message {
margin: 1rem 0;
}
/* Search form */
.fe-search-form {
display: flex;
gap: 0.5rem;
max-width: 480px;
margin: 1.25rem 0 0.5rem;
}
.fe-search-form input[type="search"] {
flex: 1;
min-width: 0;
padding: 0.5rem 0.75rem;
}
.fe-search-form button {
padding: 0.5rem 1.25rem;
cursor: pointer;
}
.fe-did-you-mean {
font-style: italic;
}
/* Sections and cards */
.fe-section {
margin-bottom: 2.5rem;
}
.fe-section-title {
margin-bottom: 1rem;
}
.fe-card-grid {
list-style: none;
margin: 0;
padding: 0;
display: grid;
grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
gap: 1rem;
}
.fe-card {
border: 1px solid rgba(0, 0, 0, 0.12);
border-radius: 6px;
overflow: hidden;
transition: box-shadow 0.15s ease-in-out;
}
.fe-card:hover {
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
}
.fe-card-link {
display: block;
height: 100%;
color: inherit;
text-decoration: none;
}
.fe-card-thumb img {
width: 100%;
height: 140px;
object-fit: cover;
display: block;
}
.fe-card-body {
display: block;
padding: 0.75rem 1rem 1rem;
}
.fe-card-title {
display: block;
font-weight: 600;
margin-bottom: 0.35rem;
}
.fe-card-excerpt {
display: block;
font-size: 0.875em;
opacity: 0.8;
}
+106
View File
@@ -0,0 +1,106 @@
/* 404 Enhancer admin script: featured image picker + featured content AJAX picker. */
jQuery(document).ready(function ($) {
'use strict';
/* Featured image via the media library frame. */
var frame;
$('#fe-upload-btn').on('click', function (e) {
e.preventDefault();
if (!frame) {
frame = wp.media({
title: FEAdmin.i18n.chooseImage,
button: { text: FEAdmin.i18n.useImage },
library: { type: 'image' },
multiple: false
});
frame.on('select', function () {
var attachment = frame.state().get('selection').first().toJSON();
$('#fe_featured_image_id').val(attachment.id);
$('#fe-featured-preview').attr('src', attachment.url).show();
$('#fe-remove-btn').show();
});
}
frame.open();
});
$('#fe-remove-btn').on('click', function (e) {
e.preventDefault();
$('#fe_featured_image_id').val('');
$('#fe-featured-preview').attr('src', '').hide();
$(this).hide();
});
/* Featured content picker: debounced AJAX search + chips. */
var $search = $('#fe-post-search');
var $results = $('#fe-search-results');
var $list = $('#fe-featured-list');
var timer = null;
function selectedIds() {
return $list.find('li').map(function () { return String($(this).data('id')); }).get();
}
function addChip(post) {
if (-1 !== $.inArray(String(post.id), selectedIds())) {
return;
}
var $chip = $('<li class="fe-chip"></li>').attr('data-id', post.id);
$chip.append(document.createTextNode(post.title + ' '));
$chip.append($('<span class="fe-chip-type"></span>').text(post.type));
$chip.append($('<input type="hidden">').attr('name', 'fe_featured_post_ids[]').val(post.id));
$chip.append($('<button type="button" class="fe-chip-remove" aria-label="Remove">&times;</button>'));
$list.append($chip);
}
function renderResults(posts) {
$results.empty();
var ids = selectedIds();
var visible = posts.filter(function (p) { return -1 === $.inArray(String(p.id), ids); });
if (!visible.length) {
$results.append($('<li></li>').text(FEAdmin.i18n.noResults)).show();
return;
}
visible.forEach(function (post) {
var $item = $('<li></li>').append(
$('<button type="button" class="fe-result"></button>').text(post.title + ' (' + post.type + ')')
);
$item.find('button').on('click', function () {
addChip(post);
$search.val('');
$results.hide().empty();
});
$results.append($item);
});
$results.show();
}
$search.on('input', function () {
var term = $search.val();
clearTimeout(timer);
if (!term || term.length < 2) {
$results.hide().empty();
return;
}
timer = setTimeout(function () {
$.post(FEAdmin.ajaxUrl, {
action: FEAdmin.action,
nonce: FEAdmin.nonce,
s: term
}, function (response) {
if (response && response.success && response.data && response.data.posts) {
renderResults(response.data.posts);
}
});
}, 300);
});
$results.on('mousedown', function (e) { e.preventDefault(); }); // Keep input focus while clicking a result.
$(document).on('click', function (e) {
if (!$(e.target).closest('#fe-featured-picker').length) {
$results.hide();
}
});
$list.on('click', '.fe-chip-remove', function () {
$(this).closest('li').remove();
});
});