Handle uploads using Ctrl-V
This commit is contained in:
parent
499c59b761
commit
1d364de8c8
3 changed files with 48 additions and 2 deletions
|
|
@ -54,3 +54,42 @@ upload_form_files_selected = function() {
|
||||||
$('#file-form').submit(); // start upload
|
$('#file-form').submit(); // start upload
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
function upload_paste(event){
|
||||||
|
console.log("paste!");
|
||||||
|
var items = (event.clipboardData || event.originalEvent.clipboardData).items;
|
||||||
|
|
||||||
|
// /*Make Sure Only One File is Copied*/
|
||||||
|
// if (items.length != 1) {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
for (var i = 0 ; i < items.length ; i++) {
|
||||||
|
var item = items[i];
|
||||||
|
if (!item.type.startsWith('image/')){ continue }
|
||||||
|
var file = item.getAsFile();
|
||||||
|
console.log(file);
|
||||||
|
upload_file_with_ajax(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function upload_file_with_ajax(file){
|
||||||
|
var formData = new FormData();
|
||||||
|
formData.append('file', file);
|
||||||
|
|
||||||
|
$.ajax('#{{upload_receive_path}}' , {
|
||||||
|
|
||||||
|
type: 'POST',
|
||||||
|
contentType: false,
|
||||||
|
processData: false,
|
||||||
|
data: formData,
|
||||||
|
dataType: 'text',
|
||||||
|
error: function(xhr, txt, err) {
|
||||||
|
console.log("error: "+txt+" / "+err);
|
||||||
|
},
|
||||||
|
success: function(res) {
|
||||||
|
console.log("AJAX file upload was ok");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,12 @@ class PackagesController < ApplicationController
|
||||||
|
|
||||||
all_errors = []
|
all_errors = []
|
||||||
|
|
||||||
params[:file].each do |img|
|
files = params[:file]
|
||||||
|
|
||||||
|
# Turn into array if a single image was uploaded through AJAX
|
||||||
|
files=[files] if files.class != Array
|
||||||
|
|
||||||
|
files.each do |img|
|
||||||
# Log.log "Uploaded img=#{img.path}"
|
# Log.log "Uploaded img=#{img.path}"
|
||||||
new_screenshot = @package.screenshots.new(simage: img)
|
new_screenshot = @package.screenshots.new(simage: img)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -66,4 +66,6 @@ h1 = "Upload screenshots for #{@package.name}"
|
||||||
javascript:
|
javascript:
|
||||||
// Hide the submit button unless images are selected for upload
|
// Hide the submit button unless images are selected for upload
|
||||||
$(document).ready(upload_form_init);
|
$(document).ready(upload_form_init);
|
||||||
// TODO: Move into javascripts/packages/upload...
|
|
||||||
|
// Handle Ctrl-V to paste an image directly
|
||||||
|
document.onpaste = upload_paste;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue