feat: implement theme management and enhance gallery functionality; add theme toggle and update image links for GLightbox
All checks were successful
CI / build (push) Successful in 31s
All checks were successful
CI / build (push) Successful in 31s
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
// Gallery functionality
|
||||
fetch("/images")
|
||||
.then(response => {
|
||||
if (!response.ok) throw new Error("Failed to fetch images.");
|
||||
@@ -9,10 +10,11 @@ fetch("/images")
|
||||
const imgContainer = document.createElement("div");
|
||||
imgContainer.className = "image-container";
|
||||
imgContainer.innerHTML = `
|
||||
<a href="${img.url}" target="_blank">
|
||||
<a href="${img.url}" class="glightbox" data-gallery="gallery">
|
||||
<img src="${img.url}" alt="${img.name}">
|
||||
</a>
|
||||
<button class="copy-btn" title="Copy URL">Copy URL</button>
|
||||
<button class="open-btn" title="Open Image">Open</button>
|
||||
`;
|
||||
const copyBtn = imgContainer.querySelector('.copy-btn');
|
||||
copyBtn.addEventListener('click', (e) => {
|
||||
@@ -22,7 +24,21 @@ fetch("/images")
|
||||
setTimeout(() => copyBtn.textContent = 'Copy URL', 1200);
|
||||
});
|
||||
});
|
||||
|
||||
const openBtn = imgContainer.querySelector('.open-btn');
|
||||
openBtn.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
window.open(img.url, '_blank');
|
||||
});
|
||||
|
||||
gallery.appendChild(imgContainer);
|
||||
});
|
||||
|
||||
// Initialize GLightbox after images are loaded
|
||||
const lightbox = GLightbox({
|
||||
touchNavigation: true,
|
||||
loop: true,
|
||||
autoplayVideos: false
|
||||
});
|
||||
})
|
||||
.catch(error => console.error("Error loading images:", error));
|
||||
|
||||
@@ -5,13 +5,16 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>PictShare Gallery</title>
|
||||
<link rel="icon" type="image/png" href="/favicon.png">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/glightbox/dist/css/glightbox.min.css">
|
||||
<link rel="stylesheet" href="/style.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<button class="theme-toggle" onclick="toggleTheme()">🌓</button>
|
||||
<h1>PictShare Gallery</h1>
|
||||
<div id="gallery"></div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/glightbox/dist/js/glightbox.min.js"></script>
|
||||
<script src="/theme.js"></script>
|
||||
<script src="/app.js"></script>
|
||||
|
||||
<footer style="margin:2rem 0 1rem 0; font-size:0.95em; color:#aaa;">
|
||||
|
||||
171
public/style.css
171
public/style.css
@@ -1,3 +1,60 @@
|
||||
:root {
|
||||
/* Light mode colors */
|
||||
--bg-gradient-start: #f8f9fa;
|
||||
--bg-gradient-end: #e9ecef;
|
||||
--text-color: #212529;
|
||||
--text-color-heading: #495057;
|
||||
--container-bg: rgba(255, 255, 255, 0.8);
|
||||
--container-border: rgba(0, 0, 0, 0.1);
|
||||
--copy-btn-bg: rgba(40, 167, 69, 0.85);
|
||||
--copy-btn-hover: rgba(40, 167, 69, 1);
|
||||
--open-btn-bg: rgba(108, 117, 125, 0.85);
|
||||
--open-btn-hover: rgba(108, 117, 125, 1);
|
||||
}
|
||||
|
||||
/* Dark mode colors */
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--bg-gradient-start: #1f1f22;
|
||||
--bg-gradient-end: #232a33;
|
||||
--text-color: #e0e0e0;
|
||||
--text-color-heading: #e0e6f0;
|
||||
--container-bg: rgba(255, 255, 255, 0.05);
|
||||
--container-border: rgba(255, 255, 255, 0.1);
|
||||
--copy-btn-bg: rgba(34, 139, 34, 0.85);
|
||||
--copy-btn-hover: rgba(34, 139, 34, 1);
|
||||
--open-btn-bg: rgba(102, 51, 153, 0.85);
|
||||
--open-btn-hover: rgba(102, 51, 153, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Manual theme override classes */
|
||||
html[data-theme="light"] {
|
||||
--bg-gradient-start: #f8f9fa;
|
||||
--bg-gradient-end: #e9ecef;
|
||||
--text-color: #212529;
|
||||
--text-color-heading: #495057;
|
||||
--container-bg: rgba(255, 255, 255, 0.8);
|
||||
--container-border: rgba(0, 0, 0, 0.1);
|
||||
--copy-btn-bg: rgba(40, 167, 69, 0.85);
|
||||
--copy-btn-hover: rgba(40, 167, 69, 1);
|
||||
--open-btn-bg: rgba(108, 117, 125, 0.85);
|
||||
--open-btn-hover: rgba(108, 117, 125, 1);
|
||||
}
|
||||
|
||||
html[data-theme="dark"] {
|
||||
--bg-gradient-start: #1f1f22;
|
||||
--bg-gradient-end: #232a33;
|
||||
--text-color: #e0e0e0;
|
||||
--text-color-heading: #e0e6f0;
|
||||
--container-bg: rgba(255, 255, 255, 0.05);
|
||||
--container-border: rgba(255, 255, 255, 0.1);
|
||||
--copy-btn-bg: rgba(34, 139, 34, 0.85);
|
||||
--copy-btn-hover: rgba(34, 139, 34, 1);
|
||||
--open-btn-bg: rgba(102, 51, 153, 0.85);
|
||||
--open-btn-hover: rgba(102, 51, 153, 1);
|
||||
}
|
||||
|
||||
html {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
@@ -5,8 +62,62 @@ html {
|
||||
box-sizing: border-box;
|
||||
font-family: Arial, sans-serif;
|
||||
text-align: center;
|
||||
background: linear-gradient(135deg, #1f1f22 0%, #232a33 100%);
|
||||
color: #e0e0e0;
|
||||
position: relative;
|
||||
/* Base light background - safe default for everyone */
|
||||
background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%, #f8fafc 100%);
|
||||
color: var(--text-color);
|
||||
transition: color 0.3s ease;
|
||||
}
|
||||
|
||||
/* Dark mode overlay - only shows for dark preference or manual dark */
|
||||
html::before {
|
||||
content: '';
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
/* Base dark gradient */
|
||||
background: linear-gradient(135deg, #1a1a1d 0%, #2d3748 50%, #1f2937 100%);
|
||||
opacity: 0;
|
||||
z-index: -2;
|
||||
transition: opacity 0.6s ease;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
/* Dark vignette overlay - only shows for dark preference or manual dark */
|
||||
html::after {
|
||||
content: '';
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
/* Dark charcoal vignette - lighter in center, darker at edges */
|
||||
background: radial-gradient(ellipse at center, rgba(45, 45, 48, 0.6) 0%, rgba(32, 32, 35, 0.8) 40%, rgba(20, 20, 23, 0.95) 100%);
|
||||
opacity: 0;
|
||||
z-index: -1;
|
||||
transition: opacity 0.6s ease;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
/* Show dark overlays for system dark preference */
|
||||
@media (prefers-color-scheme: dark) {
|
||||
html::before,
|
||||
html::after {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Manual theme overrides */
|
||||
html[data-theme="dark"]::before,
|
||||
html[data-theme="dark"]::after {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
html[data-theme="light"]::before,
|
||||
html[data-theme="light"]::after {
|
||||
opacity: 0;
|
||||
}
|
||||
body {
|
||||
margin: 0;
|
||||
@@ -15,10 +126,31 @@ body {
|
||||
|
||||
h1 {
|
||||
margin-top: 1.5rem;
|
||||
color: #e0e6f0;
|
||||
color: var(--text-color-heading);
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
|
||||
.theme-toggle {
|
||||
position: fixed;
|
||||
top: 20px;
|
||||
right: 20px;
|
||||
background: var(--container-bg);
|
||||
border: 1px solid var(--container-border);
|
||||
border-radius: 8px;
|
||||
padding: 8px 12px;
|
||||
cursor: pointer;
|
||||
font-size: 0.9rem;
|
||||
color: var(--text-color);
|
||||
transition: all 0.3s ease;
|
||||
z-index: 100;
|
||||
backdrop-filter: blur(10px);
|
||||
}
|
||||
|
||||
.theme-toggle:hover {
|
||||
background: var(--copy-btn-bg);
|
||||
color: white;
|
||||
}
|
||||
|
||||
|
||||
#gallery {
|
||||
display: grid;
|
||||
@@ -50,8 +182,8 @@ h1 {
|
||||
.copy-btn {
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
right: 8px;
|
||||
background: rgba(0,0,0,0.7);
|
||||
left: 8px;
|
||||
background: var(--copy-btn-bg);
|
||||
color: #fff;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
@@ -59,11 +191,36 @@ h1 {
|
||||
font-size: 0.9rem;
|
||||
opacity: 0;
|
||||
cursor: pointer;
|
||||
transition: opacity 0.2s;
|
||||
transition: opacity 0.2s, background 0.2s;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.image-container:hover .copy-btn {
|
||||
.copy-btn:hover {
|
||||
background: var(--copy-btn-hover);
|
||||
}
|
||||
|
||||
.open-btn {
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
right: 8px;
|
||||
background: var(--open-btn-bg);
|
||||
color: #fff;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
padding: 4px 8px;
|
||||
font-size: 0.9rem;
|
||||
opacity: 0;
|
||||
cursor: pointer;
|
||||
transition: opacity 0.2s, background 0.2s;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.open-btn:hover {
|
||||
background: var(--open-btn-hover);
|
||||
}
|
||||
|
||||
.image-container:hover .copy-btn,
|
||||
.image-container:hover .open-btn {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
|
||||
59
public/theme.js
Normal file
59
public/theme.js
Normal file
@@ -0,0 +1,59 @@
|
||||
// Theme management module
|
||||
class ThemeManager {
|
||||
constructor() {
|
||||
this.init();
|
||||
}
|
||||
|
||||
init() {
|
||||
this.setupTheme();
|
||||
this.setupSystemListener();
|
||||
}
|
||||
|
||||
setupTheme() {
|
||||
const savedTheme = localStorage.getItem('theme');
|
||||
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||
|
||||
if (savedTheme) {
|
||||
document.documentElement.setAttribute('data-theme', savedTheme);
|
||||
} else if (prefersDark) {
|
||||
document.documentElement.setAttribute('data-theme', 'dark');
|
||||
} else {
|
||||
document.documentElement.setAttribute('data-theme', 'light');
|
||||
}
|
||||
this.updateToggleIcon();
|
||||
}
|
||||
|
||||
toggle() {
|
||||
const currentTheme = document.documentElement.getAttribute('data-theme');
|
||||
const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
|
||||
|
||||
document.documentElement.setAttribute('data-theme', newTheme);
|
||||
localStorage.setItem('theme', newTheme);
|
||||
this.updateToggleIcon();
|
||||
}
|
||||
|
||||
updateToggleIcon() {
|
||||
const themeToggle = document.querySelector('.theme-toggle');
|
||||
if (themeToggle) {
|
||||
const currentTheme = document.documentElement.getAttribute('data-theme');
|
||||
themeToggle.textContent = currentTheme === 'dark' ? '☀️' : '🌙';
|
||||
}
|
||||
}
|
||||
|
||||
setupSystemListener() {
|
||||
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e) => {
|
||||
if (!localStorage.getItem('theme')) {
|
||||
document.documentElement.setAttribute('data-theme', e.matches ? 'dark' : 'light');
|
||||
this.updateToggleIcon();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize theme manager
|
||||
const themeManager = new ThemeManager();
|
||||
|
||||
// Global function for the HTML onclick
|
||||
function toggleTheme() {
|
||||
themeManager.toggle();
|
||||
}
|
||||
Reference in New Issue
Block a user