Commit 6ae3b791 authored by maeda's avatar maeda

Allow pasting screenshots from clipboard (#3816).

Patch by Takenori TAKAKI and Marius BALTEANU.


git-svn-id: https://svn.redmine.org/redmine/trunk@17874 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 68203481
......@@ -201,7 +201,8 @@ function setupFileDrop() {
$(this).on({
dragover: dragOverHandler,
dragleave: dragOutHandler,
drop: handleFileDropEvent
drop: handleFileDropEvent,
paste: copyImageFromClipboard
}).addClass('filedroplistner');
});
}
......@@ -250,6 +251,33 @@ function addInlineAttachmentMarkup(file) {
}
}
function copyImageFromClipboard(e) {
if (!$(e.target).hasClass('wiki-edit')) { return; }
var clipboardData = e.clipboardData || e.originalEvent.clipboardData
if (!clipboardData) { return; }
var items = clipboardData.items
for (var i = 0 ; i < items.length ; i++) {
var item = items[i];
if (item.type.indexOf("image") != -1) {
var blob = item.getAsFile();
var date = new Date();
var filename = 'clipboard-'
+ date.getFullYear()
+ ('0'+(date.getMonth()+1)).slice(-2)
+ ('0'+date.getDate()).slice(-2)
+ ('0'+date.getHours()).slice(-2)
+ ('0'+date.getMinutes()).slice(-2)
+ '-' + randomKey(5).toLocaleLowerCase()
+ '.' + blob.name.split('.').pop();
var file = new File([blob], filename, {type: blob.type});
var inputEl = $('input:file.filedrop').first()
handleFileDropEvent.target = e.target;
addFile(inputEl, file, true);
}
}
}
$(document).ready(setupFileDrop);
$(document).ready(function(){
$("input.deleted_attachment").change(function(){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment