mirror of
https://github.com/Dvorinka/PPve.git
synced 2026-06-04 04:22:58 +00:00
726 lines
28 KiB
HTML
726 lines
28 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="cs">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Admin Dashboard - PP Kunovice</title>
|
|
<style>
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
margin: 0;
|
|
padding: 0;
|
|
background-color: #f5f5f5;
|
|
}
|
|
.header {
|
|
background-color: #333;
|
|
color: white;
|
|
padding: 1rem 2rem;
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
}
|
|
.header h1 {
|
|
margin: 0;
|
|
font-size: 1.5rem;
|
|
}
|
|
.logout-btn {
|
|
background: none;
|
|
border: 1px solid white;
|
|
color: white;
|
|
padding: 0.5rem 1rem;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
}
|
|
.logout-btn:hover {
|
|
background-color: rgba(255, 255, 255, 0.1);
|
|
}
|
|
.container {
|
|
max-width: 1200px;
|
|
margin: 2rem auto;
|
|
padding: 0 1rem;
|
|
}
|
|
.dashboard-cards {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
|
|
gap: 1.5rem;
|
|
margin-top: 2rem;
|
|
}
|
|
.card {
|
|
background-color: white;
|
|
border-radius: 8px;
|
|
padding: 1.5rem;
|
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
|
}
|
|
.card h3 {
|
|
margin-top: 0;
|
|
color: #333;
|
|
}
|
|
.form-group {
|
|
margin-bottom: 1rem;
|
|
}
|
|
.form-group label {
|
|
display: block;
|
|
margin-bottom: 0.5rem;
|
|
font-weight: bold;
|
|
}
|
|
.form-group input[type="text"],
|
|
.form-group textarea,
|
|
.form-group select {
|
|
width: 100%;
|
|
padding: 0.5rem;
|
|
border: 1px solid #ddd;
|
|
border-radius: 4px;
|
|
font-size: 1rem;
|
|
}
|
|
.form-group textarea {
|
|
min-height: 100px;
|
|
resize: vertical;
|
|
}
|
|
.color-preview {
|
|
display: inline-block;
|
|
width: 24px;
|
|
height: 24px;
|
|
border: 1px solid #ddd;
|
|
vertical-align: middle;
|
|
margin-left: 10px;
|
|
}
|
|
.style-presets {
|
|
display: flex;
|
|
gap: 10px;
|
|
margin: 10px 0;
|
|
}
|
|
.style-preset {
|
|
padding: 5px 10px;
|
|
border: 1px solid #ddd;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
font-size: 0.9rem;
|
|
}
|
|
.style-preset:hover {
|
|
background-color: #f0f0f0;
|
|
}
|
|
.banner-preview {
|
|
margin: 20px auto;
|
|
padding: 20px;
|
|
border: 1px dashed #ccc;
|
|
border-radius: 8px;
|
|
max-width: 800px;
|
|
min-height: 100px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
position: relative;
|
|
overflow: hidden;
|
|
}
|
|
.banner-preview img {
|
|
max-width: 100%;
|
|
max-height: 200px;
|
|
object-fit: contain;
|
|
}
|
|
.banner-preview.with-image {
|
|
min-height: 200px;
|
|
}
|
|
.banner-preview-content {
|
|
position: relative;
|
|
z-index: 2;
|
|
text-align: center;
|
|
padding: 20px;
|
|
}
|
|
.banner-preview-bg {
|
|
position: absolute;
|
|
top: 0;
|
|
left: 0;
|
|
right: 0;
|
|
bottom: 0;
|
|
background-size: cover;
|
|
background-position: center;
|
|
opacity: 0.7;
|
|
z-index: 1;
|
|
}
|
|
.banner-preview-text {
|
|
position: relative;
|
|
z-index: 2;
|
|
color: inherit;
|
|
}
|
|
.color-picker-container {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 10px;
|
|
}
|
|
.color-picker {
|
|
width: 40px;
|
|
height: 30px;
|
|
padding: 0;
|
|
border: 1px solid #ddd;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
}
|
|
.image-upload-container {
|
|
margin: 15px 0;
|
|
padding: 15px;
|
|
border: 1px dashed #ddd;
|
|
border-radius: 4px;
|
|
text-align: center;
|
|
}
|
|
.image-preview {
|
|
max-width: 200px;
|
|
max-height: 150px;
|
|
margin: 10px auto;
|
|
display: block;
|
|
}
|
|
.card p {
|
|
color: #666;
|
|
margin-bottom: 0;
|
|
}
|
|
|
|
/* Form Actions */
|
|
.form-actions {
|
|
margin-top: 2rem;
|
|
padding-top: 1rem;
|
|
border-top: 1px solid #eee;
|
|
display: flex;
|
|
justify-content: flex-end;
|
|
gap: 1rem;
|
|
}
|
|
|
|
.btn {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
padding: 0.5rem 1.25rem;
|
|
border: 1px solid transparent;
|
|
border-radius: 4px;
|
|
font-size: 1rem;
|
|
font-weight: 500;
|
|
line-height: 1.5;
|
|
cursor: pointer;
|
|
transition: all 0.2s ease-in-out;
|
|
text-decoration: none;
|
|
gap: 0.5rem;
|
|
}
|
|
|
|
.btn i {
|
|
font-size: 0.9em;
|
|
}
|
|
|
|
.btn-primary {
|
|
background-color: #4a6cf7;
|
|
color: white;
|
|
border-color: #4a6cf7;
|
|
}
|
|
|
|
.btn-primary:hover {
|
|
background-color: #3a5ce4;
|
|
border-color: #3a5ce4;
|
|
}
|
|
|
|
.btn-secondary {
|
|
background-color: #6c757d;
|
|
color: white;
|
|
border-color: #6c757d;
|
|
}
|
|
|
|
.btn-secondary:hover {
|
|
background-color: #5a6268;
|
|
border-color: #545b62;
|
|
}
|
|
|
|
.btn-danger {
|
|
background-color: #dc3545;
|
|
color: white;
|
|
border-color: #dc3545;
|
|
}
|
|
|
|
.btn-danger:hover {
|
|
background-color: #c82333;
|
|
border-color: #bd2130;
|
|
}
|
|
|
|
/* Notifications */
|
|
.notification {
|
|
position: fixed;
|
|
top: 20px;
|
|
right: 20px;
|
|
padding: 15px 20px;
|
|
border-radius: 4px;
|
|
color: white;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 10px;
|
|
z-index: 1000;
|
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
|
opacity: 0;
|
|
transform: translateY(-20px);
|
|
animation: slideIn 0.3s ease-out forwards;
|
|
}
|
|
|
|
.notification i {
|
|
font-size: 1.2em;
|
|
}
|
|
|
|
.notification.success {
|
|
background-color: #28a745;
|
|
}
|
|
|
|
.notification.error {
|
|
background-color: #dc3545;
|
|
}
|
|
|
|
.notification.warning {
|
|
background-color: #ffc107;
|
|
color: #212529;
|
|
}
|
|
|
|
.fade-out {
|
|
animation: fadeOut 0.3s ease-out forwards;
|
|
}
|
|
|
|
@keyframes slideIn {
|
|
to {
|
|
opacity: 1;
|
|
transform: translateY(0);
|
|
}
|
|
}
|
|
|
|
@keyframes fadeOut {
|
|
to {
|
|
opacity: 0;
|
|
transform: translateY(-20px);
|
|
}
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="header">
|
|
<h1>Admin Dashboard</h1>
|
|
<button class="logout-btn" id="logoutBtn">Odhlásit se</button>
|
|
</div>
|
|
|
|
<div class="container">
|
|
<h2>Vítejte v administraci</h2>
|
|
|
|
<div class="card" style="margin: 2rem auto; max-width: 1000px;">
|
|
<h3>Správa banneru</h3>
|
|
|
|
<form id="bannerForm" enctype="multipart/form-data" onsubmit="saveBanner(event)">
|
|
<div class="form-group">
|
|
<label for="bannerText">Text banneru</label>
|
|
<textarea id="bannerText" name="text" placeholder="Zadejte text banneru" required></textarea>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="bannerLink">Odkaz (volitelný)</label>
|
|
<input type="url" id="bannerLink" name="link" placeholder="https://example.com">
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label>Nahrát obrázek</label>
|
|
<input type="file" id="bannerImage" name="image" accept="image/*" style="display: none;" onchange="handleImageUpload(event)">
|
|
<input type="hidden" id="removeImage" name="removeImage" value="false">
|
|
<div>
|
|
<button type="button" class="btn btn-secondary" id="uploadImageBtn">
|
|
<i class="fas fa-upload"></i> Vybrat obrázek
|
|
</button>
|
|
<button type="button" id="removeImageBtn" class="btn btn-danger" style="display: none; margin-left: 10px;" onclick="removeImage()">
|
|
<i class="fas fa-trash"></i> Odstranit obrázek
|
|
</button>
|
|
</div>
|
|
<div id="imagePreviewContainer" style="margin-top: 10px; display: none;">
|
|
<img id="imagePreview" style="max-width: 200px; max-height: 200px; border: 1px solid #ddd; border-radius: 4px; padding: 5px;" />
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label>
|
|
<input type="checkbox" id="bannerVisible" name="style[isVisible]" value="true" checked> Zobrazit banner
|
|
</label>
|
|
</div>
|
|
|
|
<h4>Styl</h4>
|
|
|
|
<div class="form-group">
|
|
<label for="bannerBgColor">Barva pozadí</label>
|
|
<input type="text" id="bannerBgColor" name="style[backgroundColor]" value="#f8d7da" class="color-input">
|
|
<input type="color" id="bannerBgColorPicker" value="#f8d7da" class="color-picker">
|
|
<div id="bgColorPreview" class="color-preview"></div>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="bannerTextColor">Barva textu</label>
|
|
<input type="text" id="bannerTextColor" name="style[textColor]" value="#721c24" class="color-input">
|
|
<input type="color" id="bannerTextColorPicker" value="#721c24" class="color-picker">
|
|
<div id="textColorPreview" class="color-preview"></div>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="bannerTextAlign">Zarovnání textu</label>
|
|
<select id="bannerTextAlign" name="style[textAlign]">
|
|
<option value="left">Vlevo</option>
|
|
<option value="center" selected>Na střed</option>
|
|
<option value="right">Vpravo</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="bannerFontSize">Velikost písma (px)</label>
|
|
<input type="number" id="bannerFontSize" name="style[fontSize]" value="18" min="10" max="50">
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="bannerPadding">Odsazení (px)</label>
|
|
<input type="number" id="bannerPadding" name="style[padding]" value="20" min="0" max="100">
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="bannerMargin">Okraj (px)</label>
|
|
<input type="number" id="bannerMargin" name="style[margin]" value="20" min="0" max="100">
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="bannerBorderRadius">Zaoblení rohů (px)</label>
|
|
<input type="number" id="bannerBorderRadius" name="style[borderRadius]" value="8" min="0" max="50">
|
|
</div>
|
|
|
|
<h4>Předvolby stylů</h4>
|
|
<div class="style-presets">
|
|
<div class="style-preset" data-preset="info">Info</div>
|
|
<div class="style-preset" data-preset="warning">Upozornění</div>
|
|
<div class="style-preset" data-preset="success">Úspěch</div>
|
|
<div class="style-preset" data-preset="error">Chyba</div>
|
|
</div>
|
|
|
|
<div class="banner-preview" id="bannerPreview" style="display: none;">
|
|
<div class="banner-preview-bg"></div>
|
|
<div class="banner-preview-content">
|
|
<div class="banner-preview-text">Náhled banneru se zde zobrazí</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-actions">
|
|
<button type="submit" id="saveBannerBtn" class="btn btn-primary">
|
|
<i class="fas fa-save"></i> Uložit banner
|
|
</button>
|
|
</div>
|
|
</form>
|
|
|
|
<div class="banner-preview" id="bannerPreview" style="display: none;">
|
|
<div class="banner-preview-bg"></div>
|
|
<div class="banner-preview-content">
|
|
<div class="banner-preview-text">Náhled banneru se zde zobrazí</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="dashboard-cards">
|
|
<div class="card">
|
|
<h3>Uživatelé</h3>
|
|
<p>Správa uživatelských účtů</p>
|
|
</div>
|
|
<div class="card">
|
|
<h3>Nastavení</h3>
|
|
<p>Konfigurace systému</p>
|
|
</div>
|
|
<div class="card">
|
|
<h3>Statistiky</h3>
|
|
<p>Přehled aktivit</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
// Check if user is authenticated
|
|
const token = localStorage.getItem('token');
|
|
if (!token) {
|
|
window.location.href = '/admin';
|
|
}
|
|
|
|
// Override fetch to include token
|
|
const originalFetch = window.fetch;
|
|
window.fetch = async function(resource, init = {}) {
|
|
// Add token to headers if it's an API request
|
|
if (typeof resource === 'string' && resource.startsWith('/api/')) {
|
|
const headers = new Headers(init.headers || {});
|
|
if (token) {
|
|
headers.set('Authorization', `Bearer ${token}`);
|
|
}
|
|
|
|
// Set content type if not set
|
|
if (!headers.has('Content-Type') && init.body) {
|
|
headers.set('Content-Type', 'application/json');
|
|
}
|
|
|
|
init.headers = headers;
|
|
}
|
|
|
|
return originalFetch(resource, init);
|
|
};
|
|
|
|
// Logout functionality
|
|
document.getElementById('logoutBtn').addEventListener('click', function() {
|
|
localStorage.removeItem('token');
|
|
window.location.href = '/';
|
|
});
|
|
|
|
// DOM Elements
|
|
const bannerText = document.getElementById('bannerText');
|
|
const bannerVisible = document.getElementById('bannerVisible');
|
|
const bannerBgColor = document.getElementById('bannerBgColor');
|
|
const bannerTextColor = document.getElementById('bannerTextColor');
|
|
const bannerTextAlign = document.getElementById('bannerTextAlign');
|
|
const bannerFontSize = document.getElementById('bannerFontSize');
|
|
const bannerPadding = document.getElementById('bannerPadding');
|
|
const bannerMargin = document.getElementById('bannerMargin');
|
|
const bannerBorderRadius = document.getElementById('bannerBorderRadius');
|
|
const bannerPreview = document.getElementById('bannerPreview');
|
|
const bannerPreviewContent = bannerPreview.querySelector('.banner-preview-content');
|
|
const bannerPreviewText = bannerPreview.querySelector('.banner-preview-text');
|
|
const bannerPreviewBg = bannerPreview.querySelector('.banner-preview-bg');
|
|
const bgColorPreview = document.getElementById('bgColorPreview');
|
|
const textColorPreview = document.getElementById('textColorPreview');
|
|
const saveBannerBtn = document.getElementById('saveBannerBtn');
|
|
const stylePresets = document.querySelectorAll('.style-preset');
|
|
let currentImage = null;
|
|
|
|
// Preset styles
|
|
const presets = {
|
|
info: {
|
|
backgroundColor: '#cce5ff',
|
|
textColor: '#004085',
|
|
textAlign: 'left'
|
|
},
|
|
warning: {
|
|
backgroundColor: '#fff3cd',
|
|
textColor: '#856404',
|
|
textAlign: 'center'
|
|
},
|
|
success: {
|
|
backgroundColor: '#d4edda',
|
|
textColor: '#155724',
|
|
textAlign: 'center'
|
|
},
|
|
error: {
|
|
backgroundColor: '#f8d7da',
|
|
textColor: '#721c24',
|
|
textAlign: 'center'
|
|
}
|
|
};
|
|
|
|
// Load current banner
|
|
async function loadBanner() {
|
|
try {
|
|
const response = await fetch('/api/banner');
|
|
if (!response.ok) throw new Error('Failed to load banner');
|
|
|
|
const banner = await response.json();
|
|
|
|
// Update form fields
|
|
document.getElementById('bannerText').value = banner.text || '';
|
|
document.getElementById('bannerLink').value = banner.link || '';
|
|
document.getElementById('bannerVisible').checked = banner.style.isVisible !== false;
|
|
document.getElementById('bannerBgColor').value = banner.style.backgroundColor || '#f8d7da';
|
|
document.getElementById('bannerBgColorPicker').value = banner.style.backgroundColor || '#f8d7da';
|
|
document.getElementById('bannerTextColor').value = banner.style.textColor || '#721c24';
|
|
document.getElementById('bannerTextColorPicker').value = banner.style.textColor || '#721c24';
|
|
document.getElementById('bannerTextAlign').value = banner.style.textAlign || 'center';
|
|
document.getElementById('bannerFontSize').value = banner.style.fontSize ? banner.style.fontSize.replace('px', '') : '18';
|
|
document.getElementById('bannerPadding').value = banner.style.padding ? banner.style.padding.replace('px', '') : '20';
|
|
document.getElementById('bannerMargin').value = banner.style.margin ? banner.style.margin.replace('px', '') : '20';
|
|
document.getElementById('bannerBorderRadius').value = banner.style.borderRadius ? banner.style.borderRadius.replace('px', '') : '8';
|
|
|
|
// Handle image
|
|
if (banner.image) {
|
|
currentImage = banner.image;
|
|
document.getElementById('imagePreview').src = currentImage;
|
|
document.getElementById('imagePreviewContainer').style.display = 'block';
|
|
document.getElementById('removeImageBtn').style.display = 'inline-block';
|
|
}
|
|
|
|
updateColorPreviews();
|
|
updateBannerPreview();
|
|
|
|
} catch (error) {
|
|
console.error('Error loading banner:', error);
|
|
alert('Nepodařilo se načíst banner');
|
|
}
|
|
}
|
|
|
|
// Save banner
|
|
async function saveBanner(event) {
|
|
event.preventDefault();
|
|
|
|
const form = document.getElementById('bannerForm');
|
|
const formData = new FormData(form);
|
|
const saveBtn = document.getElementById('saveBannerBtn');
|
|
const originalBtnText = saveBtn.innerHTML;
|
|
|
|
// Update button state
|
|
saveBtn.disabled = true;
|
|
saveBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Ukládám...';
|
|
|
|
try {
|
|
// Add style properties to form data
|
|
formData.append('style[backgroundColor]', document.getElementById('bannerBgColor').value);
|
|
formData.append('style[textColor]', document.getElementById('bannerTextColor').value);
|
|
formData.append('style[textAlign]', document.getElementById('bannerTextAlign').value);
|
|
formData.append('style[fontSize]', document.getElementById('bannerFontSize').value + 'px');
|
|
formData.append('style[padding]', document.getElementById('bannerPadding').value + 'px');
|
|
formData.append('style[margin]', document.getElementById('bannerMargin').value + 'px');
|
|
formData.append('style[borderRadius]', document.getElementById('bannerBorderRadius').value + 'px');
|
|
formData.append('style[isVisible]', document.getElementById('bannerVisible').checked);
|
|
|
|
const response = await fetch('/api/banner/update', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Authorization': `Bearer ${localStorage.getItem('token')}`
|
|
},
|
|
body: formData
|
|
});
|
|
|
|
if (!response.ok) {
|
|
const error = await response.text();
|
|
throw new Error(error || 'Chyba při ukládání banneru');
|
|
}
|
|
|
|
const result = await response.json();
|
|
|
|
// Show success message
|
|
const notification = document.createElement('div');
|
|
notification.className = 'notification success';
|
|
notification.innerHTML = '<i class="fas fa-check-circle"></i> Banner byl úspěšně uložen';
|
|
document.body.appendChild(notification);
|
|
|
|
// Remove notification after 3 seconds
|
|
setTimeout(() => {
|
|
notification.classList.add('fade-out');
|
|
setTimeout(() => notification.remove(), 300);
|
|
}, 3000);
|
|
|
|
// Update the preview with the new banner data
|
|
if (result.image) {
|
|
currentImage = result.image;
|
|
document.getElementById('imagePreview').src = currentImage;
|
|
document.getElementById('imagePreviewContainer').style.display = 'block';
|
|
document.getElementById('removeImageBtn').style.display = 'inline-block';
|
|
}
|
|
|
|
updateBannerPreview();
|
|
|
|
} catch (error) {
|
|
console.error('Chyba při ukládání banneru:', error);
|
|
|
|
// Show error message
|
|
const notification = document.createElement('div');
|
|
notification.className = 'notification error';
|
|
notification.innerHTML = `<i class="fas fa-exclamation-circle"></i> ${error.message || 'Nepodařilo se uložit banner'}`;
|
|
document.body.appendChild(notification);
|
|
|
|
// Remove notification after 5 seconds
|
|
setTimeout(() => {
|
|
notification.classList.add('fade-out');
|
|
setTimeout(() => notification.remove(), 300);
|
|
}, 5000);
|
|
|
|
} finally {
|
|
// Reset button state
|
|
saveBtn.disabled = false;
|
|
saveBtn.innerHTML = originalBtnText;
|
|
}
|
|
}
|
|
|
|
// Update color previews
|
|
function updateColorPreviews() {
|
|
bgColorPreview.style.backgroundColor = bannerBgColor.value;
|
|
textColorPreview.style.backgroundColor = bannerTextColor.value;
|
|
}
|
|
|
|
// Update banner preview
|
|
function updateBannerPreview() {
|
|
const bannerText = document.getElementById('bannerText').value;
|
|
const bannerMargin = document.getElementById('bannerMargin').value;
|
|
const bannerBorderRadius = document.getElementById('bannerBorderRadius').value;
|
|
const bannerFontSize = document.getElementById('bannerFontSize').value;
|
|
const bannerBgColor = document.getElementById('bannerBgColor').value;
|
|
const bannerTextColor = document.getElementById('bannerTextColor').value;
|
|
const bannerTextAlign = document.getElementById('bannerTextAlign').value;
|
|
const bannerPadding = document.getElementById('bannerPadding').value;
|
|
|
|
const bannerPreview = document.getElementById('bannerPreview');
|
|
const bannerPreviewText = bannerPreview.querySelector('.banner-preview-text');
|
|
const bannerPreviewBg = bannerPreview.querySelector('.banner-preview-bg');
|
|
const bannerPreviewContent = bannerPreview.querySelector('.banner-preview-content');
|
|
|
|
if (!bannerText.trim() && !currentImage) {
|
|
bannerPreview.style.display = 'none';
|
|
return;
|
|
}
|
|
|
|
bannerPreview.style.display = 'block';
|
|
bannerPreview.style.margin = `${bannerMargin}px auto`;
|
|
bannerPreview.style.borderRadius = `${bannerBorderRadius}px`;
|
|
|
|
// Update banner content
|
|
bannerPreviewText.textContent = bannerText || '';
|
|
bannerPreviewText.style.fontSize = `${bannerFontSize}px`;
|
|
|
|
// Update background and text colors
|
|
bannerPreview.style.backgroundColor = bannerBgColor;
|
|
bannerPreviewText.style.color = bannerTextColor;
|
|
|
|
// Update text alignment
|
|
bannerPreview.style.textAlign = bannerTextAlign;
|
|
|
|
// Update padding
|
|
bannerPreviewContent.style.padding = `${bannerPadding}px`;
|
|
|
|
// Handle image
|
|
if (currentImage) {
|
|
bannerPreview.classList.add('with-image');
|
|
bannerPreviewBg.style.backgroundImage = `url(${currentImage})`;
|
|
bannerPreviewBg.style.display = 'block';
|
|
} else {
|
|
bannerPreview.classList.remove('with-image');
|
|
bannerPreviewBg.style.display = 'none';
|
|
}
|
|
}
|
|
|
|
// Apply preset
|
|
function applyPreset(preset) {
|
|
const style = presets[preset];
|
|
if (!style) return;
|
|
|
|
bannerBgColor.value = style.backgroundColor;
|
|
bannerTextColor.value = style.textColor;
|
|
bannerTextAlign.value = style.textAlign;
|
|
|
|
updateColorPreviews();
|
|
updateBannerPreview();
|
|
}
|
|
|
|
// Event Listeners
|
|
bannerBgColor.addEventListener('input', () => {
|
|
updateColorPreviews();
|
|
updateBannerPreview();
|
|
});
|
|
|
|
bannerTextColor.addEventListener('input', () => {
|
|
updateColorPreviews();
|
|
updateBannerPreview();
|
|
});
|
|
|
|
[bannerText, bannerTextAlign, bannerFontSize, bannerPadding, bannerVisible].forEach(el => {
|
|
el.addEventListener('change', updateBannerPreview);
|
|
el.addEventListener('input', updateBannerPreview);
|
|
});
|
|
|
|
stylePresets.forEach(preset => {
|
|
preset.addEventListener('click', () => applyPreset(preset.dataset.preset));
|
|
});
|
|
|
|
saveBannerBtn.addEventListener('click', saveBanner);
|
|
|
|
// Load banner when page loads
|
|
document.addEventListener('DOMContentLoaded', loadBanner);
|
|
</script>
|
|
</body>
|
|
</html>
|