Socket
Socket
Sign inDemoInstall

drag-drop

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

drag-drop

Unfuck the HTML5 drag & drop API


Version published
Weekly downloads
15K
increased by29.72%
Maintainers
1
Weekly downloads
 
Created
Source

drag-drop

Build Status NPM Version NPM Gittip

browser support

Unfuck the HTML5 drag & drop API

Also works in the browser with browserify!

install

npm install drag-drop

usage

var dragDrop = require('drag-drop')
var dropTarget = document.querySelector('#dropTarget')

dragDrop(dropTarget, function (files) {
  console.log('Here are the dropped files', files)
})

Another handy thing this does is add a drag class to the drop target when the user is dragging a file over the drop target. Useful for styling the drop target to make it obvious that this is a drop target!

a more complete example

var dragDrop = require('drag-drop')
var dropTarget = document.querySelector('#dropTarget')

dragDrop(dropTarget, function (files) {
  console.log('Here are the dropped files', files)

  // `files` is an Array!
  files.forEach(function (file) {

    // convert the file to a Buffer that we can use!
    var reader = new FileReader()
    reader.addEventListener('load', function (e) {
      // e.target.result is an ArrayBuffer
      var arr = new Uint8Array(e.target.result)
      var buffer = new Buffer(arr)

      // do something with the buffer!
    })
    reader.addEventListener('error', function (err) {
      console.error('FileReader error' + err)
    })
    reader.readAsArrayBuffer(file)
  })
})

license

MIT. Copyright (c) Feross Aboukhadijeh.

Keywords

FAQs

Package last updated on 05 Mar 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc