From fd9499d79c170af803a7f018baa01f51792e3368 Mon Sep 17 00:00:00 2001 From: Doug Patti Date: Fri, 20 Jul 2012 21:44:51 -0400 Subject: [PATCH] Allow file uploading via clipboard paste --- js/upload.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/js/upload.js b/js/upload.js index 5e608f3..66e9472 100644 --- a/js/upload.js +++ b/js/upload.js @@ -129,4 +129,26 @@ $(function(){ dropbox.trigger(e); } }); + + // Clipboard paste support + $(document).bind("paste", function(e) { + if (e.originalEvent && e.originalEvent.clipboardData && e.originalEvent.clipboardData.items) { + var items = e.originalEvent.clipboardData.items; + for (var i = 0; i < items.length; i++) { + var file = items[i]; + if (file.type == "image/png") { + // Send this as if it were dropped + file = file.getAsFile(); + file.name = "paste_" + Math.random().toString(16).slice(2) + ".png"; + var e = $.Event("drop", { + dataTransfer: { + files: [file], + }, + }); + dropbox.trigger(e); + return; + } + } + } + }); });