• Stars
    star
    105
  • Rank 328,196 (Top 7 %)
  • Language
    HTML
  • License
    MIT License
  • Created over 11 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Better HTML5 drag events

I'm no longer actively maintaining Dragster. If you'd like to take over, let me know on this issue

Dragster

✨✨Demo✨✨

HTML5 dragenter and dragleave events are crap. Dragster gives you sane new dragster:enter and dragster:leave events that behave just like mouseenter and mouseleave.

Detecting when the user has dragged over a dropzone with child elements sucks. It usually involves transparent overlay elements, listening to the constantly-firing dragover event or nuking every other event with pointer-events: none.

Dragster is tiny (417 bytes minified & gzipped), unobtrusive & doesn't do much - it just add a couple of event listeners for dragenter and dragleave on the elements that you specify. It never does anything automagically, and doesn't cancel the original events.

Dragster works in latest stable Chrome, Firefox, Safari & Opera. It does nothing at all in IE 7-10 (IE doesn't support DOM event constructors).

@catmanjan maintains a jQuery plugin version of Dragster if you'd like better cross browser support.

Setup

Just include Dragster in your app, then bootstrap your dropzone elements with Dragster so they can start emitting dragster: events.

var dropzone = document.getElementById( "my-dropzone" );
new Dragster( dropzone );

Then you can add some plain old event listeners without pulling your hair out.

document.addEventListener( "dragster:enter", function (e) {
  e.target.classList.add( "dragged-over" );
}, false );

document.addEventListener( "dragster:leave", function (e) {
  e.target.classList.remove( "dragged-over" );
}, false );

You can teardown a Dragster instance by calling removeListeners

dragster = new Dragster( dropzone );
// Dragging over dropzone emits dragster: events
dragster.removeListeners();
// Dragster events no longer emitted from dropzone

Contributing

Dragster is written in CoffeeScript.

npm install
npm run build

License

Dragster is released under the MIT License

More Repositories

1

style

An opinionated starting point for scalable, maintainable CSS architecture.
HTML
491
star
2

webpack-css-example

Example repo showing a webpack CSS build
JavaScript
450
star
3

sample-react-rails-app

Sample Rails app with server-rendered React components
Ruby
206
star
4

tropical

Fast, mostly-just-HTML static sites with islands of client-side JS. Click the "Use this template" button ↖️
JavaScript
162
star
5

tropical-utils

JavaScript
33
star
6

viewloader

A tiny little framework-agnostic JS bootstrapping thing.
JavaScript
32
star
7

structurizr-mini

A static site for C4 diagrams from a Structurizr workspace
JavaScript
22
star
8

coexist

Unobtrusively server-render JS pages from non-JS frameworks.
Ruby
18
star
9

flux-jasmine-rewire-example

An example repo showing how to test Flux stores without Jest, using Jasmine & Rewire instead.
JavaScript
15
star
10

json2css-sprite-mixins

Sprite mixins from json2css' sass template, plus some retina mixins.
CSS
15
star
11

MediaElement.js-Playlist

Turn a list of media links into a playlist using MediaElement.js
JavaScript
12
star
12

cssconfracer

A stupid racing game
JavaScript
10
star
13

boilerplizzle

A fast, flexible starting point for little web projects that gives you tools like Compass, CoffeeScript & your favourite JS & CSS libraries then gets out of your way.
JavaScript
7
star
14

sample-webpack-setup

Just something I'm messing with. You shouldn't use this code. It's probably not good.
JavaScript
6
star
15

going-isomorphic-with-react

JavaScript
4
star
16

metalsmith-json-feed

A Metalsmith plugin for generating a JSON Feed from a collection.
JavaScript
3
star
17

react-style-example

react-style example for melbjs talk
JavaScript
2
star
18

metalsmith-blog-example

A Metalsmith-powered blog.
Shell
2
star
19

css-architecture-on-a-shoestring

Slides from my Decompress presentation
JavaScript
2
star
20

design-friendly-repo-starter

Boilerplate for new open source projects aimed at encouraging contributions from non-devs
1
star
21

allihoopa-mixtape

Allihoopa is dead. Long live Allihoopa.
HTML
1
star
22

panoramx

1
star
23

overthrow-dist

Overthrow doesn't include a built version of the library. This is a bower component with the latest built version.
JavaScript
1
star