heycarsten / ember-drag-drop-example

An example of a way that you can use HTML5 drag and drop in your Ember app.

Home Page:http://ember-drag-drop-example.s3-website-us-east-1.amazonaws.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HTML5 Drag & Drop and Ember

HTML5 Drag & Drop is pretty cool, it was primarily designed with the idea of dragging data in and out of the browser, but it can also be used for dragging elements inside the browser too. It doesn't support locking drags to the x or y axis, but with some smart CSS you can still provide a pretty great experience for your users.

The D-L

DnD accels at moving data in and out of the browser, with the ironic exception of IE (sadly, yes, even 11), Microsoft having designed the specification in the first place. I don't show you how to move data in and out of the browser here, but all of events are the same. If you are interested in that, you'll want to look into the dataTransfer property of the dragstart and drop events, it provides access to any files and content dropped onto an element you've deemed droppable.

This example shows you how to capture the events in an Ember component, and then use them to implement swapping items through dragging.

The Example

Check it out here

On the homepage you'll see two buttons, Disrupt Order and Position Veritcals. If you click Disrupt Order you'll be taken to page of tiles, you can enable/disable sorting by checking the Enable Disruption check box. Drag a tile over another one to swap them. The other section Position Veritcals, was going to demonstrate inserting an item above or below an existing one in a vertical list, I ran out of time so I never finished implementing it. See "Update" below for a library that provides that functionality:

Update

Ryan Florence is working on a series of Ember component mixins for drag and drop, so once you've poked around this project and had a laugh, I highly recommend you check it out: ic-sortable. His implementation is much more robust, has tests, and deals with inserting items not just swapping, it also adds classes to droppables so that you can show the user where the insertion will happen. He also deals with validating drops so that you can ensure your droppables only accept the correct draggables.

Installation

  • git clone this repository
  • npm install
  • bower install

Running

Resources

About

An example of a way that you can use HTML5 drag and drop in your Ember app.

http://ember-drag-drop-example.s3-website-us-east-1.amazonaws.com/


Languages

Language:JavaScript 61.8%Language:CSS 38.2%