From 24aea957b358cbe85a39a3167ebe1c64aa7bc2dc Mon Sep 17 00:00:00 2001 From: thororm Date: Sat, 13 May 2017 21:43:32 +0200 Subject: [PATCH] Added possibility to paste an image from the clipboard --- i18n/de.json | 2 +- js/privatebin.js | 18 ++++++++++++++++++ tpl/bootstrap.php | 4 ++-- tpl/page.php | 4 ++-- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/i18n/de.json b/i18n/de.json index 19edcbdc..6c0ad332 100644 --- a/i18n/de.json +++ b/i18n/de.json @@ -132,7 +132,7 @@ "Cloned: '%s'": "Geklont: '%s'", "The cloned file '%s' was attached to this paste.": "Die geklonte Datei '%s' wurde angehängt.", "Attach a file": "Datei anhängen", - "or drag & drop file": "oder per Drag & Drop einfügen", + "alternatively drag & drop a file or paste an image from the clipboard": "Alternativ Drag & Drop einer Datei oder einfügen eines Bildes aus der Zwischenablage", "File too large, to display a preview. Please download the attachment.": "Datei zu groß, um als Vorschau angezeigt zu werden. Bitte Anhang herunterladen.", "Remove attachment": "Anhang entfernen", "Your browser does not support uploading encrypted files. Please use a newer browser.": diff --git a/js/privatebin.js b/js/privatebin.js index 2d7badd8..77e393fe 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -2298,6 +2298,23 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { }); }; + /** + * Attaches the clipboard attachment handler to the page. + * @returns {undefined} + */ + me.addClipboardEventHandler = function () { + document.addEventListener("paste", + function (event) { + var items = (event.clipboardData || event.originalEvent.clipboardData).items; + for (var i in items) { + var item = items[i]; + if (item.kind === 'file') { + me.readFileData(item.getAsFile()); + } + } + }, false); + }; + /** * initiate * @@ -2315,6 +2332,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { me.$fileInput = $('#file'); me.addDragDropHandler(); + me.addClipboardEventHandler(); } } diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index 0c5f6197..13b93eb3 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -69,7 +69,7 @@ if ($MARKDOWN): - + @@ -283,7 +283,7 @@ if ($FILEUPLOAD):
-
+
  • diff --git a/tpl/page.php b/tpl/page.php index b6fb26a4..06b9026c 100644 --- a/tpl/page.php +++ b/tpl/page.php @@ -47,7 +47,7 @@ if ($MARKDOWN): - + @@ -203,7 +203,7 @@ if ($FILEUPLOAD):