Avoid handling clipboard data item if it is not file type

This commit is contained in:
Haocen Xu 2020-05-17 01:35:19 -04:00
parent bb9a5772bc
commit 7eb96eb3cb
No known key found for this signature in database
GPG key ID: 3F0D955A0F6AD729

View file

@ -3110,19 +3110,15 @@ jQuery.PrivateBin = (function($, RawDeflate) {
*/
function addClipboardEventHandler() {
$(document).on('paste', function (event) {
const items = (event.clipboardData || event.originalEvent.clipboardData).items;
const lastItem = items[items.length - 1];
if (lastItem.kind === 'file') {
if (TopNav.isAttachmentReadonly()) {
event.stopPropagation();
event.preventDefault();
return false;
}
const items = (event.clipboardData || event.originalEvent.clipboardData).items;
for (let i = 0; i < items.length; ++i) {
if (items[i].kind === 'file') {
//Clear the file input:
$fileInput.wrap('<form>').closest('form').get(0).reset();
$fileInput.unwrap();
readFileData(items[i].getAsFile());
} else {
readFileData(lastItem.getAsFile());
}
}
});