feat: allow file uploads on mobile chat

closes https://github.com/NodeBB/NodeBB/issues/11217
isekai-main
Barış Soner Uşaklı 2 years ago
parent 557198a377
commit 79731735c0

@ -74,6 +74,7 @@ define('forum/chats', [
dragDropAreaEl: $('.chats-full'),
pasteEl: $('[component="chat/input"]'),
uploadFormEl: $('[component="chat/upload"]'),
uploadBtnEl: $('[component="chat/upload/button"]'),
inputEl: $('[component="chat/input"]'),
});
@ -87,6 +88,7 @@ define('forum/chats', [
dragDropAreaEl: options.dragDropAreaEl,
pasteEl: options.pasteEl,
uploadFormEl: options.uploadFormEl,
uploadBtnEl: options.uploadBtnEl,
route: '/api/post/upload', // using same route as post uploads
callback: function (uploads) {
const inputEl = options.inputEl;

@ -304,6 +304,7 @@ define('chat', [
dragDropAreaEl: chatModal.find('.modal-content'),
pasteEl: chatModal,
uploadFormEl: chatModal.find('[component="chat/upload"]'),
uploadBtnEl: $('[component="chat/upload/button"]'),
inputEl: chatModal.find('[component="chat/input"]'),
});

@ -36,6 +36,27 @@ define('uploadHelpers', ['alerts'], function (alerts) {
},
});
}
if (options.uploadBtnEl) {
const fileInput = formEl.find('input[name="files[]"]');
options.uploadBtnEl.on('click', function () {
fileInput.trigger('click');
});
fileInput.on('change', function (e) {
const files = (e.target || {}).files ||
($(this).val() ? [{ name: $(this).val(), type: utils.fileMimeType($(this).val()) }] : null);
if (files) {
uploadHelpers.ajaxSubmit({
uploadForm: formEl,
upload: {
files: files,
fileNames: Array.from(files).map(f => f.name),
},
callback: options.callback,
});
}
});
}
};
uploadHelpers.handleDragDrop = function (options) {

Loading…
Cancel
Save