feat: implémenter système thèmes complet avec 14 thèmes prédéfinis (DEFAULT/GitHub/Linear/Spotify/Notion/Discord/Dracula/OneDark/TokyoNight/Nord/NightOwl/Anthracite/Cyberpunk/NavyElegance/Earthy), panel gestion thèmes dans tools.html avec grid previews et sélection interactive, synchronisation bidirectionnelle via bookmark shaarit_config (fetch/save JSON config), enforcement dark-only pour thèmes sans support light mode (disable toggle sidebar, auto-force dark), ajout data-theme-id attribute
This commit is contained in:
@@ -14,6 +14,16 @@
|
||||
<div class="card">
|
||||
<div class="card-header">{'Settings'|t}</div>
|
||||
<div class="list-group">
|
||||
<a class="list-group-item list-group-item-action ripple" href="#" id="themes-panel-toggle">
|
||||
<div class="list-sortable-handle">
|
||||
<i class="mdi mdi-palette"></i>
|
||||
</div>
|
||||
<div class="list-group-item-content">
|
||||
<div class="list-group-item-label">{'Themes'|t}</div>
|
||||
<div class="list-group-item-sublabel">{'Choose application visual theme'|t}</div>
|
||||
</div>
|
||||
<i class="mdi mdi-chevron-right"></i>
|
||||
</a>
|
||||
<a class="list-group-item list-group-item-action ripple" href="{$base_path}/admin/configure">
|
||||
<div class="list-sortable-handle">
|
||||
<i class="mdi mdi-cog"></i>
|
||||
@@ -101,6 +111,34 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Themes Management Panel -->
|
||||
<div class="row" id="themes-panel" style="display: none;">
|
||||
<div class="col-md-8 col-md-offset-2">
|
||||
<div class="card themes-card">
|
||||
<div class="card-header">
|
||||
<span><i class="mdi mdi-palette"></i> {'Application Themes'|t}</span>
|
||||
<button type="button" class="btn btn-sm btn-secondary" id="close-themes-panel">
|
||||
<i class="mdi mdi-close"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="themes-info">
|
||||
<i class="mdi mdi-information-outline"></i>
|
||||
<span>{'Choose your preferred visual theme. The theme configuration will be synchronized across your devices via the shaarit_config bookmark.'|t}</span>
|
||||
</div>
|
||||
|
||||
<div class="themes-grid" id="themes-grid">
|
||||
<!-- Filled by JavaScript -->
|
||||
</div>
|
||||
|
||||
<div class="themes-actions">
|
||||
<span id="theme-save-status" class="save-status"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Hidden Tags Management Panel -->
|
||||
<div class="row" id="hidden-tags-panel" style="display: none;">
|
||||
<div class="col-md-8 col-md-offset-2">
|
||||
@@ -249,6 +287,111 @@
|
||||
{include="page.footer"}
|
||||
|
||||
<style>
|
||||
/* Themes Panel Styles */
|
||||
.themes-card .card-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.themes-info {
|
||||
display: flex;
|
||||
gap: 0.75rem;
|
||||
padding: 1rem;
|
||||
background: linear-gradient(135deg, rgba(0, 212, 170, 0.1) 0%, rgba(14, 165, 233, 0.1) 100%);
|
||||
border: 1px solid rgba(0, 212, 170, 0.2);
|
||||
border-radius: 0.75rem;
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.themes-info i {
|
||||
font-size: 1.25rem;
|
||||
color: var(--primary);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.themes-info span {
|
||||
font-size: 0.9rem;
|
||||
color: var(--text-muted);
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.themes-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.theme-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
padding: 1rem;
|
||||
background: var(--bg-card);
|
||||
border: 2px solid var(--border-light);
|
||||
border-radius: 0.75rem;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.theme-item:hover {
|
||||
border-color: rgba(0, 212, 170, 0.4);
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.theme-item.active {
|
||||
border-color: var(--primary);
|
||||
background: rgba(var(--primary-rgb), 0.05);
|
||||
}
|
||||
|
||||
.theme-preview {
|
||||
width: 100%;
|
||||
height: 80px;
|
||||
border-radius: 0.5rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
border: 1px solid var(--border-light);
|
||||
}
|
||||
|
||||
.theme-preview-top {
|
||||
height: 30%;
|
||||
background: var(--preview-primary);
|
||||
}
|
||||
|
||||
.theme-preview-bottom {
|
||||
height: 70%;
|
||||
background: var(--preview-bg);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.theme-preview-card {
|
||||
width: 60%;
|
||||
height: 50%;
|
||||
background: var(--preview-surface);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.theme-name {
|
||||
font-weight: 500;
|
||||
font-size: 1rem;
|
||||
color: var(--text-primary);
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
|
||||
.theme-desc {
|
||||
font-size: 0.8rem;
|
||||
color: var(--text-muted);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
[data-theme="light"] .themes-info {
|
||||
background: linear-gradient(135deg, rgba(0, 107, 90, 0.05) 0%, rgba(0, 119, 182, 0.05) 100%);
|
||||
}
|
||||
|
||||
/* Hidden Tags Panel Styles */
|
||||
.hidden-tags-card .card-header {
|
||||
display: flex;
|
||||
@@ -426,6 +569,177 @@
|
||||
</style>
|
||||
|
||||
<script>
|
||||
// Themes Management
|
||||
(function() {
|
||||
const THEMES = [
|
||||
{ id: 'DEFAULT', name: 'ShaarIt', desc: 'Original theme', color: '#00D4AA', bg: '#0A1628', surface: '#0D1B2A', hasLight: true },
|
||||
{ id: 'GITHUB', name: 'GitHub', desc: 'Soft contrast', color: '#58A6FF', bg: '#0D1117', surface: '#161B22', hasLight: true },
|
||||
{ id: 'LINEAR', name: 'Linear', desc: 'Subtle gradients', color: '#5E6AD2', bg: '#12131A', surface: '#1B1C24', hasLight: false },
|
||||
{ id: 'SPOTIFY', name: 'Spotify', desc: 'Pure black & green', color: '#1DB954', bg: '#000000', surface: '#121212', hasLight: false },
|
||||
{ id: 'NOTION', name: 'Notion', desc: 'Clean reading', color: '#529CCA', bg: '#191919', surface: '#202020', hasLight: false },
|
||||
{ id: 'DISCORD', name: 'Discord', desc: 'Community standard', color: '#5865F2', bg: '#313338', surface: '#2B2D31', hasLight: false },
|
||||
{ id: 'DRACULA', name: 'Dracula', desc: 'Pink & purple accents', color: '#BD93F9', bg: '#282A36', surface: '#21222C', hasLight: false },
|
||||
{ id: 'ONE_DARK_PRO', name: 'One Dark', desc: 'Atom inspired', color: '#61AFEF', bg: '#282C34', surface: '#21252B', hasLight: false },
|
||||
{ id: 'TOKYO_NIGHT', name: 'Tokyo Night', desc: 'Neon blue', color: '#7AA2F7', bg: '#1A1B26', surface: '#16171F', hasLight: false },
|
||||
{ id: 'NORD', name: 'Nord', desc: 'Arctic style', color: '#88C0D0', bg: '#2E3440', surface: '#3B4252', hasLight: false },
|
||||
{ id: 'NIGHT_OWL', name: 'Night Owl', desc: 'Optimized for night', color: '#7FDBCA', bg: '#011627', surface: '#0B2942', hasLight: false },
|
||||
{ id: 'ANTHRACITE', name: 'Anthracite', desc: 'Material dark', color: '#BB86FC', bg: '#121212', surface: '#1E1E1E', hasLight: false },
|
||||
{ id: 'CYBERPUNK', name: 'Cyberpunk', desc: 'Vibrant neon', color: '#00FFFF', bg: '#0A0A14', surface: '#12121E', hasLight: false },
|
||||
{ id: 'NAVY_ELEGANCE', name: 'Navy Élégance', desc: 'Deep blue & gold', color: '#D4AF37', bg: '#0B1929', surface: '#0F2035', hasLight: false },
|
||||
{ id: 'EARTHY', name: 'Tons Terreux', desc: 'Organic feel', color: '#81C784', bg: '#1A1510', surface: '#231E18', hasLight: false }
|
||||
];
|
||||
|
||||
function getActiveTheme() {
|
||||
return localStorage.getItem('shaarit_theme_id') || 'DEFAULT';
|
||||
}
|
||||
|
||||
function showSaveStatus() {
|
||||
const status = document.getElementById('theme-save-status');
|
||||
if (status) {
|
||||
status.textContent = 'Saved! Refreshing...';
|
||||
status.classList.add('show');
|
||||
}
|
||||
}
|
||||
|
||||
function renderThemes() {
|
||||
const container = document.getElementById('themes-grid');
|
||||
if (!container) return;
|
||||
|
||||
const activeTheme = getActiveTheme();
|
||||
|
||||
container.innerHTML = THEMES.map(theme => `
|
||||
<div class="theme-item ${activeTheme === theme.id ? 'active' : ''}" data-theme-id="${theme.id}" data-has-light="${theme.hasLight}">
|
||||
<div class="theme-preview" style="--preview-primary: ${theme.color}; --preview-bg: ${theme.bg}; --preview-surface: ${theme.surface};">
|
||||
<div class="theme-preview-top"></div>
|
||||
<div class="theme-preview-bottom">
|
||||
<div class="theme-preview-card"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="theme-name">${theme.name}</div>
|
||||
<div class="theme-desc">${theme.desc}</div>
|
||||
</div>
|
||||
`).join('');
|
||||
|
||||
container.querySelectorAll('.theme-item').forEach(item => {
|
||||
item.addEventListener('click', function() {
|
||||
const themeId = this.dataset.themeId;
|
||||
const hasLight = this.dataset.hasLight === 'true';
|
||||
|
||||
// Update UI immediately
|
||||
container.querySelectorAll('.theme-item').forEach(el => el.classList.remove('active'));
|
||||
this.classList.add('active');
|
||||
|
||||
// Apply theme locally
|
||||
localStorage.setItem('shaarit_theme_id', themeId);
|
||||
document.documentElement.setAttribute('data-theme-id', themeId);
|
||||
|
||||
// Handle light mode restriction
|
||||
if (!hasLight) {
|
||||
localStorage.setItem('theme', 'dark');
|
||||
document.documentElement.setAttribute('data-theme', 'dark');
|
||||
// Trigger event for sidebar to update its switch
|
||||
window.dispatchEvent(new Event('themeChanged'));
|
||||
}
|
||||
|
||||
showSaveStatus();
|
||||
|
||||
// Sync to bookmark in background
|
||||
syncThemeToBookmark(themeId).then(() => {
|
||||
// Refresh to ensure everything applies cleanly (plugins etc)
|
||||
setTimeout(() => window.location.reload(), 500);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function syncThemeToBookmark(themeId) {
|
||||
try {
|
||||
// We fetch the current config bookmark if any
|
||||
const res = await fetch(shaarli.basePath + '/?searchtags=shaarit_config');
|
||||
const text = await res.text();
|
||||
const parser = new DOMParser();
|
||||
const doc = parser.parseFromString(text, 'text/html');
|
||||
|
||||
let config = { version: 1, theme: themeId, collections: [] };
|
||||
let editUrl = null;
|
||||
|
||||
// Find existing config
|
||||
const linkCard = doc.querySelector('.linklist-item');
|
||||
if (linkCard) {
|
||||
const descEl = linkCard.querySelector('.link-description p');
|
||||
if (descEl) {
|
||||
try {
|
||||
const parsed = JSON.parse(descEl.textContent.trim());
|
||||
config = Object.assign({}, parsed, { theme: themeId });
|
||||
} catch(e) {}
|
||||
}
|
||||
const editBtn = linkCard.querySelector('.link-action-edit');
|
||||
if (editBtn) editUrl = editBtn.getAttribute('href');
|
||||
}
|
||||
|
||||
// Prepare form data
|
||||
const formData = new FormData();
|
||||
formData.append('lf_title', 'collections');
|
||||
formData.append('lf_url', 'https://shaarit.app/config/collections');
|
||||
formData.append('lf_tags', 'shaarit_config');
|
||||
formData.append('lf_description', JSON.stringify(config));
|
||||
formData.append('save_edit', 'Save');
|
||||
|
||||
let token = '';
|
||||
|
||||
if (editUrl) {
|
||||
// Update existing
|
||||
const editRes = await fetch(editUrl);
|
||||
const editDoc = parser.parseFromString(await editRes.text(), 'text/html');
|
||||
const tokenEl = editDoc.querySelector('input[name="token"]');
|
||||
const idEl = editDoc.querySelector('input[name="lf_id"]');
|
||||
if (tokenEl) token = tokenEl.value;
|
||||
if (idEl) formData.append('lf_id', idEl.value);
|
||||
} else {
|
||||
// Create new
|
||||
const addRes = await fetch(shaarli.basePath + '/admin/add-shaare');
|
||||
const addDoc = parser.parseFromString(await addRes.text(), 'text/html');
|
||||
const tokenEl = addDoc.querySelector('input[name="token"]');
|
||||
if (tokenEl) token = tokenEl.value;
|
||||
}
|
||||
|
||||
if (token) {
|
||||
formData.append('token', token);
|
||||
await fetch(shaarli.basePath + '/admin/shaare', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to sync theme to bookmark', e);
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const toggleBtn = document.getElementById('themes-panel-toggle');
|
||||
const panel = document.getElementById('themes-panel');
|
||||
const closeBtn = document.getElementById('close-themes-panel');
|
||||
|
||||
if (toggleBtn && panel) {
|
||||
toggleBtn.addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
panel.style.display = panel.style.display === 'none' ? '' : 'none';
|
||||
if (panel.style.display !== 'none') {
|
||||
renderThemes();
|
||||
panel.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (closeBtn && panel) {
|
||||
closeBtn.addEventListener('click', function() {
|
||||
panel.style.display = 'none';
|
||||
});
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
||||
// Hidden Tags Management
|
||||
(function() {
|
||||
const STORAGE_KEY = 'shaarli_hidden_tags';
|
||||
|
||||
Reference in New Issue
Block a user