Improve context menus
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
parent
f26f102650
commit
8f3929875f
|
@ -199,7 +199,7 @@ function redrawMessages() {
|
||||||
messageContentSpan.innerText = message['content']
|
messageContentSpan.innerText = message['content']
|
||||||
messageContentDiv.appendChild(messageContentSpan)
|
messageContentDiv.appendChild(messageContentSpan)
|
||||||
|
|
||||||
registerMessageContextMenu(message, messageContentSpan)
|
registerMessageContextMenu(message, messageContentDiv, messageContentSpan)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -216,7 +216,7 @@ function redrawMessages() {
|
||||||
authorSpan.innerText = message['author']
|
authorSpan.innerText = message['author']
|
||||||
authorDiv.appendChild(authorSpan)
|
authorDiv.appendChild(authorSpan)
|
||||||
|
|
||||||
registerSendPrivateMessageContextMenu(message, authorSpan)
|
registerSendPrivateMessageContextMenu(message, authorDiv, authorSpan)
|
||||||
|
|
||||||
let dateSpan = document.createElement('span')
|
let dateSpan = document.createElement('span')
|
||||||
dateSpan.classList.add('text-muted', 'float-end')
|
dateSpan.classList.add('text-muted', 'float-end')
|
||||||
|
@ -232,7 +232,7 @@ function redrawMessages() {
|
||||||
messageContentSpan.innerText = message['content']
|
messageContentSpan.innerText = message['content']
|
||||||
messageContentDiv.appendChild(messageContentSpan)
|
messageContentDiv.appendChild(messageContentSpan)
|
||||||
|
|
||||||
registerMessageContextMenu(message, messageContentSpan)
|
registerMessageContextMenu(message, messageContentDiv, messageContentSpan)
|
||||||
|
|
||||||
lastMessage = message
|
lastMessage = message
|
||||||
lastContentDiv = contentDiv
|
lastContentDiv = contentDiv
|
||||||
|
@ -253,11 +253,11 @@ function removeAllPopovers() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function registerSendPrivateMessageContextMenu(message, element) {
|
function registerSendPrivateMessageContextMenu(message, div, span) {
|
||||||
element.addEventListener('contextmenu', (menu_event) => {
|
div.addEventListener('contextmenu', (menu_event) => {
|
||||||
menu_event.preventDefault()
|
menu_event.preventDefault()
|
||||||
removeAllPopovers()
|
removeAllPopovers()
|
||||||
const popover = bootstrap.Popover.getOrCreateInstance(element, {
|
const popover = bootstrap.Popover.getOrCreateInstance(span, {
|
||||||
'title': message['author'],
|
'title': message['author'],
|
||||||
'content': `<a id="send-private-message-link-${message['id']}" class="nav-link" href="#" tabindex="0">Envoyer un message privé</a>`,
|
'content': `<a id="send-private-message-link-${message['id']}" class="nav-link" href="#" tabindex="0">Envoyer un message privé</a>`,
|
||||||
'html': true,
|
'html': true,
|
||||||
|
@ -275,8 +275,8 @@ function registerSendPrivateMessageContextMenu(message, element) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function registerMessageContextMenu(message, element) {
|
function registerMessageContextMenu(message, div, span) {
|
||||||
element.addEventListener('contextmenu', (menu_event) => {
|
div.addEventListener('contextmenu', (menu_event) => {
|
||||||
menu_event.preventDefault()
|
menu_event.preventDefault()
|
||||||
removeAllPopovers()
|
removeAllPopovers()
|
||||||
let content = `<a id="send-private-message-link-msg-${message['id']}" class="nav-link" href="#" tabindex="0">Envoyer un message privé</a>`
|
let content = `<a id="send-private-message-link-msg-${message['id']}" class="nav-link" href="#" tabindex="0">Envoyer un message privé</a>`
|
||||||
|
@ -288,7 +288,7 @@ function registerMessageContextMenu(message, element) {
|
||||||
content += `<a id="delete-message-${message['id']}" class="nav-link" href="#" tabindex="0">Supprimer</a>`
|
content += `<a id="delete-message-${message['id']}" class="nav-link" href="#" tabindex="0">Supprimer</a>`
|
||||||
}
|
}
|
||||||
|
|
||||||
const popover = bootstrap.Popover.getOrCreateInstance(element, {
|
const popover = bootstrap.Popover.getOrCreateInstance(span, {
|
||||||
'content': content,
|
'content': content,
|
||||||
'html': true,
|
'html': true,
|
||||||
'placement': 'bottom',
|
'placement': 'bottom',
|
||||||
|
@ -321,7 +321,7 @@ function registerMessageContextMenu(message, element) {
|
||||||
document.getElementById('delete-message-' + message['id']).addEventListener('click', event => {
|
document.getElementById('delete-message-' + message['id']).addEventListener('click', event => {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
popover.dispose()
|
popover.dispose()
|
||||||
if (confirm("Supprimer le message ?")) {
|
if (confirm(`Supprimer le message ?\n${message['content']}`)) {
|
||||||
socket.send(JSON.stringify({
|
socket.send(JSON.stringify({
|
||||||
'type': 'delete_message',
|
'type': 'delete_message',
|
||||||
'message_id': message['id'],
|
'message_id': message['id'],
|
||||||
|
|
Loading…
Reference in New Issue