Allow paste file and images into chat input form
This commit is contained in:
parent
175a91f979
commit
7fe329b5cf
|
@ -319,12 +319,10 @@ export function hasPendingFileAttachment() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays file information in the message sending form.
|
* Displays file information in the message sending form.
|
||||||
|
* @param {File} file File object
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
async function onFileAttach() {
|
async function onFileAttach(file) {
|
||||||
const fileInput = document.getElementById('file_form_input');
|
|
||||||
if (!(fileInput instanceof HTMLInputElement)) return;
|
|
||||||
const file = fileInput.files[0];
|
|
||||||
if (!file) return;
|
if (!file) return;
|
||||||
|
|
||||||
const isValid = await validateFile(file);
|
const isValid = await validateFile(file);
|
||||||
|
@ -1503,8 +1501,28 @@ jQuery(function () {
|
||||||
$(document).on('click', '.mes_img_enlarge', enlargeMessageImage);
|
$(document).on('click', '.mes_img_enlarge', enlargeMessageImage);
|
||||||
$(document).on('click', '.mes_img_delete', deleteMessageImage);
|
$(document).on('click', '.mes_img_delete', deleteMessageImage);
|
||||||
|
|
||||||
$('#file_form_input').on('change', onFileAttach);
|
$('#file_form_input').on('change', async () => {
|
||||||
|
const fileInput = document.getElementById('file_form_input');
|
||||||
|
if (!(fileInput instanceof HTMLInputElement)) return;
|
||||||
|
const file = fileInput.files[0];
|
||||||
|
await onFileAttach(file);
|
||||||
|
});
|
||||||
$('#file_form').on('reset', function () {
|
$('#file_form').on('reset', function () {
|
||||||
$('#file_form').addClass('displayNone');
|
$('#file_form').addClass('displayNone');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
document.getElementById('send_textarea').addEventListener('paste', async function (event) {
|
||||||
|
if (event.clipboardData.files.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
|
||||||
|
const fileInput = document.getElementById('file_form_input');
|
||||||
|
if (!(fileInput instanceof HTMLInputElement)) return;
|
||||||
|
|
||||||
|
fileInput.files = event.clipboardData.files;
|
||||||
|
await onFileAttach(fileInput.files[0]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue