added hover and show original/translated
This commit is contained in:
parent
5d4423ddb0
commit
dcfeb416ec
|
@ -82,6 +82,7 @@ class PagesController < ApplicationController
|
||||||
|
|
||||||
ActionCable.server.broadcast "chat_room_#{params[:chat_room_id]}", {
|
ActionCable.server.broadcast "chat_room_#{params[:chat_room_id]}", {
|
||||||
translated_message: translated_message,
|
translated_message: translated_message,
|
||||||
|
original_message: message,
|
||||||
userId: userId,
|
userId: userId,
|
||||||
photo_url: params[:photo_url]
|
photo_url: params[:photo_url]
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,13 +79,21 @@ App['chatroom' + chatroomId] = App.cable.subscriptions.create({
|
||||||
|
|
||||||
const messageElement = document.createElement("p")
|
const messageElement = document.createElement("p")
|
||||||
messageElement.classList.add("message")
|
messageElement.classList.add("message")
|
||||||
messageElement.classList.add("message")
|
|
||||||
messageElement.classList.add("no-margin")
|
messageElement.classList.add("no-margin")
|
||||||
messageElement.innerText = data["translated_message"]
|
messageElement.innerText = data["translated_message"]
|
||||||
|
messageElement.setAttribute('data-original', `${data["original_message"]}`)
|
||||||
|
messageElement.setAttribute('data-translated', `${data["translated_message"]}`)
|
||||||
|
|
||||||
messageDiv.appendChild(photo)
|
messageDiv.appendChild(photo)
|
||||||
messageDiv.appendChild(messageElement)
|
messageDiv.appendChild(messageElement)
|
||||||
|
|
||||||
|
messageDiv.addEventListener('mouseover', event => {
|
||||||
|
messageElement.innerText = data["original_message"]
|
||||||
|
})
|
||||||
|
messageDiv.addEventListener('mouseout', event => {
|
||||||
|
messageElement.innerText = data["translated_message"]
|
||||||
|
})
|
||||||
|
|
||||||
messagesContainer.appendChild(messageDiv)
|
messagesContainer.appendChild(messageDiv)
|
||||||
} else {
|
} else {
|
||||||
// console.log(data)
|
// console.log(data)
|
||||||
|
@ -119,6 +127,23 @@ hangUpIcon.addEventListener('click', event => {
|
||||||
// })
|
// })
|
||||||
// })
|
// })
|
||||||
|
|
||||||
|
const originalBtn = document.getElementById('original-btn')
|
||||||
|
originalBtn.addEventListener('click', event => {
|
||||||
|
originalBtn.classList.toggle('original')
|
||||||
|
const allMessages = document.querySelectorAll('.messageDiv:not(.right) > p')
|
||||||
|
|
||||||
|
if (originalBtn.classList.contains('original')) {
|
||||||
|
originalBtn.innerText = "Show Original"
|
||||||
|
allMessages.forEach(message => {
|
||||||
|
message.innerText = message.dataset.translated
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
originalBtn.innerText = "Show Translated"
|
||||||
|
allMessages.forEach(message => {
|
||||||
|
message.innerText = message.dataset.original
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
const sendBtn = document.getElementById('send-btn')
|
const sendBtn = document.getElementById('send-btn')
|
||||||
sendBtn.addEventListener('click', event => {
|
sendBtn.addEventListener('click', event => {
|
||||||
|
|
|
@ -32,7 +32,9 @@
|
||||||
<input type="text" class="form-control" name="chat-input" id="chat-input" value="">
|
<input type="text" class="form-control" name="chat-input" id="chat-input" value="">
|
||||||
<span class="input-group-btn">
|
<span class="input-group-btn">
|
||||||
<button class="btn btn-primary form-control" id="send-btn" type="submit" remote: true>Send</button>
|
<button class="btn btn-primary form-control" id="send-btn" type="submit" remote: true>Send</button>
|
||||||
<!-- <i class="far fa-paper-plane"></i> -->
|
</span>
|
||||||
|
<span class="input-group-btn">
|
||||||
|
<button class="btn btn-danger form-control" id="original-btn" type="submit" remote: true>Show Original</button>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue