From 1f35f96fe3c46535764aa2ee3bb9625e6e479096 Mon Sep 17 00:00:00 2001 From: ksamuel Date: Thu, 13 Aug 2020 17:26:25 +0200 Subject: [PATCH 1/7] Add padding to paste --- zerobin/static/css/style.css | 1 + 1 file changed, 1 insertion(+) diff --git a/zerobin/static/css/style.css b/zerobin/static/css/style.css index 0bcc2c8..3918d9e 100644 --- a/zerobin/static/css/style.css +++ b/zerobin/static/css/style.css @@ -230,6 +230,7 @@ li.L9 { pre.prettyprint { width: 100%; min-height: 100px; + padding: 5px; } /* Specify class=linenums on a pre to get line numbering */ From 2abbab53053e782f114ef9851d0db49bd9c505c4 Mon Sep 17 00:00:00 2001 From: ksamuel Date: Thu, 13 Aug 2020 18:14:19 +0200 Subject: [PATCH 2/7] Handle paste --- zerobin/static/js/behavior.js | 61 ++++++++++++----------------------- 1 file changed, 20 insertions(+), 41 deletions(-) diff --git a/zerobin/static/js/behavior.js b/zerobin/static/js/behavior.js index 5f43a78..e047e09 100644 --- a/zerobin/static/js/behavior.js +++ b/zerobin/static/js/behavior.js @@ -628,23 +628,31 @@ window.zerobin = { } } - // return total * 250 / size; return total * 1000 / size; }, - // prevent defaults ignoreDrag: function (e) { e.stopPropagation(); e.preventDefault(); }, - // Handle Drop handleDrop: function (e) { e.preventDefault(); zerobin.upload(e.dataTransfer.files); document.getElementById("content").classList.remove("hover"); }, + handlePaste: function (e) { + var items = (event.clipboardData || event.originalEvent.clipboardData).items; + for (var i = 0; i < items.length; i++) { + if (items[i].type.indexOf("image") === 0) { + e.preventDefault() + return zerobin.upload([items[i].getAsFile()]); + } + } + + }, + handleDragOver: function (e) { zerobin.ignoreDrag(e); document.getElementById("content").classList.add('hover'); @@ -656,58 +664,28 @@ window.zerobin = { upload: function (files) { let content = document.getElementById('content'); - var current_file = files[0]; + var currentFile = files[0]; var reader = new FileReader(); - if (current_file.type.indexOf('image') == 0) { + if (currentFile.type.indexOf('image') == 0) { reader.onload = function (event) { var image = new Image(); image.src = event.target.result; image.onload = function () { - var maxWidth = 1024, - maxHeight = 1024, - imageWidth = image.width, - imageHeight = image.height; - - if (imageWidth > imageHeight) { - if (imageWidth > maxWidth) { - imageHeight *= maxWidth / imageWidth; - imageWidth = maxWidth; - } - } else { - if (imageHeight > maxHeight) { - imageWidth *= maxHeight / imageHeight; - imageHeight = maxHeight; - } - } - - var canvas = document.createElement('canvas'); - canvas.width = imageWidth; - canvas.height = imageHeight; - image.width = imageWidth; - image.height = imageHeight; - var ctx = canvas.getContext("2d"); - ctx.drawImage(this, 0, 0, imageWidth, imageHeight); - - var paste = canvas.toDataURL(current_file.type); - - content.value = paste; - content.dispatchEvent(new Event('change')); - - image.style.maxWidth = '742px'; - + var imgWrapper = document.createElement('div'); + imgWrapper.classList.add('paste-wrapper'); + imgWrapper.appendChild(image) content.style.display = "none"; - content.after(image); - + content.after(imgWrapper); } } - reader.readAsDataURL(current_file); + reader.readAsDataURL(currentFile); } else { reader.onload = function (event) { content.value = event.target.result content.dispatchEvent(new Event('change')); }; - reader.readAsText(current_file); + reader.readAsText(currentFile); } } }; @@ -862,6 +840,7 @@ if (app.support.fileUpload) { // Implements drag & drop upload let content = document.getElementById('content'); content.addEventListener('drop', zerobin.handleDrop); + content.addEventListener('paste', zerobin.handlePaste); content.addEventListener('dragover', zerobin.handleDragOver); content.addEventListener('dragleave', zerobin.handleDragLeave); From e667e1f94739bfdaeb7fdff0892e2f827efc847f Mon Sep 17 00:00:00 2001 From: ksamuel Date: Thu, 13 Aug 2020 18:23:11 +0200 Subject: [PATCH 3/7] Add active class on previousPasteMenu --- zerobin/views/base.tpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zerobin/views/base.tpl b/zerobin/views/base.tpl index f251b35..0d73490 100644 --- a/zerobin/views/base.tpl +++ b/zerobin/views/base.tpl @@ -46,10 +46,10 @@