diff --git a/assets/js/comments.js b/assets/js/comments.js index f1446a5..058157f 100644 --- a/assets/js/comments.js +++ b/assets/js/comments.js @@ -35,6 +35,7 @@
Dodaj notatkę
+
@@ -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