forked from gitbot/uguu
support for pasting files
This commit is contained in:
parent
d90f9e58e9
commit
c036012e55
@ -1,5 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright (c) 2016 Luminarys <postmaster@gensok.io>
|
* Copyright (c) 2016 Luminarys <postmaster@gensok.io>
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021 Eric Johansson (Nekunekus) <neku@pomf.se>
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -20,7 +22,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
/**
|
/**
|
||||||
* Sets up the elements inside file upload rows.
|
* Sets up the elements inside file upload rows.
|
||||||
*
|
*
|
||||||
@ -251,6 +253,17 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
target.click();
|
target.click();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Handles the pasting function */
|
||||||
|
window.addEventListener("paste", e =>{
|
||||||
|
var len = e.clipboardData.files.length;
|
||||||
|
for (var i = 0; i < len; i++) {
|
||||||
|
var file = e.clipboardData.files[i];
|
||||||
|
var row = addRow(file);
|
||||||
|
uploadFile(file, row);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
/* Set-up the event handlers for the <button>, <input> and the window itself
|
/* Set-up the event handlers for the <button>, <input> and the window itself
|
||||||
and also set the "js" class on selector "#upload-form", presumably to
|
and also set the "js" class on selector "#upload-form", presumably to
|
||||||
allow custom styles for clients running javascript. */
|
allow custom styles for clients running javascript. */
|
||||||
@ -261,6 +274,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
window.addEventListener('drop', handleDragAway.bind(this, state, uploadButton), false);
|
window.addEventListener('drop', handleDragAway.bind(this, state, uploadButton), false);
|
||||||
window.addEventListener('dragover', stopDefaultEvent, false);
|
window.addEventListener('dragover', stopDefaultEvent, false);
|
||||||
|
|
||||||
|
|
||||||
var uploadInput = document.getElementById('upload-input');
|
var uploadInput = document.getElementById('upload-input');
|
||||||
uploadInput.addEventListener('change', uploadFiles);
|
uploadInput.addEventListener('change', uploadFiles);
|
||||||
uploadButton.addEventListener('click', selectFiles.bind(this, uploadInput));
|
uploadButton.addEventListener('click', selectFiles.bind(this, uploadInput));
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<form id="upload-form" enctype="multipart/form-data" method="post" action="upload.php?output=html">
|
<form id="upload-form" enctype="multipart/form-data" method="post" action="upload.php?output=html">
|
||||||
<button id="upload-btn" class="btn" type="button">Select or drop file(s)</button>
|
<button id="upload-btn" class="btn" type="button">Drop or paste file(s)</button>
|
||||||
<input type="file" id="upload-input" name="files[]" multiple data-max-size="{{max_upload_size}}MiB">
|
<input type="file" id="upload-input" name="files[]" multiple data-max-size="{{max_upload_size}}MiB">
|
||||||
<input type="submit" value="Submit">
|
<input type="submit" value="Submit">
|
||||||
</form>
|
</form>
|
||||||
|
Loading…
Reference in New Issue
Block a user