permalink option

This commit is contained in:
mi
2025-11-15 18:04:49 +10:00
parent 742ff0e553
commit 866bfe4d6d
7 changed files with 143 additions and 9 deletions

View File

@@ -1070,13 +1070,45 @@ footer.compact-footer .footer-section:not(:last-child)::after {
}
/* ============================================================
EMBED FEATURE STYLES
SHARE/EMBED FEATURE STYLES
============================================================ */
/* Embed button section */
.comic-embed-section {
/* Share section (contains permalink and embed buttons) */
.comic-share-section {
margin-top: var(--space-lg);
text-align: center;
display: flex;
justify-content: center;
gap: var(--space-md);
flex-wrap: wrap;
}
/* Permalink button */
.btn-permalink {
padding: var(--space-sm) var(--space-lg);
background-color: var(--color-background);
border: var(--border-width-thin) solid var(--color-border);
color: var(--color-text);
font-family: var(--font-family);
font-size: var(--font-size-md);
cursor: pointer;
text-transform: uppercase;
letter-spacing: var(--letter-spacing-tight);
transition: background-color var(--transition-speed);
}
.btn-permalink:hover {
background-color: var(--color-hover-bg);
}
.btn-permalink:focus {
outline: 3px solid var(--color-primary);
outline-offset: 2px;
}
.btn-permalink.copied {
background-color: var(--color-primary);
color: var(--color-background);
}
/* Embed button */

84
static/js/permalink.js Normal file
View File

@@ -0,0 +1,84 @@
// Permalink functionality for Sunday Comics
// Handles copying comic permalinks to clipboard
(function() {
'use strict';
const permalinkButton = document.getElementById('permalink-button');
if (!permalinkButton) {
// Permalink feature not enabled or button not found
return;
}
// Get the site URL from the page
const siteUrl = document.body.getAttribute('data-site-url') || window.location.origin;
// Copy permalink when button is clicked
permalinkButton.addEventListener('click', function() {
const comicNumber = this.getAttribute('data-comic-number');
if (!comicNumber) return;
// Generate permalink URL
const permalink = `${siteUrl}/comic/${comicNumber}`;
// Copy to clipboard
copyToClipboard(permalink);
});
// Copy text to clipboard
function copyToClipboard(text) {
// Modern clipboard API
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(text).then(function() {
showCopyFeedback();
}).catch(function() {
// Fallback for older browsers
fallbackCopy(text);
});
} else {
// Fallback for older browsers
fallbackCopy(text);
}
}
// Fallback copy method for older browsers
function fallbackCopy(text) {
// Create temporary textarea
const textarea = document.createElement('textarea');
textarea.value = text;
textarea.style.position = 'fixed';
textarea.style.opacity = '0';
document.body.appendChild(textarea);
textarea.focus();
textarea.select();
try {
document.execCommand('copy');
showCopyFeedback();
} catch (err) {
alert('Failed to copy. Please copy manually: ' + text);
}
document.body.removeChild(textarea);
}
// Show visual feedback that the permalink was copied
function showCopyFeedback() {
const originalText = permalinkButton.textContent;
permalinkButton.textContent = 'Copied!';
permalinkButton.classList.add('copied');
setTimeout(function() {
permalinkButton.textContent = originalText;
permalinkButton.classList.remove('copied');
}, 2000);
}
// Update permalink button when comic changes via client-side navigation
window.addEventListener('comicUpdated', function(event) {
if (event.detail && event.detail.comicNumber && permalinkButton) {
permalinkButton.setAttribute('data-comic-number', event.detail.comicNumber);
}
});
})();