From 8f3929875f548da32ec0f349a0905556e1b7526e Mon Sep 17 00:00:00 2001 From: Emmy D'Anello Date: Sun, 28 Apr 2024 20:25:00 +0200 Subject: [PATCH] Improve context menus Signed-off-by: Emmy D'Anello --- chat/static/chat.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/chat/static/chat.js b/chat/static/chat.js index 74567f1..95a63a4 100644 --- a/chat/static/chat.js +++ b/chat/static/chat.js @@ -199,7 +199,7 @@ function redrawMessages() { messageContentSpan.innerText = message['content'] messageContentDiv.appendChild(messageContentSpan) - registerMessageContextMenu(message, messageContentSpan) + registerMessageContextMenu(message, messageContentDiv, messageContentSpan) continue } } @@ -216,7 +216,7 @@ function redrawMessages() { authorSpan.innerText = message['author'] authorDiv.appendChild(authorSpan) - registerSendPrivateMessageContextMenu(message, authorSpan) + registerSendPrivateMessageContextMenu(message, authorDiv, authorSpan) let dateSpan = document.createElement('span') dateSpan.classList.add('text-muted', 'float-end') @@ -232,7 +232,7 @@ function redrawMessages() { messageContentSpan.innerText = message['content'] messageContentDiv.appendChild(messageContentSpan) - registerMessageContextMenu(message, messageContentSpan) + registerMessageContextMenu(message, messageContentDiv, messageContentSpan) lastMessage = message lastContentDiv = contentDiv @@ -253,11 +253,11 @@ function removeAllPopovers() { } } -function registerSendPrivateMessageContextMenu(message, element) { - element.addEventListener('contextmenu', (menu_event) => { +function registerSendPrivateMessageContextMenu(message, div, span) { + div.addEventListener('contextmenu', (menu_event) => { menu_event.preventDefault() removeAllPopovers() - const popover = bootstrap.Popover.getOrCreateInstance(element, { + const popover = bootstrap.Popover.getOrCreateInstance(span, { 'title': message['author'], 'content': `Envoyer un message privé`, 'html': true, @@ -275,8 +275,8 @@ function registerSendPrivateMessageContextMenu(message, element) { }) } -function registerMessageContextMenu(message, element) { - element.addEventListener('contextmenu', (menu_event) => { +function registerMessageContextMenu(message, div, span) { + div.addEventListener('contextmenu', (menu_event) => { menu_event.preventDefault() removeAllPopovers() let content = `Envoyer un message privé` @@ -288,7 +288,7 @@ function registerMessageContextMenu(message, element) { content += `Supprimer` } - const popover = bootstrap.Popover.getOrCreateInstance(element, { + const popover = bootstrap.Popover.getOrCreateInstance(span, { 'content': content, 'html': true, 'placement': 'bottom', @@ -321,7 +321,7 @@ function registerMessageContextMenu(message, element) { document.getElementById('delete-message-' + message['id']).addEventListener('click', event => { event.preventDefault() popover.dispose() - if (confirm("Supprimer le message ?")) { + if (confirm(`Supprimer le message ?\n${message['content']}`)) { socket.send(JSON.stringify({ 'type': 'delete_message', 'message_id': message['id'],