feat: refactorer l'interface Daily/Weekly/Monthly avec système de navigation unifié, calendrier interactif React-style avec sélection de plage, sidebar de raccourcis temporels, grille de jours avec états hover/in-range/start/end, variables CSS personnalisables, support complet thème clair/sombre, et amélioration responsive avec breakpoints optimisés pour mobile/tablette
This commit is contained in:
+260
-44
@@ -435,8 +435,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
const currentVisibility = (typeof shaarli !== 'undefined' && shaarli.visibility) ? shaarli.visibility : '';
|
||||
const currentUntagged = (typeof shaarli !== 'undefined' && shaarli.untaggedonly) || false;
|
||||
|
||||
|
||||
|
||||
let url = basePath + '/';
|
||||
|
||||
// Determine desired visibility
|
||||
@@ -464,7 +462,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
window.location.href = url;
|
||||
}
|
||||
|
||||
@@ -506,8 +503,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
// Initialize filter states from server-side variables (set in includes.html)
|
||||
(function initFilterStates() {
|
||||
|
||||
|
||||
// Get filter state from server-side rendered variables
|
||||
const visibility = (typeof shaarli !== 'undefined' && shaarli.visibility) ? shaarli.visibility : '';
|
||||
const untaggedonly = (typeof shaarli !== 'undefined' && shaarli.untaggedonly) ? shaarli.untaggedonly : false;
|
||||
@@ -517,36 +512,28 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
let isPublicActive = visibility === 'public';
|
||||
let isUntaggedActive = untaggedonly === true;
|
||||
|
||||
|
||||
|
||||
// Set checkbox states
|
||||
if (filterPrivate && isPrivateActive) {
|
||||
filterPrivate.checked = true;
|
||||
|
||||
}
|
||||
if (filterPublic && isPublicActive) {
|
||||
filterPublic.checked = true;
|
||||
|
||||
}
|
||||
if (filterUntagged && isUntaggedActive) {
|
||||
filterUntagged.checked = true;
|
||||
|
||||
}
|
||||
|
||||
const hasActiveFilter = isPrivateActive || isPublicActive || isUntaggedActive;
|
||||
|
||||
|
||||
// Add/update filter indicator badge on the filter button
|
||||
if (filterToggleBtn && hasActiveFilter) {
|
||||
filterToggleBtn.classList.add('has-active-filter');
|
||||
|
||||
|
||||
// Add badge indicator if not exists
|
||||
if (!filterToggleBtn.querySelector('.filter-badge')) {
|
||||
const badge = document.createElement('span');
|
||||
badge.className = 'filter-badge';
|
||||
filterToggleBtn.appendChild(badge);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -599,8 +586,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (message) {
|
||||
// Get base path safely
|
||||
const basePath = (typeof shaarli !== 'undefined' && shaarli.basePath) ? shaarli.basePath : '';
|
||||
@@ -623,25 +608,18 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
const linklist = document.getElementById('linklist');
|
||||
const emptyStateDiv = document.querySelector('.empty-state');
|
||||
|
||||
|
||||
|
||||
// Insert after the content-toolbar (pagination)
|
||||
if (contentToolbar && contentToolbar.parentNode) {
|
||||
contentToolbar.parentNode.insertBefore(banner, contentToolbar.nextSibling);
|
||||
|
||||
} else if (emptyStateDiv && emptyStateDiv.parentNode) {
|
||||
emptyStateDiv.parentNode.insertBefore(banner, emptyStateDiv);
|
||||
|
||||
} else if (linklist) {
|
||||
linklist.insertBefore(banner, linklist.firstChild);
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
// Add click handler to clear button
|
||||
document.getElementById('filter-clear-btn')?.addEventListener('click', () => {
|
||||
|
||||
// Clear based on what was active
|
||||
if (isPrivateActive || isPublicActive) {
|
||||
window.location.href = basePath + '/admin/visibility/all';
|
||||
@@ -658,7 +636,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
// Handle links per page options
|
||||
|
||||
|
||||
// Handle custom value form submission
|
||||
const filterInput = document.querySelector('.filter-input');
|
||||
if (filterInput) {
|
||||
@@ -887,7 +864,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
form.submit();
|
||||
}
|
||||
|
||||
|
||||
// ===== Thumbnail Update =====
|
||||
const thumbnailsPage = document.querySelector('.page-thumbnails');
|
||||
if (thumbnailsPage) {
|
||||
@@ -903,9 +879,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
let i = 0;
|
||||
|
||||
const updateThumbnail = function (id) {
|
||||
|
||||
|
||||
|
||||
fetch(shaarli.basePath + '/admin/shaare/' + id + '/update-thumbnail', {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
@@ -2195,6 +2168,12 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
lines.push(' audio.pause();');
|
||||
lines.push(' audio.src = \'\';');
|
||||
lines.push(' localStorage.removeItem(\'mediaPopupState\');');
|
||||
lines.push(' localStorage.removeItem(\'mediaPlayerUrl\');');
|
||||
lines.push(' localStorage.removeItem(\'mediaPlayerTitle\');');
|
||||
lines.push(' localStorage.removeItem(\'mediaPlayerPlaying\');');
|
||||
lines.push(' if (channel) {');
|
||||
lines.push(' try { channel.postMessage({ type: \'player-closed\' }); } catch(e) {}');
|
||||
lines.push(' }');
|
||||
lines.push(' window.close();');
|
||||
lines.push(' } else if (msg.type === \'player-seek\') {');
|
||||
lines.push(' if (audio.duration && isFinite(audio.duration)) {');
|
||||
@@ -2221,23 +2200,16 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
lines.push('');
|
||||
lines.push(' // --- Also listen for localStorage changes (fallback for no BroadcastChannel) ---');
|
||||
lines.push(' window.addEventListener(\'storage\', function(e) {');
|
||||
lines.push(' if (e.key === \'mediaPlayerCommand\' && e.newValue) {');
|
||||
lines.push(' if (e.key === \'mediaPopupState\' && e.newValue) {');
|
||||
lines.push(' try {');
|
||||
lines.push(' var cmd = JSON.parse(e.newValue);');
|
||||
lines.push(' if (cmd.action === \'load\') {');
|
||||
lines.push(' loadAndPlay(cmd.url, cmd.title);');
|
||||
lines.push(' } else if (cmd.action === \'toggle\') {');
|
||||
lines.push(' if (audio.paused) audio.play().catch(function() {});');
|
||||
lines.push(' else audio.pause();');
|
||||
lines.push(' } else if (cmd.action === \'stop\') {');
|
||||
lines.push(' audio.pause();');
|
||||
lines.push(' audio.src = \'\';');
|
||||
lines.push(' localStorage.removeItem(\'mediaPopupState\');');
|
||||
lines.push(' window.close();');
|
||||
lines.push(' var state = JSON.parse(e.newValue);');
|
||||
lines.push(' if (state.url) {');
|
||||
lines.push(' loadAndPlay(state.url, state.title);');
|
||||
lines.push(' }');
|
||||
lines.push(' // Clear the command');
|
||||
lines.push(' localStorage.removeItem(\'mediaPlayerCommand\');');
|
||||
lines.push(' } catch(err) {}');
|
||||
lines.push(' } else if (e.key === \'mediaPlayerClosed\') {');
|
||||
lines.push(' if (playerBar) playerBar.classList.remove(\'show\');');
|
||||
lines.push(' playerPopup = null;');
|
||||
lines.push(' }');
|
||||
lines.push(' });');
|
||||
lines.push('');
|
||||
@@ -2276,6 +2248,8 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
* Open (or re-use) the popup player window using a Blob URL.
|
||||
* Blob URLs share the parent page's origin, so BroadcastChannel
|
||||
* and localStorage work seamlessly - and no server file is needed.
|
||||
* Communication via BroadcastChannel API.
|
||||
* The inline bar serves as a "Now Playing" indicator and control relay.
|
||||
*/
|
||||
function showPlayer(url, title) {
|
||||
// Save config to localStorage - the popup reads it on load
|
||||
@@ -2329,9 +2303,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
updateInlineBar(title, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the inline "Now Playing" bar
|
||||
*/
|
||||
function updateInlineBar(title, playing) {
|
||||
if (!playerBar) return;
|
||||
|
||||
@@ -2522,4 +2493,249 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
} catch (err) { }
|
||||
}
|
||||
})();
|
||||
|
||||
// --- Daily calendar range picker ---
|
||||
(function initDailyCalendar() {
|
||||
var calendarToggle = document.getElementById('daily-calendar-toggle');
|
||||
var calendarPanel = document.getElementById('daily-calendar-panel');
|
||||
var calendarWrap = calendarPanel ? calendarPanel.closest('.daily-calendar-wrap') : null;
|
||||
var calendarMonth = document.getElementById('daily-calendar-month');
|
||||
var calendarWeekdays = document.getElementById('daily-calendar-weekdays');
|
||||
var calendarGrid = document.getElementById('daily-calendar-grid');
|
||||
var calendarPrev = document.getElementById('daily-calendar-prev');
|
||||
var calendarNext = document.getElementById('daily-calendar-next');
|
||||
var calendarStart = document.getElementById('daily-calendar-start');
|
||||
var calendarEnd = document.getElementById('daily-calendar-end');
|
||||
var calendarCancel = document.getElementById('daily-calendar-cancel');
|
||||
var calendarApply = document.getElementById('daily-calendar-apply');
|
||||
var dateDisplay = document.getElementById('daily-date-display');
|
||||
var shortcuts = document.querySelectorAll('.daily-calendar-shortcut');
|
||||
|
||||
if (!calendarToggle || !calendarPanel || !calendarGrid || !calendarWeekdays || !calendarMonth) return;
|
||||
|
||||
var MONTH_NAMES = ['Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre'];
|
||||
var DAY_NAMES = ['Lun', 'Mar', 'Mer', 'Jeu', 'Ven', 'Sam', 'Dim'];
|
||||
|
||||
var state = {
|
||||
viewDate: new Date(),
|
||||
startDate: null,
|
||||
endDate: null,
|
||||
hoverDate: null
|
||||
};
|
||||
|
||||
function getDaysInMonth(year, month) {
|
||||
return new Date(year, month + 1, 0).getDate();
|
||||
}
|
||||
|
||||
function getFirstDayOfMonth(year, month) {
|
||||
var day = new Date(year, month, 1).getDay();
|
||||
return day === 0 ? 6 : day - 1;
|
||||
}
|
||||
|
||||
function formatDate(date) {
|
||||
if (!date) return '';
|
||||
return new Intl.DateTimeFormat('fr-FR', { day: 'numeric', month: 'long', year: 'numeric' }).format(date);
|
||||
}
|
||||
|
||||
function isSameDay(d1, d2) {
|
||||
if (!d1 || !d2) return false;
|
||||
return d1.getDate() === d2.getDate() &&
|
||||
d1.getMonth() === d2.getMonth() &&
|
||||
d1.getFullYear() === d2.getFullYear();
|
||||
}
|
||||
|
||||
function isDateBetween(date, start, end) {
|
||||
if (!start || !end || !date) return false;
|
||||
return date > start && date < end;
|
||||
}
|
||||
|
||||
function normalizeDate(date) {
|
||||
return new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
||||
}
|
||||
|
||||
function updateSummary() {
|
||||
if (calendarStart) calendarStart.textContent = state.startDate ? formatDate(state.startDate) : '-';
|
||||
if (calendarEnd) calendarEnd.textContent = state.endDate ? formatDate(state.endDate) : '-';
|
||||
if (calendarApply) calendarApply.disabled = !(state.startDate && state.endDate);
|
||||
if (dateDisplay) {
|
||||
if (state.startDate && state.endDate) {
|
||||
if (isSameDay(state.startDate, state.endDate)) {
|
||||
dateDisplay.textContent = formatDate(state.startDate);
|
||||
} else {
|
||||
dateDisplay.textContent = formatDate(state.startDate) + ' - ' + formatDate(state.endDate);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function renderWeekdays() {
|
||||
calendarWeekdays.innerHTML = DAY_NAMES.map(function(day) {
|
||||
return '<span>' + day + '</span>';
|
||||
}).join('');
|
||||
}
|
||||
|
||||
function renderDays() {
|
||||
var year = state.viewDate.getFullYear();
|
||||
var month = state.viewDate.getMonth();
|
||||
var daysInMonth = getDaysInMonth(year, month);
|
||||
var firstDay = getFirstDayOfMonth(year, month);
|
||||
|
||||
calendarMonth.textContent = MONTH_NAMES[month] + ' ' + year;
|
||||
calendarGrid.innerHTML = '';
|
||||
|
||||
// Empty slots
|
||||
for (var i = 0; i < firstDay; i++) {
|
||||
var empty = document.createElement('span');
|
||||
empty.className = 'daily-calendar-empty';
|
||||
calendarGrid.appendChild(empty);
|
||||
}
|
||||
|
||||
// Days
|
||||
for (var day = 1; day <= daysInMonth; day++) {
|
||||
var currentDate = new Date(year, month, day);
|
||||
var btn = document.createElement('button');
|
||||
btn.type = 'button';
|
||||
btn.textContent = day;
|
||||
btn.className = 'daily-calendar-day';
|
||||
|
||||
var isSelectedStart = isSameDay(currentDate, state.startDate);
|
||||
var isSelectedEnd = isSameDay(currentDate, state.endDate);
|
||||
var rangeEnd = state.endDate || state.hoverDate;
|
||||
var isInRange = rangeEnd && isDateBetween(currentDate, state.startDate, rangeEnd);
|
||||
|
||||
// Apply classes like React version
|
||||
if (isSelectedStart && isSelectedEnd) {
|
||||
btn.classList.add('is-range-start', 'is-range-end', 'is-range-single');
|
||||
} else if (isSelectedStart) {
|
||||
btn.classList.add('is-range-start');
|
||||
} else if (isSelectedEnd) {
|
||||
btn.classList.add('is-range-end');
|
||||
} else if (isInRange) {
|
||||
btn.classList.add('is-in-range');
|
||||
}
|
||||
|
||||
// Event handlers with closure
|
||||
(function(d, y, m) {
|
||||
btn.addEventListener('mouseenter', function() {
|
||||
if (state.startDate && !state.endDate) {
|
||||
var newHoverDate = new Date(y, m, d);
|
||||
if (!state.hoverDate || state.hoverDate.getTime() !== newHoverDate.getTime()) {
|
||||
state.hoverDate = newHoverDate;
|
||||
renderDays();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
btn.addEventListener('click', function(e) {
|
||||
e.stopPropagation();
|
||||
var clickedDate = normalizeDate(new Date(y, m, d));
|
||||
console.log('Date clicked:', clickedDate);
|
||||
console.log('Before click - Start:', state.startDate, 'End:', state.endDate);
|
||||
|
||||
if (!state.startDate || (state.startDate && state.endDate)) {
|
||||
// Start new selection
|
||||
state.startDate = clickedDate;
|
||||
state.endDate = null;
|
||||
console.log('New selection started - Start:', state.startDate, 'End:', state.endDate);
|
||||
} else if (state.startDate && !state.endDate) {
|
||||
// Complete selection
|
||||
if (clickedDate < state.startDate) {
|
||||
state.endDate = state.startDate;
|
||||
state.startDate = clickedDate;
|
||||
console.log('Range completed (reverse) - Start:', state.startDate, 'End:', state.endDate);
|
||||
} else {
|
||||
state.endDate = clickedDate;
|
||||
console.log('Range completed - Start:', state.startDate, 'End:', state.endDate);
|
||||
}
|
||||
}
|
||||
state.hoverDate = null;
|
||||
updateSummary();
|
||||
renderDays();
|
||||
});
|
||||
})(day, year, month);
|
||||
|
||||
calendarGrid.appendChild(btn);
|
||||
}
|
||||
}
|
||||
|
||||
function setOpen(isOpen) {
|
||||
calendarPanel.classList.toggle('is-open', isOpen);
|
||||
calendarPanel.setAttribute('aria-hidden', String(!isOpen));
|
||||
if (calendarWrap) calendarWrap.classList.toggle('is-open', isOpen);
|
||||
if (calendarToggle) calendarToggle.setAttribute('aria-expanded', String(isOpen));
|
||||
}
|
||||
|
||||
function selectPreset(days) {
|
||||
var end = normalizeDate(new Date());
|
||||
var start = normalizeDate(new Date());
|
||||
start.setDate(end.getDate() - days);
|
||||
state.startDate = start;
|
||||
state.endDate = end;
|
||||
state.viewDate = new Date(end.getFullYear(), end.getMonth(), 1);
|
||||
updateSummary();
|
||||
renderDays();
|
||||
}
|
||||
|
||||
// Event listeners
|
||||
calendarToggle.addEventListener('click', function() {
|
||||
var willOpen = !calendarPanel.classList.contains('is-open');
|
||||
setOpen(willOpen);
|
||||
});
|
||||
|
||||
document.addEventListener('click', function(event) {
|
||||
if (!calendarPanel.classList.contains('is-open')) return;
|
||||
if (calendarWrap && !calendarWrap.contains(event.target) && event.target !== calendarToggle) {
|
||||
setOpen(false);
|
||||
}
|
||||
});
|
||||
|
||||
calendarPanel.addEventListener('click', function(event) {
|
||||
event.stopPropagation();
|
||||
});
|
||||
|
||||
if (calendarPrev) {
|
||||
calendarPrev.addEventListener('click', function() {
|
||||
state.viewDate = new Date(state.viewDate.getFullYear(), state.viewDate.getMonth() - 1, 1);
|
||||
renderDays();
|
||||
});
|
||||
}
|
||||
|
||||
if (calendarNext) {
|
||||
calendarNext.addEventListener('click', function() {
|
||||
state.viewDate = new Date(state.viewDate.getFullYear(), state.viewDate.getMonth() + 1, 1);
|
||||
renderDays();
|
||||
});
|
||||
}
|
||||
|
||||
shortcuts.forEach(function(shortcut) {
|
||||
shortcut.addEventListener('click', function() {
|
||||
var range = parseInt(this.dataset.range, 10);
|
||||
selectPreset(range);
|
||||
});
|
||||
});
|
||||
|
||||
if (calendarCancel) {
|
||||
calendarCancel.addEventListener('click', function() {
|
||||
setOpen(false);
|
||||
});
|
||||
}
|
||||
|
||||
if (calendarApply) {
|
||||
calendarApply.addEventListener('click', function() {
|
||||
if (!state.startDate || !state.endDate) return;
|
||||
setOpen(false);
|
||||
// Navigate to selected range
|
||||
var startFormatted = state.startDate.toISOString().split('T')[0].replace(/-/g, '');
|
||||
var endFormatted = state.endDate.toISOString().split('T')[0].replace(/-/g, '');
|
||||
var url = window.location.pathname + '?start=' + startFormatted + '&end=' + endFormatted;
|
||||
console.log('Navigating to range URL:', url);
|
||||
window.location.href = url;
|
||||
});
|
||||
}
|
||||
|
||||
// Initialize
|
||||
renderWeekdays();
|
||||
updateSummary();
|
||||
renderDays();
|
||||
})();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user