add close attachments button & esc

This commit is contained in:
Martti Malmi 2020-05-16 07:50:56 +03:00
parent 2db891ed02
commit 75e6b30888
2 changed files with 36 additions and 12 deletions

View File

@ -391,6 +391,11 @@ header #back-button {
max-height: 60vh; max-height: 60vh;
} }
#attachment-preview button {
display: block;
margin-bottom: 10px;
}
#message-list { #message-list {
display: flex; display: flex;
max-width: 700px; max-width: 700px;

View File

@ -327,27 +327,47 @@ if (!iris.util.isMobile) {
}); });
} }
$(document).keyup(function(e) {
if (e.key === "Escape") { // escape key maps to keycode `27`
closeAttachmentsPreview();
}
});
function openAttachmentsPreview() {
var attachmentsPreview = $('#attachment-preview');
attachmentsPreview.empty();
var closeBtn = $('<button>').text('Cancel').click(closeAttachmentsPreview);
attachmentsPreview.append(closeBtn);
$('#attach-file').click(event => {
event.preventDefault();
$('#attachment-input').click();
})
$('#attachment-input').change(e => {
$('#attachment-preview').empty();
var files = $('#attachment-input')[0].files; var files = $('#attachment-input')[0].files;
if (files) { if (files) {
$('#attachment-preview').show(); attachmentsPreview.show();
$('#message-list').hide(); $('#message-list').hide();
for (var i = 0;i < files.length;i++) { for (var i = 0;i < files.length;i++) {
getBase64(files[i]).then(base64 => { getBase64(files[i]).then(base64 => {
chats[activeChat].attachments = chats[activeChat].attachments || []; chats[activeChat].attachments = chats[activeChat].attachments || [];
chats[activeChat].attachments.push({type: 'image', data: base64}); chats[activeChat].attachments.push({type: 'image', data: base64});
var preview = $('<img>').attr('src', base64); var preview = $('<img>').attr('src', base64);
$('#attachment-preview').append(preview); attachmentsPreview.append(preview);
}); });
} }
} }
}); }
function closeAttachmentsPreview() {
$('#attachment-preview').hide();
$('#message-list').show();
$('#message-view').scrollTop($('#message-view')[0].scrollHeight - $('#message-view')[0].clientHeight);
if (activeChat) {
chats[activeChat].attachments = null;
}
}
$('#attach-file').click(event => {
event.preventDefault();
$('#attachment-input').click();
})
$('#attachment-input').change(openAttachmentsPreview);
$('#desktop-application-about').toggle(!iris.util.isMobile && !iris.util.isElectron); $('#desktop-application-about').toggle(!iris.util.isMobile && !iris.util.isElectron);
@ -463,6 +483,7 @@ function resetView() {
$("#header-content").empty(); $("#header-content").empty();
$("#header-content").css({cursor: null}); $("#header-content").css({cursor: null});
$('#private-key-qr').remove(); $('#private-key-qr').remove();
closeAttachmentsPreview();
} }
function showMenu(show = true) { function showMenu(show = true) {
@ -992,9 +1013,7 @@ function showChat(pub) {
msg.attachments = chats[pub].attachments; msg.attachments = chats[pub].attachments;
} }
chats[pub].send(msg); chats[pub].send(msg);
chats[pub].attachments = null; closeAttachmentsPreview();
$('#attachment-preview').hide();
$('#message-list').show();
$('#new-msg').val(''); $('#new-msg').val('');
}); });
changeChatUnseenCount(pub, 0); changeChatUnseenCount(pub, 0);