0

As I know it is not possible to upload the files by hooking paste event by javascript.
But I have found such thing on trello.com
How to reproduce:

Only on windows and with google chrome I can'not reproduce it on linux ff or chrome

  1. Create a new card
  2. Click on it -> it's form appeared
  3. Click on comment text area
  4. Make screenshot by PrnScr, Ctrl+V -> upload process started (green progress bar in right top corner)

So how do they implemented it?

Fabrizio
  • 7,603
  • 6
  • 44
  • 104
freemanoid
  • 14,592
  • 6
  • 54
  • 77

1 Answers1

1

In Trello, they use an event handler registered on the paste event and basically accessing event.clipboardData.items.

The javascript code (here) is minified, hence not particularly easy to read, but it basically boils down to applying the trick found in that other question

Extract of the paste handler:

        c.prototype.paste = function (b) {
            var c, f, e, g, h, k, m, l;
            e = null;
            h = this.handlers;
            for (g in h)
                if (c = h[g], null != c.paste) {
                    e = c.paste;
                    break
                }
            if (null != e && (f = null != (k = null != (m = b.originalEvent) ? null != (l = m.clipboardData) ? l.items : void 0 : void 0) ? k : [], b = function (b) {
                return _.detect(f, function (c) {
                    return c.type === b
                })
            }, !b("text/plain") && (b = b("image/png"), null != b && (b = b.getAsFile(), null != b)))) return j.validFileSize(b) ? (n("Keyboard Shortcuts", "Paste - Upload Image From Clipboard"), e(b)) : P.show("File size exceeds 10mb limit",
                "error", "upload", 5E3)
        };    
Community
  • 1
  • 1
Gerard Yin
  • 1,283
  • 1
  • 12
  • 24