summaryrefslogtreecommitdiffstats
path: root/public/javascripts
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2019-02-17 21:55:24 +0000
committerGo MAEDA <maeda@farend.jp>2019-02-17 21:55:24 +0000
commit66be1ff1061abc452a107886de9e16231c97a72a (patch)
tree0fda731d5ffa2b9a3ff8e313d14b5cfe038a55e8 /public/javascripts
parent675b0c641df7fb47b6f26eb44877e511e8e97718 (diff)
downloadredmine-66be1ff1061abc452a107886de9e16231c97a72a.tar.gz
redmine-66be1ff1061abc452a107886de9e16231c97a72a.zip
Allow pasting screenshots from clipboard (#3816).
Patch by Takenori TAKAKI and Marius BALTEANU. git-svn-id: http://svn.redmine.org/redmine/trunk@17874 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'public/javascripts')
-rw-r--r--public/javascripts/attachments.js30
1 files changed, 29 insertions, 1 deletions
diff --git a/public/javascripts/attachments.js b/public/javascripts/attachments.js
index 753855f91..d7f8d41fa 100644
--- a/public/javascripts/attachments.js
+++ b/public/javascripts/attachments.js
@@ -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(){