pagination curseur, layout 3 colonnes article, sidebar fixe
This commit is contained in:
+433
-4
@@ -115,13 +115,35 @@ body {
|
||||
background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%2830%2C41%2C59%2C0.75%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
|
||||
}
|
||||
|
||||
/* ─── Category nav in navbar ─────────────── */
|
||||
.navbar-cats {
|
||||
gap: 0.15rem;
|
||||
}
|
||||
|
||||
.nav-cat {
|
||||
font-size: 0.8rem !important;
|
||||
padding: 0.25rem 0.6rem !important;
|
||||
border-radius: 2rem !important;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.nav-cat.active {
|
||||
background-color: var(--vl-accent) !important;
|
||||
color: #fff !important;
|
||||
}
|
||||
|
||||
/* ─── Main ───────────────────────────────── */
|
||||
main.container {
|
||||
max-width: 980px;
|
||||
main.container,
|
||||
main.container-xl,
|
||||
main.container-fluid {
|
||||
padding-top: 2rem;
|
||||
padding-bottom: 3rem;
|
||||
}
|
||||
|
||||
main.container {
|
||||
max-width: 980px;
|
||||
}
|
||||
|
||||
/* ─── Headings ───────────────────────────── */
|
||||
h1 {
|
||||
font-weight: 700;
|
||||
@@ -170,6 +192,139 @@ a:hover {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.article-cover--gradient {
|
||||
height: 160px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
/* Hero : titre sur l'image */
|
||||
.article-cover--hero {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.article-cover--hero img {
|
||||
height: clamp(260px, 45vw, 480px);
|
||||
}
|
||||
|
||||
.article-cover--hero.article-cover--gradient {
|
||||
height: clamp(200px, 35vw, 340px);
|
||||
}
|
||||
|
||||
.article-hero-text {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
padding: 0.9rem 1.4rem 1.25rem;
|
||||
background: linear-gradient(
|
||||
to top,
|
||||
rgba(0,0,0,.80) 0%,
|
||||
rgba(0,0,0,.32) 50%,
|
||||
transparent 100%
|
||||
);
|
||||
}
|
||||
|
||||
.article-hero-top {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 0.4rem;
|
||||
align-items: flex-start;
|
||||
min-height: 2rem;
|
||||
}
|
||||
|
||||
.article-hero-bottom {
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.article-hero-left { flex: 1; min-width: 0; }
|
||||
|
||||
.article-hero-right {
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-end;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.article-hero-text .cover-category {
|
||||
position: static;
|
||||
align-self: flex-start;
|
||||
margin-bottom: 0.55rem;
|
||||
}
|
||||
|
||||
.article-hero-text .article-title {
|
||||
color: #fff;
|
||||
text-shadow: 0 1px 8px rgba(0,0,0,.5);
|
||||
margin-bottom: 0.3rem;
|
||||
}
|
||||
|
||||
.article-hero-meta {
|
||||
font-size: 0.82rem;
|
||||
color: rgba(255,255,255,.72);
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* Boutons glass sur le hero */
|
||||
.hero-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
padding: 0.28rem 0.75rem;
|
||||
font-size: 0.73rem;
|
||||
font-weight: 600;
|
||||
color: #fff !important;
|
||||
background: rgba(0,0,0,.35);
|
||||
border: 1px solid rgba(255,255,255,.22);
|
||||
border-radius: 999px;
|
||||
backdrop-filter: blur(8px);
|
||||
-webkit-backdrop-filter: blur(8px);
|
||||
text-decoration: none !important;
|
||||
cursor: pointer;
|
||||
transition: background 0.15s;
|
||||
white-space: nowrap;
|
||||
line-height: 1.4;
|
||||
}
|
||||
.hero-btn:hover { background: rgba(0,0,0,.58); color: #fff !important; }
|
||||
.hero-btn--danger { border-color: rgba(239,68,68,.5); }
|
||||
.hero-btn--danger:hover { background: rgba(180,30,30,.65); }
|
||||
|
||||
/* Score de notation dans le hero */
|
||||
.hero-rating-score {
|
||||
font-size: 0.8rem;
|
||||
font-weight: 600;
|
||||
color: rgba(255,255,255,.88);
|
||||
}
|
||||
|
||||
/* Étoiles sur fond sombre */
|
||||
.star-rating--hero label { color: rgba(255,255,255,.4); font-size: 1.1rem; }
|
||||
.star-rating--hero input:checked ~ label,
|
||||
.star-rating--hero label:hover,
|
||||
.star-rating--hero label:hover ~ label { color: #f5c842; }
|
||||
|
||||
.card-cover {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.cover-category {
|
||||
position: absolute;
|
||||
bottom: 0.6rem;
|
||||
left: 0.75rem;
|
||||
font-size: 0.65rem;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.1em;
|
||||
text-transform: uppercase;
|
||||
color: #fff;
|
||||
background: rgba(0, 0, 0, 0.28);
|
||||
padding: 0.2rem 0.55rem;
|
||||
border-radius: 999px;
|
||||
backdrop-filter: blur(6px);
|
||||
-webkit-backdrop-filter: blur(6px);
|
||||
}
|
||||
|
||||
.card {
|
||||
border: 1px solid var(--vl-border) !important;
|
||||
border-radius: var(--vl-radius) !important;
|
||||
@@ -195,6 +350,15 @@ a:hover {
|
||||
color: var(--vl-text);
|
||||
}
|
||||
|
||||
.article-title {
|
||||
font-weight: 800;
|
||||
font-size: clamp(1.6rem, 4vw, 2.4rem);
|
||||
line-height: 1.2;
|
||||
letter-spacing: -0.5px;
|
||||
color: var(--vl-text);
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
/* Override la couleur text-primary Bootstrap sur les card-title */
|
||||
.card-title.text-primary {
|
||||
color: var(--vl-text) !important;
|
||||
@@ -226,7 +390,8 @@ a:hover {
|
||||
|
||||
/* ─── Ribbons (brouillon / avant-première) ── */
|
||||
.draft-ribbon,
|
||||
.premiere-ribbon {
|
||||
.premiere-ribbon,
|
||||
.private-ribbon {
|
||||
position: absolute;
|
||||
top: 26px;
|
||||
right: -34px;
|
||||
@@ -244,8 +409,9 @@ a:hover {
|
||||
box-shadow: 0 1px 3px rgba(0,0,0,.18);
|
||||
}
|
||||
|
||||
.draft-ribbon { background: #f59e0b; }
|
||||
.draft-ribbon { background: #f59e0b; }
|
||||
.premiere-ribbon { background: #6366f1; }
|
||||
.private-ribbon { background: #64748b; }
|
||||
|
||||
/* ─── Buttons ─────────────────────────────── */
|
||||
.btn {
|
||||
@@ -349,6 +515,195 @@ textarea.form-control {
|
||||
color: #991b1b;
|
||||
}
|
||||
|
||||
/* ─── Left category sidebar ──────────────── */
|
||||
.left-sidebar {
|
||||
position: sticky;
|
||||
top: 1.5rem;
|
||||
}
|
||||
|
||||
.left-sidebar-section {
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.left-sidebar-cat {
|
||||
display: block;
|
||||
font-size: 0.7rem;
|
||||
font-weight: 700;
|
||||
letter-spacing: .08em;
|
||||
text-transform: uppercase;
|
||||
color: var(--vl-muted);
|
||||
text-decoration: none;
|
||||
margin-bottom: 0.4rem;
|
||||
padding: 0.2rem 0.5rem;
|
||||
border-radius: 0.4rem;
|
||||
transition: background 0.15s, color 0.15s;
|
||||
}
|
||||
|
||||
.left-sidebar-cat:hover {
|
||||
background: var(--vl-accent-soft);
|
||||
color: var(--vl-accent);
|
||||
}
|
||||
|
||||
.left-sidebar-list {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.left-sidebar-list li {
|
||||
border-left: 2px solid var(--vl-border);
|
||||
padding-left: 0.6rem;
|
||||
margin-bottom: 0.3rem;
|
||||
}
|
||||
|
||||
.left-sidebar-list li a {
|
||||
font-size: 0.8rem;
|
||||
line-height: 1.35;
|
||||
color: var(--vl-text);
|
||||
text-decoration: none;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
transition: color 0.15s;
|
||||
}
|
||||
|
||||
.left-sidebar-list li a:hover {
|
||||
color: var(--vl-accent);
|
||||
}
|
||||
|
||||
/* ─── Related articles sidebar ───────────── */
|
||||
.related-sidebar {
|
||||
position: sticky;
|
||||
top: 1.5rem;
|
||||
}
|
||||
|
||||
/* ─── Post layout: colonnes sidebar fixe + article flexible ── */
|
||||
@media (min-width: 992px) {
|
||||
.post-sidebar-col {
|
||||
flex: 0 0 260px;
|
||||
width: 260px;
|
||||
max-width: 260px;
|
||||
}
|
||||
}
|
||||
|
||||
.related-sidebar-title {
|
||||
font-size: 0.7rem;
|
||||
font-weight: 700;
|
||||
letter-spacing: .08em;
|
||||
text-transform: uppercase;
|
||||
color: var(--vl-muted);
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.related-card {
|
||||
display: flex;
|
||||
gap: 0.75rem;
|
||||
align-items: flex-start;
|
||||
text-decoration: none;
|
||||
color: var(--vl-text);
|
||||
padding: 0.65rem;
|
||||
border-radius: var(--vl-radius);
|
||||
transition: background 0.15s;
|
||||
margin-bottom: 0.25rem;
|
||||
}
|
||||
|
||||
.related-card:hover {
|
||||
background: var(--vl-accent-soft);
|
||||
color: var(--vl-accent);
|
||||
}
|
||||
|
||||
.related-card-thumb {
|
||||
width: 64px;
|
||||
height: 52px;
|
||||
border-radius: 0.5rem;
|
||||
flex-shrink: 0;
|
||||
background-size: cover;
|
||||
background-position: center;
|
||||
}
|
||||
|
||||
.related-card-body {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.related-card-title {
|
||||
font-size: 0.875rem;
|
||||
font-weight: 600;
|
||||
line-height: 1.35;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.related-card-date {
|
||||
font-size: 0.75rem;
|
||||
color: var(--vl-muted);
|
||||
margin-top: 0.2rem;
|
||||
}
|
||||
|
||||
/* ─── Source / attachment cards (sidebar) ── */
|
||||
.source-card {
|
||||
display: flex;
|
||||
gap: 0.65rem;
|
||||
align-items: flex-start;
|
||||
text-decoration: none;
|
||||
color: var(--vl-text);
|
||||
padding: 0.5rem 0.65rem;
|
||||
border-radius: var(--vl-radius);
|
||||
border: 1px solid var(--vl-border);
|
||||
background: var(--vl-surface);
|
||||
transition: border-color 0.15s, box-shadow 0.15s;
|
||||
}
|
||||
|
||||
.source-card:hover {
|
||||
border-color: var(--vl-accent);
|
||||
box-shadow: 0 0 0 3px rgba(79,70,229,.08);
|
||||
color: var(--vl-accent);
|
||||
}
|
||||
|
||||
.source-card-thumb {
|
||||
width: 52px;
|
||||
height: 42px;
|
||||
border-radius: 0.4rem;
|
||||
flex-shrink: 0;
|
||||
background-color: var(--vl-accent-soft);
|
||||
}
|
||||
|
||||
.source-card-thumb--pdf,
|
||||
.source-card-thumb--link {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 1.2rem;
|
||||
color: var(--vl-accent);
|
||||
}
|
||||
|
||||
.source-card-body {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.source-card-title {
|
||||
font-size: 0.82rem;
|
||||
font-weight: 600;
|
||||
line-height: 1.3;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.source-card-meta {
|
||||
font-size: 0.72rem;
|
||||
color: var(--vl-muted);
|
||||
margin-top: 0.2rem;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
/* ─── Post content (Markdown rendu) ──────── */
|
||||
.post-content {
|
||||
font-size: 1rem;
|
||||
@@ -554,6 +909,56 @@ footer {
|
||||
opacity: 0.75;
|
||||
}
|
||||
|
||||
/* ─── Pagination ─────────────────────────── */
|
||||
.pagination-nav {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.3rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.pagination-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-width: 2.2rem;
|
||||
height: 2.2rem;
|
||||
padding: 0 0.5rem;
|
||||
border-radius: 0.5rem;
|
||||
border: 1px solid var(--vl-border);
|
||||
background: var(--vl-surface);
|
||||
color: var(--vl-text);
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
text-decoration: none;
|
||||
transition: border-color 0.15s, background 0.15s, color 0.15s;
|
||||
}
|
||||
|
||||
.pagination-btn:hover:not(.disabled):not(.active) {
|
||||
border-color: var(--vl-accent);
|
||||
color: var(--vl-accent);
|
||||
background: var(--vl-accent-soft);
|
||||
}
|
||||
|
||||
.pagination-btn.active {
|
||||
background: var(--vl-accent);
|
||||
border-color: var(--vl-accent);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.pagination-btn.disabled {
|
||||
opacity: 0.35;
|
||||
cursor: default;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.pagination-ellipsis {
|
||||
padding: 0 0.25rem;
|
||||
color: var(--vl-muted);
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
/* ─── Footer 2 colonnes ──────────────────── */
|
||||
footer {
|
||||
border-top: 1px solid var(--vl-border);
|
||||
@@ -639,3 +1044,27 @@ footer {
|
||||
.text-primary {
|
||||
color: var(--vl-accent) !important;
|
||||
}
|
||||
|
||||
/* ─── Widget étoiles ──────────────────────── */
|
||||
.star-rating {
|
||||
display: inline-flex;
|
||||
flex-direction: row-reverse;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.star-rating input {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.star-rating label {
|
||||
font-size: 1.4rem;
|
||||
color: #ccc;
|
||||
cursor: pointer;
|
||||
transition: color 0.1s;
|
||||
}
|
||||
|
||||
.star-rating input:checked ~ label,
|
||||
.star-rating label:hover,
|
||||
.star-rating label:hover ~ label {
|
||||
color: #f5a623;
|
||||
}
|
||||
|
||||
+420
-2
@@ -2,7 +2,7 @@
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
|
||||
// Auto-resize textarea au chargement et à la saisie
|
||||
// ─── Auto-resize textareas ───────────────────────────────────────────────
|
||||
document.querySelectorAll('textarea.form-control').forEach(function (ta) {
|
||||
function resize() {
|
||||
ta.style.height = 'auto';
|
||||
@@ -12,7 +12,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
resize();
|
||||
});
|
||||
|
||||
// Ctrl+Enter (ou Cmd+Enter) pour soumettre le formulaire de post
|
||||
// ─── Ctrl+Enter : soumettre le formulaire ────────────────────────────────
|
||||
var form = document.querySelector('form[method="POST"]');
|
||||
if (form) {
|
||||
form.addEventListener('keydown', function (e) {
|
||||
@@ -22,4 +22,422 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
});
|
||||
}
|
||||
|
||||
// ─── Slug auto-génération ────────────────────────────────────────────────
|
||||
const titleInput = document.getElementById('title');
|
||||
const slugField = document.getElementById('slug');
|
||||
const slugPreview = document.getElementById('slug-preview');
|
||||
|
||||
if (titleInput && slugField) {
|
||||
if (slugField.value !== '') slugField._auto = false;
|
||||
|
||||
titleInput.addEventListener('input', function () {
|
||||
if (slugField._auto !== false) {
|
||||
const generated = slugify(this.value);
|
||||
slugField.value = generated;
|
||||
if (slugPreview) slugPreview.textContent = generated;
|
||||
}
|
||||
});
|
||||
|
||||
slugField.addEventListener('input', function () {
|
||||
this._auto = (this.value === '');
|
||||
if (slugPreview) slugPreview.textContent = this.value;
|
||||
});
|
||||
}
|
||||
|
||||
function slugify(s) {
|
||||
const map = {'à':'a','â':'a','ä':'a','é':'e','è':'e','ê':'e','ë':'e','î':'i','ï':'i','ô':'o','ö':'o','ù':'u','û':'u','ü':'u','ç':'c','æ':'ae','œ':'oe'};
|
||||
return s.toLowerCase().replace(/[àâäéèêëîïôöùûüçæœ]/g, c => map[c] || c)
|
||||
.replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
|
||||
}
|
||||
|
||||
// ─── Aperçu couleur catégorie ────────────────────────────────────────────
|
||||
const KNOWN_CATS = {
|
||||
'actualité': 10, 'travaux': 35, 'scolaire': 55,
|
||||
'linux': 120, 'domotique': 160, 'télécom': 190,
|
||||
'blog': 220, 'informatique': 255, 'réflexion': 285,
|
||||
'loisirs': 320, 'perso': 345,
|
||||
};
|
||||
const FREE_HUES = [87, 140, 205, 237, 302];
|
||||
|
||||
function gradient(hue) {
|
||||
return `linear-gradient(135deg,hsl(${hue},70%,88%) 0%,hsl(${hue},60%,28%) 100%)`;
|
||||
}
|
||||
|
||||
function hashHue(str) {
|
||||
let h = 5381;
|
||||
for (let i = 0; i < str.length; i++) h = (((h << 5) + h) + str.charCodeAt(i)) | 0;
|
||||
return ((Math.abs(h) * 0.6180339887) * 360 | 0) % 360;
|
||||
}
|
||||
|
||||
function nearestKnown(hue) {
|
||||
let best = null, bestDist = Infinity;
|
||||
for (const [name, h] of Object.entries(KNOWN_CATS)) {
|
||||
const d = Math.min(Math.abs(hue - h), 360 - Math.abs(hue - h));
|
||||
if (d < bestDist) { bestDist = d; best = name; }
|
||||
}
|
||||
return { name: best, dist: bestDist };
|
||||
}
|
||||
|
||||
function updateCatPreview(val) {
|
||||
const key = val.trim().toLowerCase();
|
||||
const swatch = document.getElementById('cat-swatch');
|
||||
const hint = document.getElementById('cat-hint');
|
||||
const freeEl = document.getElementById('cat-free-swatches');
|
||||
if (!swatch) return;
|
||||
freeEl.innerHTML = '';
|
||||
|
||||
if (!key) {
|
||||
swatch.style.background = '#e5e7eb';
|
||||
swatch.title = '';
|
||||
hint.textContent = '';
|
||||
return;
|
||||
}
|
||||
|
||||
if (KNOWN_CATS[key] !== undefined) {
|
||||
const hue = KNOWN_CATS[key];
|
||||
swatch.style.background = gradient(hue);
|
||||
swatch.title = `${hue}°`;
|
||||
hint.textContent = `Catégorie existante · teinte fixe (${hue}°)`;
|
||||
hint.className = 'text-muted d-block mt-1';
|
||||
return;
|
||||
}
|
||||
|
||||
const hue = hashHue(key);
|
||||
const { name, dist } = nearestKnown(hue);
|
||||
|
||||
swatch.style.background = gradient(hue);
|
||||
swatch.title = `${hue}°`;
|
||||
|
||||
if (dist < 20) {
|
||||
hint.innerHTML = `⚠ Teinte proche de <strong>${name}</strong> (${dist}° d'écart) · couleurs disponibles :`;
|
||||
hint.className = 'text-warning d-block mt-1';
|
||||
FREE_HUES.forEach(h => {
|
||||
const el = document.createElement('span');
|
||||
el.title = `${h}°`;
|
||||
el.style.cssText = `display:inline-block;width:28px;height:20px;border-radius:4px;cursor:help;background:${gradient(h)}`;
|
||||
freeEl.appendChild(el);
|
||||
});
|
||||
} else {
|
||||
hint.textContent = `Nouvelle catégorie · teinte libre (${hue}°)`;
|
||||
hint.className = 'text-muted d-block mt-1';
|
||||
}
|
||||
}
|
||||
|
||||
const catInput = document.getElementById('category');
|
||||
if (catInput) {
|
||||
catInput.addEventListener('input', function () { updateCatPreview(this.value); });
|
||||
updateCatPreview(catInput.value);
|
||||
}
|
||||
|
||||
// ─── Copier la référence Markdown ────────────────────────────────────────
|
||||
document.querySelectorAll('[data-copy-md-name]').forEach(function (btn) {
|
||||
btn.addEventListener('click', function () {
|
||||
const name = this.dataset.copyMdName;
|
||||
const isImage = this.dataset.copyMdIsImage === '1';
|
||||
const ref = isImage ? `` : `[${name}](${name})`;
|
||||
navigator.clipboard.writeText(ref).then(() => {
|
||||
const orig = this.textContent;
|
||||
this.textContent = 'Copié !';
|
||||
setTimeout(() => { this.textContent = orig; }, 1500);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// ─── Boîtes de confirmation (suppression) ───────────────────────────────
|
||||
document.querySelectorAll('button[data-confirm], a[data-confirm]').forEach(function (el) {
|
||||
el.addEventListener('click', function (e) {
|
||||
if (!confirm(this.dataset.confirm)) e.preventDefault();
|
||||
});
|
||||
});
|
||||
document.querySelectorAll('form[data-confirm]').forEach(function (form) {
|
||||
form.addEventListener('submit', function (e) {
|
||||
if (!confirm(this.dataset.confirm)) e.preventDefault();
|
||||
});
|
||||
});
|
||||
|
||||
// ─── Insérer une référence Markdown au curseur ───────────────────────────
|
||||
const ta = document.getElementById('content');
|
||||
if (ta) {
|
||||
ta._savedStart = null;
|
||||
ta._savedEnd = null;
|
||||
|
||||
function saveCursor() {
|
||||
if (document.activeElement === ta) {
|
||||
ta._savedStart = ta.selectionStart;
|
||||
ta._savedEnd = ta.selectionEnd;
|
||||
}
|
||||
}
|
||||
document.addEventListener('mousedown', saveCursor);
|
||||
ta.addEventListener('keyup', saveCursor);
|
||||
ta.addEventListener('mouseup', saveCursor);
|
||||
|
||||
document.querySelectorAll('[data-insert-ref]').forEach(function (el) {
|
||||
el.addEventListener('click', function () {
|
||||
insertRef(this.dataset.insertRef);
|
||||
});
|
||||
if (el.tagName === 'IMG') {
|
||||
el.addEventListener('mouseenter', function () { this.style.borderColor = '#0d6efd'; });
|
||||
el.addEventListener('mouseleave', function () { this.style.borderColor = 'transparent'; });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function insertRef(url) {
|
||||
if (!ta) return;
|
||||
const isImage = /\.(jpe?g|png|gif|webp|svg|avif)(\?.*)?$/i.test(url);
|
||||
const label = url.startsWith('http')
|
||||
? (decodeURIComponent(url.split('/').pop().split('?')[0]) || url)
|
||||
: url;
|
||||
const ref = isImage ? `` : `[${label}](${url})`;
|
||||
const len = ta.value.length;
|
||||
const start = ta._savedStart !== null ? ta._savedStart : len;
|
||||
const end = ta._savedEnd !== null ? ta._savedEnd : len;
|
||||
ta.focus();
|
||||
ta.setRangeText(ref, start, end, 'end');
|
||||
ta._savedStart = ta._savedEnd = start + ref.length;
|
||||
ta.dispatchEvent(new Event('input'));
|
||||
}
|
||||
|
||||
// ─── Compteurs SEO ───────────────────────────────────────────────────────
|
||||
function initCounter(inputId, counterId, max) {
|
||||
const input = document.getElementById(inputId);
|
||||
const counter = document.getElementById(counterId);
|
||||
if (!input || !counter) return;
|
||||
function update() {
|
||||
const len = input.value.length;
|
||||
counter.textContent = `${len} / ${max}`;
|
||||
counter.className = len > max ? 'text-danger' : 'text-muted';
|
||||
}
|
||||
input.addEventListener('input', update);
|
||||
update();
|
||||
}
|
||||
initCounter('seo_title', 'seo_title_counter', 60);
|
||||
initCounter('seo_description', 'seo_desc_counter', 155);
|
||||
|
||||
// ─── Page catégories ─────────────────────────────────────────────────────
|
||||
function catComputeGradient(val) {
|
||||
const key = val.trim().toLowerCase();
|
||||
if (!key) return null;
|
||||
if (KNOWN_CATS[key] !== undefined) return { hue: KNOWN_CATS[key], known: true };
|
||||
const hue = hashHue(key);
|
||||
const { name, dist } = nearestKnown(hue);
|
||||
return { hue, known: false, conflict: dist < 20 ? name : null };
|
||||
}
|
||||
|
||||
document.querySelectorAll('form[action="/?action=rename_category"] input[name="new"]').forEach(function (input) {
|
||||
input.addEventListener('input', function () {
|
||||
const swatch = input.closest('form').querySelector('.rename-swatch');
|
||||
const result = catComputeGradient(input.value);
|
||||
if (swatch) swatch.style.background = result ? gradient(result.hue) : '#e5e7eb';
|
||||
});
|
||||
});
|
||||
|
||||
const newCatInput = document.getElementById('new-cat-input');
|
||||
if (newCatInput) {
|
||||
newCatInput.addEventListener('input', function () {
|
||||
const swatch = document.getElementById('new-cat-swatch');
|
||||
const hint = document.getElementById('new-cat-hint');
|
||||
const result = catComputeGradient(this.value);
|
||||
|
||||
if (!result) {
|
||||
swatch.style.background = '#e5e7eb';
|
||||
hint.textContent = '';
|
||||
return;
|
||||
}
|
||||
|
||||
swatch.style.background = gradient(result.hue);
|
||||
|
||||
if (result.known) {
|
||||
hint.textContent = `Catégorie existante · teinte fixe (${result.hue}°)`;
|
||||
hint.className = 'text-muted d-block mb-3';
|
||||
} else if (result.conflict) {
|
||||
hint.textContent = `⚠ Teinte proche de « ${result.conflict} » — choisissez un autre nom ou une couleur disponible ci-dessous`;
|
||||
hint.className = 'text-warning d-block mb-3';
|
||||
} else {
|
||||
hint.textContent = `Couleur libre · teinte ${result.hue}°`;
|
||||
hint.className = 'text-success d-block mb-3';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ─── Import image : récupérer les métadonnées ────────────────────────────
|
||||
const fetchMetaBtn = document.getElementById('fetch-meta-btn');
|
||||
if (fetchMetaBtn) {
|
||||
fetchMetaBtn.addEventListener('click', async function () {
|
||||
const urlInput = document.getElementById('import-url');
|
||||
const resultDiv = document.getElementById('meta-result');
|
||||
const url = urlInput ? urlInput.value.trim() : '';
|
||||
|
||||
if (!url) {
|
||||
resultDiv.innerHTML = '<small class="text-danger">Saisissez une URL d\'abord.</small>';
|
||||
return;
|
||||
}
|
||||
|
||||
fetchMetaBtn.disabled = true;
|
||||
fetchMetaBtn.textContent = 'Chargement…';
|
||||
resultDiv.innerHTML = '';
|
||||
|
||||
try {
|
||||
const res = await fetch(`/?action=fetch_file_meta&url=${encodeURIComponent(url)}`);
|
||||
const data = await res.json();
|
||||
|
||||
if (!data.ok) {
|
||||
resultDiv.innerHTML = `<small class="text-danger">${data.error || 'Erreur lors de la récupération.'}</small>`;
|
||||
return;
|
||||
}
|
||||
|
||||
// Auto-remplissage dynamique des champs (si vides)
|
||||
const AUTOFILL = {
|
||||
img_author: { keys: ['author', 'credit'], label: 'Auteur / crédit' },
|
||||
img_source: { keys: ['canonical', 'source'], label: 'URL source' },
|
||||
};
|
||||
const autofillKeys = new Set();
|
||||
const autofillNotice = [];
|
||||
for (const [fieldName, cfg] of Object.entries(AUTOFILL)) {
|
||||
const f = document.querySelector(`input[name="${fieldName}"]`);
|
||||
if (!f || f.value) continue;
|
||||
for (const key of cfg.keys) {
|
||||
if (data[key]) {
|
||||
f.value = data[key];
|
||||
autofillKeys.add(key);
|
||||
autofillNotice.push(`<strong>${cfg.label}</strong> : ${data[key]}`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Affichage dynamique de tous les champs retournés
|
||||
const isPdf = (data.mime === 'application/pdf');
|
||||
const isHtml = (data.mime || '').startsWith('text/html');
|
||||
|
||||
const META_ORDER = ['mime','size','pages','page_size','pdf_version',
|
||||
'width','site_name','og_type','language',
|
||||
'title','description','author','subject','keywords',
|
||||
'credit','source','creator','producer','date','camera','copyright',
|
||||
'canonical','og_image'];
|
||||
const META_LABELS = {
|
||||
mime: 'Type', size: 'Taille', width: 'Dimensions',
|
||||
pages: 'Pages', page_size: 'Format', pdf_version: 'Version PDF',
|
||||
site_name: 'Site', og_type: 'Type OG', language: 'Langue',
|
||||
title: isPdf || isHtml ? 'Titre' : 'Titre EXIF/IPTC',
|
||||
author: isPdf || isHtml ? 'Auteur' : 'Auteur EXIF/IPTC',
|
||||
date: isPdf ? 'Créé le' : isHtml ? 'Publié le' : 'Prise de vue',
|
||||
description: 'Description', subject: 'Sujet', keywords: 'Mots-clés',
|
||||
credit: 'Crédit', source: 'Source IPTC',
|
||||
creator: 'Créé avec', producer: 'Produit par',
|
||||
camera: 'Appareil', copyright: 'Copyright',
|
||||
canonical: 'URL canonique', og_image: 'Image OG',
|
||||
};
|
||||
|
||||
function fmtVal(key, val) {
|
||||
if (key === 'size') return (val/1024).toFixed(0) + ' Ko' + (val >= 1048576 ? ` (${(val/1048576).toFixed(1)} Mo)` : '');
|
||||
if (key === 'width') return `${data.width} × ${data.height} px`;
|
||||
if (key === 'og_image') return `<img src="${val}" style="max-width:120px;max-height:80px;border-radius:4px" alt="">`;
|
||||
if (key === 'canonical') return `<a href="${val}" target="_blank" rel="noopener">${val}</a>`;
|
||||
return String(val);
|
||||
}
|
||||
|
||||
const SKIP = new Set(['ok', 'height']);
|
||||
const seen = new Set();
|
||||
const rows = [];
|
||||
|
||||
for (const key of META_ORDER) {
|
||||
const val = data[key];
|
||||
if (val == null || val === '' || key === 'height') continue;
|
||||
seen.add(key);
|
||||
const badge = autofillKeys.has(key)
|
||||
? ' <span class="badge text-bg-primary ms-1" title="Pré-rempli dans le formulaire">↓ pré-rempli</span>'
|
||||
: '';
|
||||
rows.push([META_LABELS[key] ?? key, fmtVal(key, val) + badge]);
|
||||
}
|
||||
for (const [key, val] of Object.entries(data)) {
|
||||
if (seen.has(key) || SKIP.has(key) || val == null || val === '') continue;
|
||||
rows.push([key, fmtVal(key, val)]);
|
||||
}
|
||||
|
||||
let html = '';
|
||||
if (rows.length > 0) {
|
||||
const trs = rows.map(([k, v]) =>
|
||||
`<tr><th class="text-muted fw-normal pe-3 text-nowrap">${k}</th><td>${v}</td></tr>`
|
||||
).join('');
|
||||
html = `<table class="table table-sm table-borderless mb-0 small"><tbody>${trs}</tbody></table>`;
|
||||
} else {
|
||||
html = '<small class="text-muted">Aucune métadonnée disponible pour ce fichier.</small>';
|
||||
}
|
||||
if (autofillNotice.length > 0) {
|
||||
html += `<div class="small text-primary mt-1">✓ Pré-rempli — ${autofillNotice.join(' · ')}</div>`;
|
||||
}
|
||||
resultDiv.innerHTML = html;
|
||||
} catch {
|
||||
resultDiv.innerHTML = '<small class="text-danger">Erreur de connexion.</small>';
|
||||
} finally {
|
||||
fetchMetaBtn.disabled = false;
|
||||
fetchMetaBtn.textContent = 'Métadonnées';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ─── Import image : toggle mode download ────────────────────────────────
|
||||
document.querySelectorAll('input[name="mode"]').forEach(function (r) {
|
||||
r.addEventListener('change', function () {
|
||||
const dl = this.value === 'download';
|
||||
const ss = this.value === 'screenshot';
|
||||
const warn = document.getElementById('copyright-warning');
|
||||
const fields = document.getElementById('download-fields');
|
||||
if (warn) warn.style.display = dl ? 'block' : 'none';
|
||||
if (fields) fields.style.display = (dl || ss) ? 'block' : 'none';
|
||||
});
|
||||
});
|
||||
|
||||
// ─── Données page (mode édition uniquement) ──────────────────────────────
|
||||
const pageEl = document.getElementById('vl-page');
|
||||
if (!pageEl) return;
|
||||
|
||||
const uuid = pageEl.dataset.uuid;
|
||||
const insertUrl = pageEl.dataset.insertUrl;
|
||||
|
||||
// Auto-insertion après import d'image
|
||||
if (insertUrl && ta) {
|
||||
const isImage = /\.(jpe?g|png|gif|webp|svg|avif)(\?.*)?$/i.test(insertUrl);
|
||||
const name = decodeURIComponent(insertUrl.split('/').pop().split('?')[0]) || 'fichier';
|
||||
const ref = isImage ? `` : `[${name}](${insertUrl})`;
|
||||
const sep = ta.value.length > 0 && !ta.value.endsWith('\n') ? '\n' : '';
|
||||
ta.value += sep + ref;
|
||||
ta.focus();
|
||||
ta.selectionStart = ta.selectionEnd = ta.value.length;
|
||||
ta.dispatchEvent(new Event('input'));
|
||||
}
|
||||
|
||||
// ─── Autosave ────────────────────────────────────────────────────────────
|
||||
const indicator = document.getElementById('autosave-indicator');
|
||||
if (!indicator || !uuid) return;
|
||||
|
||||
let timer = null;
|
||||
|
||||
function scheduleAutosave() {
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(doAutosave, 3000);
|
||||
}
|
||||
|
||||
async function doAutosave() {
|
||||
const title = document.getElementById('title').value;
|
||||
const slug = document.getElementById('slug').value;
|
||||
const content = document.getElementById('content').value;
|
||||
indicator.textContent = 'Sauvegarde…';
|
||||
try {
|
||||
const res = await fetch(`/?action=autosave&uuid=${encodeURIComponent(uuid)}`, {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
|
||||
body: new URLSearchParams({title, slug, content}),
|
||||
});
|
||||
const data = await res.json();
|
||||
indicator.textContent = data.ok ? `Brouillon sauvegardé à ${data.time}` : 'Erreur de sauvegarde';
|
||||
} catch {
|
||||
indicator.textContent = 'Erreur de sauvegarde';
|
||||
}
|
||||
}
|
||||
|
||||
['title', 'slug', 'content'].forEach(id => {
|
||||
document.getElementById(id)?.addEventListener('input', scheduleAutosave);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user