Opcja rozwiązywani i usuwania komentarzy.

This commit is contained in:
2026-02-18 22:11:02 +01:00
parent e7549c6f00
commit d4355e3ee2

View File

@@ -35,6 +35,7 @@
<div id="comment-input-box-overlay"></div>
<div id="comment-input-box">
<h6 style="margin-top:0;">Dodaj notatkę</h6>
<input type="text" id="new-comment-author" class="form-control mb-2" placeholder="Twój podpis (np. Jan)" style="font-size: 0.9rem;">
<textarea id="new-comment-text" class="form-control mb-2" rows="3" placeholder="Wpisz uwagę..."></textarea>
<div style="text-align: right; gap: 5px; display: flex; justify-content: flex-end;">
<button id="cancel-comment" class="btn btn-sm btn-outline-secondary">Anuluj</button>
@@ -155,7 +156,8 @@
// ZAWSZE pozwalamy na interakcję z naszym UI
if (e.target.closest('#prototype-topbar') ||
e.target.closest('#comment-input-box') ||
e.target.closest('.comment-marker')) {
e.target.closest('.comment-marker') ||
e.target.closest('.comment-popover')) { // Dodano popover do wykluczeń
return;
}
@@ -232,7 +234,15 @@
box.style.display = 'block';
// Focus po małym timeout, żeby przeglądarka zdążyła przenieść element
setTimeout(() => document.getElementById('new-comment-text').focus(), 50);
setTimeout(() => {
const authorInput = document.getElementById('new-comment-author');
const savedAuthor = localStorage.getItem('magico_comment_author');
if (savedAuthor) authorInput.value = savedAuthor;
// Focus na tekst, chyba że brak autora
if (!savedAuthor) authorInput.focus();
else document.getElementById('new-comment-text').focus();
}, 50);
}
function closeInputBox() {
@@ -251,11 +261,16 @@
function saveComment() {
const text = document.getElementById('new-comment-text').value;
const author = document.getElementById('new-comment-author').value || 'Anonim';
if (!text || !pendingElement) {
closeInputBox();
return;
}
// Zapisz autora na przyszłość
localStorage.setItem('magico_comment_author', author);
const selector = getCssSelector(pendingElement);
fetch(API_URL + '?action=add', {
@@ -264,7 +279,7 @@
page_path: CURRENT_PATH,
selector: selector,
comment: text,
author: 'User'
author: author
})
})
.then(res => res.json())
@@ -400,12 +415,18 @@
activePopover = pop;
pop._associatedMarker = marker;
// Bindowanie akcji
// Bindowanie akcji z stopPropagation
pop.querySelectorAll('.btn-resolve').forEach(btn => {
btn.addEventListener('click', () => resolveComment(btn.dataset.id));
btn.addEventListener('click', (e) => {
e.stopPropagation(); // Ważne!
resolveComment(btn.dataset.id);
});
});
pop.querySelectorAll('.btn-delete').forEach(btn => {
btn.addEventListener('click', () => deleteComment(btn.dataset.id));
btn.addEventListener('click', (e) => {
e.stopPropagation(); // Ważne!
deleteComment(btn.dataset.id);
});
});
// Obsługa zamykania przy wyjechaniu z popovera