Mercurial > libervia-web
changeset 1540:b4342176fa0a
browser (chat): minor reformatting
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 28 Jun 2023 10:06:54 +0200 |
parents | bc856e74f74d |
children | 3c384b51b2a1 |
files | libervia/web/pages/chat/_browser/__init__.py |
diffstat | 1 files changed, 17 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/libervia/web/pages/chat/_browser/__init__.py Wed Jun 28 10:05:16 2023 +0200 +++ b/libervia/web/pages/chat/_browser/__init__.py Wed Jun 28 10:06:54 2023 +0200 @@ -19,7 +19,6 @@ class LiberviaWebChat: - def __init__(self): self.message_tpl = Template("chat/message.html") self.messages_elt = document["messages"] @@ -48,7 +47,6 @@ <= SCROLL_SENSITIVITY ) - def send_message(self): """Send message currently in input area @@ -219,13 +217,13 @@ def on_attachment_delete(self, evt): evt.stopPropagation() target = evt.currentTarget - item_elt = DOMNode(target.closest('.attachment-preview')) + item_elt = DOMNode(target.closest(".attachment-preview")) item_elt.remove() def on_attach_button_click(self, evt): document["file_input"].click() - @bind(document["attachments"], 'wheel') + @bind(document["attachments"], "wheel") def wheel_event(evt): """Make the mouse wheel to act on horizontal scrolling for attachments @@ -233,43 +231,43 @@ for horizontal scrolling """ if evt.deltaY != 0: - document['attachments'].scrollLeft += evt.deltaY * 0.8 + document["attachments"].scrollLeft += evt.deltaY * 0.8 evt.preventDefault() - def make_attachments_dynamic(self, parent_elt = None): + def make_attachments_dynamic(self, parent_elt=None): """Make attachments dynamically clickable""" # FIXME: only handle images for now, and display them in a modal if parent_elt is None: parent_elt = document - img_elts = parent_elt.select('.message-attachment img') + img_elts = parent_elt.select(".message-attachment img") for img_elt in img_elts: - img_elt.bind('click', self.open_modal) - img_elt.style.cursor = 'pointer' + img_elt.bind("click", self.open_modal) + img_elt.style.cursor = "pointer" - close_button = document.select_one('.modal-close') - close_button.bind('click', self.close_modal) + close_button = document.select_one(".modal-close") + close_button.bind("click", self.close_modal) def open_modal(self, evt): - modal_image = document.select_one('#modal-image') + modal_image = document.select_one("#modal-image") modal_image.src = evt.target.src modal_image.alt = evt.target.alt - modal = document.select_one('#modal') - modal.classList.add('is-active') + modal = document.select_one("#modal") + modal.classList.add("is-active") def close_modal(self, evt): - modal = document.select_one('#modal') - modal.classList.remove('is-active') + modal = document.select_one("#modal") + modal.classList.remove("is-active") libervia_web_chat = LiberviaWebChat() + document["message_input"].bind( "input", lambda __: libervia_web_chat.auto_resize_message_input() ) document["message_input"].bind("keydown", libervia_web_chat.on_message_keydown) document["send_button"].bind("click", lambda __: libervia_web_chat.send_message()) -document["attach_button"].bind( - "click", libervia_web_chat.on_attach_button_click -) +document["attach_button"].bind("click", libervia_web_chat.on_attach_button_click) document["file_input"].bind("change", libervia_web_chat.on_file_selected) bridge.register_signal("message_new", libervia_web_chat._on_message_new) + libervia_web_chat.make_attachments_dynamic()