From 4baf4bd43c646428ac39306eb67bc718db5094a2 Mon Sep 17 00:00:00 2001 From: clsr Date: Fri, 16 Dec 2016 16:06:41 +0100 Subject: Add support for uploading pasted blobs --- static/gomf.js | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/static/gomf.js b/static/gomf.js index da14d14..86bb007 100644 --- a/static/gomf.js +++ b/static/gomf.js @@ -95,10 +95,6 @@ input.type = 'text'; input.readOnly = true; input.value = resp; - console.log(input); - console.log(resp); - console.log(input.value); - console.log(input.value.length); input.size = input.value.length; input.addEventListener('click', function() { this.select(); @@ -162,17 +158,38 @@ upload(e.dataTransfer.files); }; + var paste = function(e) { + var data = e.clipboardData || e.originalEvent.clipboardData; + var items = data.items; + var files = []; + for (var i in items) { + var item = items[i]; + if (item.kind == 'file') { + var f = item.getAsFile(); + f.name = f.name || 'clipboard-' + i; + files.push(f); + } + } + if (files.length) { + upload(files); + } + } + fileInput.addEventListener('change', submit); fileInput.addEventListener('dragenter', dragenter); fileInput.addEventListener('dragover', dragenter); fileInput.addEventListener('drop', drop); + fileInput.focus(); + fileName.textContent = 'Select or drop files here'; fileName.originalText = fileName.textContent; fileDiv.className = 'file'; fileInput.multiple = 'multiple'; fileSubmit.style.display = 'none'; + document.addEventListener('paste', paste); + updateName(); }; -- cgit