{
  "attachments": [],
  "comments_archived": true,
  "date": "2009-07-15T15:26:40.000Z",
  "layout": "post",
  "tags": [
    "webdev",
    "firefox",
    "js",
    "outliners",
    "outlining",
    "javascript",
    "dhtml",
    "eventdelegation",
    "entries",
    "mozilla",
    "draganddrop"
  ],
  "title": "HTML5 drag and drop in Firefox 3.5",
  "wordpress_id": 1793,
  "wordpress_slug": "html5-drag-and-drop",
  "wordpress_url": "http://decafbad.com/blog/?p=1793",
  "year": "2009",
  "month": "07",
  "day": "15",
  "isDir": false,
  "slug": "html5-drag-and-drop",
  "type": "entry",
  "postName": "2009-07-15-html5-drag-and-drop",
  "html": "<p><i>\nOh hey, look! It's another blog post—and this one\n<a href=\"http://hacks.mozilla.org/2009/07/html5-drag-and-drop/\">is cross-posted on hacks.mozilla.com</a>.\nI won't say this is the start of a renewed blogging habit, but let's see what happens.\n</i></p>\n\n<style type=\"text/css\">\ndl { margin-left: 2em; }\ndd { margin-left: 2em; margin-bottom: 0.25em; }\n</style>\n<div id=\"introduction\">\n<p>\nDrag and drop is one of the most fundamental interactions\nafforded by graphical user interfaces.  In one gesture, it\nallows users to pair the selection of an object with the\nexecution of an action, often including a second object in the\noperation.  It's a simple yet powerful UI concept used to\nsupport copying, list reordering, deletion (ala the Trash / Recycle Bin),\nand even the creation of link relationships.\n</p><p>\nSince it's so fundamental, offering drag and drop in web\napplications has been a no-brainer ever since browsers first\noffered mouse events in DHTML.  But, although\n<code>mousedown</code>, <code>mousemove</code>, and\n<code>mouseup</code> made it possible, the implementation has been\nlimited to the bounds of the browser window.  Additionally,\nsince these events refer only to the object being dragged,\nthere's a challenge to find the subject of the drop when\nthe interaction is completed.\n</p><p>\nOf course, that doesn't prevent most modern JavaScript\nframeworks from abstracting away most of the problems and\nthrowing in some flourishes while they're at it.  But, wouldn't\nit be nice if browsers offered first-class support for drag and\ndrop, and maybe even extended it beyond the window sandbox?\n</p><p>\nAs it turns out, this very wish is answered by the HTML 5 specification \n<a target=\"_new\" href=\"http://www.whatwg.org/specs/web-apps/current-work/multipage/editing.html#dnd\">section on new drag-and-drop events</a>, and \n<a target=\"_new\" href=\"https://developer.mozilla.org/En/DragDrop/Drag_and_Drop\">Firefox 3.5 includes an implementation</a> of those events.\n</p><p>\nIf you want to jump straight to the code, I've put together \n<a target=\"_new\" href=\"http://decafbad.com/2009/07/drag-and-drop/api-demos.html\">some simple demos</a> \nof the new events.  \n</p><p>\nI've even scratched an itch of my own and\nbuilt <a target=\"_new\" href=\"http://decafbad.com/2009/07/drag-and-drop/outline.html\">the beginnings of an outline editor</a>,\nwhere every draggable element is also a drop target—of which\nthere could be dozens to hundreds in a complex document, something\nthat gave me some minor hair-tearing moments in the past\nwhile trying to make do with plain old mouse events.\n</p><p>\nAnd, all the above can be downloaded or cloned from \n<a href=\"http://github.com/lmorchard/fx35-drag-and-drop\">a GitHub repository</a>\nI've created especially for this article—which continues after the jump.\n</p>\n</div>\n\n\n\n\n\n<!--more-->\n\n\n\n<div id=\"events\">\n<h2>The New Drag and Drop Events</h2>\n<p>\nSo, with no further ado, here are the new drag and drop events,\nin roughly the order you might expect to see them fired:\n</p>\n<dl>\n<dt><code>dragstart</code></dt>\n<dd>\nA drag has been initiated, with the dragged element as the\nevent target.\n</dd>\n<dt><code>drag</code></dt>\n<dd>\nThe mouse has moved, with the dragged element as the event target.\n</dd>\n<dt><code>dragenter</code></dt>\n<dd>\nThe dragged element has been moved into a drop listener,\nwith the drop listener element as the event target.\n</dd>\n<dt><code>dragover</code></dt>\n<dd>\nThe dragged element has been moved over a drop listener,\nwith the drop listener element as the event target.  Since\nthe default behavior is to cancel drops, returning\n<code>false</code> or calling <code>preventDefault()</code> in\nthe event handler indicates that a drop is allowed here.\n</dd>\n<dt><code>dragleave</code></dt>\n<dd>\nThe dragged element has been moved out of a drop listener,\nwith the drop listener element as the event target.\n</dd>\n<dt><code>drop</code></dt>\n<dd>\nThe dragged element has been successfully dropped on a drop\nlistener, with the drop listener element as the event\ntarget.\n</dd>\n<dt><code>dragend</code></dt>\n<dd>\nA drag has been ended, successfully or not, with the\ndragged element as the event target.\n</dd>\n</dl>\n<p>\nLike the mouse events of yore, listeners can be attached to\nelements using <code>addEventListener()</code> \ndirectly or by way of your favorite JS library.  \n</p><p>\nConsider the following example using jQuery, \n<a target=\"_new\" href=\"http://decafbad.com/2009/07/drag-and-drop/api-demos.html#newschool\">also available as a live demo</a>:\n</p>\n<pre lang=\"javascript\" line=\"1\"><div id=\"newschool\">\n<div class=\"dragme\">Drag me!</div>\n\n\n<div class=\"drophere\">Drop here!</div>\n\n\n</div>\n\n\n\n<script type=\"text/javascript\">\n$(document).ready(function() {\n$('#newschool .dragme')\n.attr('draggable', 'true')\n.bind('dragstart', function(ev) {\nvar dt = ev.originalEvent.dataTransfer;\ndt.setData(\"Text\", \"Dropped in zone!\");\nreturn true;\n})\n.bind('dragend', function(ev) {\nreturn false;\n});\n$('#newschool .drophere')\n.bind('dragenter', function(ev) {\n$(ev.target).addClass('dragover');\nreturn false;\n})\n.bind('dragleave', function(ev) {\n$(ev.target).removeClass('dragover');\nreturn false;\n})\n.bind('dragover', function(ev) {\nreturn false;\n})\n.bind('drop', function(ev) {\nvar dt = ev.originalEvent.dataTransfer;\nalert(dt.getData('Text'));\nreturn false;\n});\n});\n</script>\n\n<p>\nThanks to the new events and jQuery, this example is both short\nand simple—but it packs in a lot of functionality, as the rest\nof this article will explain.  \n</p><p>\nBefore moving on, there are at least three things about the above\ncode that are worth mentioning:\n</p>\n<ul>\n<li>\n<p>\nDrop targets are enabled by virtue of having\nlisteners for drop events.  But, \n<a target=\"_new\" href=\"http://www.whatwg.org/specs/web-apps/current-work/multipage/editing.html#drag-and-drop-processing-model\">per the HTML 5 spec</a>,\ndraggable elements need an\nattribute of <code>draggable=\"true\"</code>, set either in\nmarkup or in JavaScript.  \n</p>\n<p>\nThus, <code>$('#newschool&nbsp;.dragme').attr('draggable', 'true')</code>.\n</p>\n</li>\n<li>\n<p>\nThe original DOM event (as opposed to jQuery's event\nwrapper) offers a property called <code>dataTransfer</code>.\nBeyond just manipulating elements, the new drag and drop\nevents accomodate the transmission of user-definable data\nduring the course of the interaction.  \n</p>\n</li>\n<li>\n<p>\nSince these are first-class events, you can apply \n<a target=\"_new\" href=\"http://icant.co.uk/sandbox/eventdelegation/\">the technique of Event Delegation</a>.\n</p><p>\nWhat's that?  Well, imagine you have a list of 1000\nlist items—as part of a deeply-nested outline document,\nfor instance.  Rather than needing to attach listeners\nor otherwise fiddle with all 1000 items, simply attach\na listener to the parent node (eg. the\n<code></code></p><ul> element) and all events from\nthe children will propagate up to the single parent listener.\nAs a bonus, all new child elements added after page\nload will enjoy the same benefits.\n<p></p><p>\n<a target=\"_new\" href=\"http://decafbad.com/2009/07/drag-and-drop/api-demos.html#delegated\">Check out this demo</a>, \nand \n<a target=\"_new\" href=\"http://decafbad.com/2009/07/drag-and-drop/js/drag-delegated.js\">the associated JS code</a> \nto see more about these events and Event Delegation.\n</p>\n\n</ul>\n\n\n</li></ul></pre></div>\n\n\n\n<div id=\"datatransfer\">\n<h2>Using dataTransfer</h2>\n<p>\nAs mentioned in the last section, the new drag and drop events\nlet you send data along with a dragged element.  But, it's even\nbetter than that:  Your drop targets can receive data\ntransferred by content objects dragged into the window from \nother browser windows, and even <i>other applications</i>.\n</p><p>\nSince the example is a bit longer,  \n<a target=\"_new\" href=\"http://decafbad.com/2009/07/drag-and-drop/api-demos.html#data_transfer\">check out the live demo</a>\nand \n<a target=\"_new\" href=\"http://decafbad.com/2009/07/drag-and-drop/js/drag-datatransfer.js\">associated code</a>\nto get an idea of what's possible with <code>dataTransfer</code>.\n</p><p>\nIn a nutshell, the stars of this show are the\n<code>setData()</code> and <code>getData()</code> methods of\nthe <code>dataTransfer</code> property exposed by the Event object.\n</p>\n<p>\nThe <code>setData()</code> method is typically called in the \n<code>dragstart</code> listener, loading <code>dataTransfer</code>\nup with one or more strings of content with associated\n<a href=\"https://developer.mozilla.org/En/DragDrop/Recommended_Drag_Types#link\">recommended content types</a>.\n</p>\n<p>\nFor illustration, here's a quick snippet from the example code:\n</p>\n<pre lang=\"javascript\" line=\"1\">var dt = ev.originalEvent.dataTransfer;    \ndt.setData('text/plain', $('#logo').parent().text());\ndt.setData('text/html', $('#logo').parent().html());\ndt.setData('text/uri-list', $('#logo')[0].src);\n</pre>\n<p></p><p>\nOn the other end, <code>getData()</code> allows you to query\nfor content by type (eg. <code>text/html</code> followed by\n<code>text/plain</code>).  This, in turn, allows you to decide\non acceptable content types at the time of the\n<code>drop</code> event or even during <code>dragover</code>\nto offer feedback for unacceptable types during the drag.\n</p><p>\nHere's another example from the receiving end of the example code:\n</p>\n<pre lang=\"javascript\" line=\"1\">var dt = ev.originalEvent.dataTransfer;    \n$('.content_url .content').text(dt.getData('text/uri-list'));\n$('.content_text .content').text(dt.getData('text/plain'));\n$('.content_html .content').html(dt.getData('text/html'));\n</pre>\n\n<p>\nWhere <code>dataTransfer</code> really shines, though, is that\nit allows your drop targets to receive content from \nsources outside your defined draggable elements and even from\noutside the browser altogether.  Firefox accepts such drags, \nand attempts to populate <code>dataTransfer</code> with\nappropriate content types extracted from the external object.\n</p><p>\nThus, you could select some text in a word processor window and\ndrop it into one of your elements, and at least expect to find\nit available as <code>text/plain</code> content.  \n</p><p>\nYou can also select content in \nanother browser window, and expect to see <code>text/html</code>\nappear in your events.  Check out the \n<a target=\"_new\" href=\"http://decafbad.com/2009/07/drag-and-drop/outline.html\">outline editing demo</a>\nand see what happens when you try dragging various elements \n(eg. images, tables, and lists) and highlighted content from\nother windows onto the items there.\n</p>\n\n</div>\n\n\n\n<div id=\"dragfeedback\">\n<h2>Using Drag Feedback Images</h2>\n<p>\nAn important aspect of the drag and drop interaction is a\nrepresentation of the thing being dragged.  By default in\nFirefox, this is a \"ghost\" image of the dragged element itself.  But,\nthe <code>dataTransfer</code> property of the original Event\nobject exposes the method <code>setDragImage()</code> for use\nin customizing this representation.\n</p><p>\nThere's\n<a target=\"_new\" href=\"http://decafbad.com/2009/07/drag-and-drop/api-demos.html#feedback_image\">a live demo</a> of this feature, as well as\n<a target=\"_new\" href=\"http://decafbad.com/2009/07/drag-and-drop/js/drag-feedback-images.js\">associated JS code</a> \navailable.  The gist, however, is sketched out in these code snippets:\n</p>\n<pre lang=\"javascript\" line=\"1\">var dt = ev.originalEvent.dataTransfer;    \n\n<p>dt.setDragImage( $('#feedback_image h2')[0], 0, 0);</p>\n<p>dt.setDragImage( $('#logo')[0], 32, 32); </p>\n<p>var canvas = document.createElement(\"canvas\");\ncanvas.width = canvas.height = 50;</p>\n<p>var ctx = canvas.getContext(\"2d\");\nctx.lineWidth = 8;\nctx.moveTo(25,0);\nctx.lineTo(50, 50);\nctx.lineTo(0, 50);\nctx.lineTo(25, 0);\nctx.stroke();</p>\n<p>dt.setDragImage(canvas, 25, 25);\n</p></pre><p></p>\n<p>\nYou can supply a DOM node as the first parameter to \n<code>setDragImage()</code>, which includes everything from\ntext to images to <code>canvas</code> elements.  The\nsecond two parameters indicate at what left and top offset\nthe mouse should appear in the image while dragging.\n</p><p>\nFor example, since the <code>#logo</code> image is 64x64,\nthe parameters in the second <code>setDragImage()</code>\nmethod places the mouse right in the center of the image.\nOn the other hand, the first call positions the feedback\nimage such that the mouse rests in the upper left corner.\n</p><p>\n</p>\n</div>\n\n\n\n<div id=\"dragfeedback\">\n<h2>Using Drop Effects</h2>\n<p>\nAs mentioned at the start of this article, the drag and drop\ninteraction has been used to support actions such as copying,\nmoving, and linking.  Accordingly, the HTML 5 specification \naccomodates these operations in the form of the \n<code>effectAllowed</code> and <code>dropEffect</code>\nproperties exposed by the Event object.\n</p>\n<p>\nFor a quick fix, check out the\n<a target=\"_new\" href=\"http://decafbad.com/2009/07/drag-and-drop/api-demos.html#drag_effects\">a live demo</a> \nof this feature, as well as the\n<a target=\"_new\" href=\"http://decafbad.com/2009/07/drag-and-drop/js/drag-effects.js\">associated JS code</a>.\n</p><p>\nThe basic idea is that the <code>dragstart</code> event\nlistener can set a value for <code>effectAllowed</code> like so:\n</p>\n<pre lang=\"javascript\" line=\"1\">var dt = ev.originalEvent.dataTransfer;\nswitch (ev.target.id) {\ncase 'effectdrag0': dt.effectAllowed = 'copy'; break;\ncase 'effectdrag1': dt.effectAllowed = 'move'; break;\ncase 'effectdrag2': dt.effectAllowed = 'link'; break;\ncase 'effectdrag3': dt.effectAllowed = 'all'; break;\ncase 'effectdrag4': dt.effectAllowed = 'none'; break;\n}\n</pre>\n<p>The choices available for this property include the following:</p>\n<dl> \n<dt><code>none</code></dt><dd>no operation is permitted </dd>\n<dt><code>copy</code></dt><dd>copy only </dd>\n<dt><code>move</code></dt><dd>move only </dd>\n<dt><code>link</code></dt><dd>link only </dd>\n<dt><code>copyMove</code></dt><dd>copy or move only </dd>\n<dt><code>copyLink</code></dt><dd>copy or link only </dd>\n<dt><code>linkMove</code></dt><dd>link or move only </dd>\n<dt><code>all</code></dt><dd>copy, move, or link </dd>\n</dl>\n<p>\nOn the other end, the <code>dragover</code> event listener \ncan set the value of the\n<code>dropEffect</code> property to indicate the expected effect\ninvoked on a successful drop.  If the value does\nnot match up with <code>effectAllowed</code>, the drop will\nbe considered cancelled on completion.\n</p><p>\nIn the \n<a target=\"_new\" href=\"http://decafbad.com/2009/07/drag-and-drop/api-demos.html#drag_effects\">a live demo</a>,\nyou should be able to see that only elements with matching\neffects can be dropped into the appropriate drop zones.  This\nis accomplished with code like the following:\n</p>\n<pre lang=\"javascript\" line=\"1\">var dt = ev.originalEvent.dataTransfer;\nswitch (ev.target.id) {\ncase 'effectdrop0': dt.dropEffect = 'copy'; break;\ncase 'effectdrop1': dt.dropEffect = 'move'; break;\ncase 'effectdrop2': dt.dropEffect = 'link'; break;\ncase 'effectdrop3': dt.dropEffect = 'all'; break;\ncase 'effectdrop4': dt.dropEffect = 'none'; break;\n}\n</pre>\n<p>\nAlthough the OS itself can provide some feedback, you \ncan also use these properties to update your own visible \nfeedback, both on the dragged element and on the drop zone\nitself.\n</p>\n</div>\n\n\n\n<div id=\"conclusion\">\n<h2>Conclusion</h2>\n<p>\nThe new first-class drag and drop events in HTML5 and Firefox\nmake supporting this form of UI interaction simple, concise,\nand powerful in the browser.  But beyond the new simplicity of\nthese events, the ability to transfer content between\napplications opens brand new avenues for web-based applications\nand collaboration with desktop software in general.\n</p><p>\n</p><p>\n</p>\n</div>\n\n\n\n\n<div id=\"comments\" class=\"comments archived-comments\"><h3>Archived Comments</h3>\n<ul class=\"comments\">\n<li class=\"comment\" id=\"comment-221090962\">\n<div class=\"meta\">\n<div class=\"author\">\n<a class=\"avatar image\" rel=\"nofollow\" href=\"http://lmframework.com\"><img src=\"http://www.gravatar.com/avatar.php?gravatar_id=03dc722b1852367f02b0b21f02b10675&amp;size=32&amp;default=http://mediacdn.disqus.com/1320279820/images/noavatar32.png\" width=\"\" height=\"\"></a>\n<a class=\"avatar name\" rel=\"nofollow\" href=\"http://lmframework.com\">David Semeria</a>\n</div>\n\n\n<p><a href=\"#comment-221090962\" class=\"permalink\"><time datetime=\"2009-07-16T17:56:52\">2009-07-16T17:56:52</time></a></p>\n</div>\n\n\n<div class=\"content\"><p>Wow - thanks for a great introduction to D+D in HTML 5, I'm really looking forward to giving it a thorough road test. </p>\n<p>The key part of the implementation are the target listeners, because, as I'm sure you're aware, onmouseover would historically never fire over the target element because the dragged item would always 'cover it up'. BTW, my proposed solution was to add an 'event transparency' property, which would have made the dragged item invisible from the point of view of selected events, eg onmouseover.</p>\n<p>This implementation is going to take a lot of pain away. You have no idea how many hoops I had to jump through to get a fully generic D+D implementation working without these new calls.</p>\n<p>If you're interested, you can see it working here: http://lmframework.com/page.php?id=vd_twig_short_2</p></div>\n\n\n</li>\n<li class=\"comment\" id=\"comment-221090964\">\n<div class=\"meta\">\n<div class=\"author\">\n<a class=\"avatar image\" rel=\"nofollow\" href=\"\"><img src=\"http://www.gravatar.com/avatar.php?gravatar_id=cee7ac3f63d7e8c1367e170bec302c14&amp;size=32&amp;default=http://mediacdn.disqus.com/1320279820/images/noavatar32.png\" width=\"\" height=\"\"></a>\n<a class=\"avatar name\" rel=\"nofollow\" href=\"\">Alex</a>\n</div>\n\n\n<p><a href=\"#comment-221090964\" class=\"permalink\"><time datetime=\"2009-07-17T00:13:23\">2009-07-17T00:13:23</time></a></p>\n</div>\n\n\n<div class=\"content\"><p>Hey,</p>\n<p>Looks great and useful article.  For dragging from external applications (such as the Desktop) is a normal webpage able to get the data from the drop?  I was just playing with it and seem to always get what seems to be a security error with getData or mozGetDataAt.  However, the documentation seems to state that on drop that data should be made available to the page.  Likewise, in the same way an image can be dragged off the page onto the desktop, can an arbitrary element be dragged onto the desktop with whatever file content to be saved?  Thanks for the help.</p>\n<p>Alex</p></div>\n\n\n</li>\n<li class=\"comment\" id=\"comment-221090966\">\n<div class=\"meta\">\n<div class=\"author\">\n<a class=\"avatar image\" rel=\"nofollow\" href=\"http://paulisageek.com/\"><img src=\"http://www.gravatar.com/avatar.php?gravatar_id=b3bb70a4bace7f9bd49f48b149ab95f9&amp;size=32&amp;default=http://mediacdn.disqus.com/1320279820/images/noavatar32.png\" width=\"\" height=\"\"></a>\n<a class=\"avatar name\" rel=\"nofollow\" href=\"http://paulisageek.com/\">Paul Tarjan</a>\n</div>\n\n\n<p><a href=\"#comment-221090966\" class=\"permalink\"><time datetime=\"2009-07-17T04:52:54\">2009-07-17T04:52:54</time></a></p>\n</div>\n\n\n<div class=\"content\"><p>Very nice, I didn't know that FF 3.5 actually had this implemented. Time to start playing :)</p>\n<p>Also, how did you do your code posts? Was it just pasting in HTML or do you have a better setup?</p></div>\n\n\n</li>\n<li class=\"comment\" id=\"comment-221090967\">\n<div class=\"meta\">\n<div class=\"author\">\n<a class=\"avatar image\" rel=\"nofollow\" href=\"\"><img src=\"http://www.gravatar.com/avatar.php?gravatar_id=066d1e75c9b938053ee6b3d48b1c0f6a&amp;size=32&amp;default=http://mediacdn.disqus.com/1320279820/images/noavatar32.png\" width=\"\" height=\"\"></a>\n<a class=\"avatar name\" rel=\"nofollow\" href=\"\">Animal</a>\n</div>\n\n\n<p><a href=\"#comment-221090967\" class=\"permalink\"><time datetime=\"2009-07-17T14:35:21\">2009-07-17T14:35:21</time></a></p>\n</div>\n\n\n<div class=\"content\"><p>Seems pretty pointless pressing ahead with this when you just can't write a web app to use it. There's no support. All a bunch of whizzy fun I'm sure, but sod-all use.</p></div>\n\n\n</li>\n<li class=\"comment\" id=\"comment-221090969\">\n<div class=\"meta\">\n<div class=\"author\">\n<a class=\"avatar image\" rel=\"nofollow\" href=\"http://www.decafbad.com\"><img src=\"http://www.gravatar.com/avatar.php?gravatar_id=2377f34a68801b861c3e54e1301f0dce&amp;size=32&amp;default=http://mediacdn.disqus.com/1320279820/images/noavatar32.png\" width=\"\" height=\"\"></a>\n<a class=\"avatar name\" rel=\"nofollow\" href=\"http://www.decafbad.com\">l.m.orchard</a>\n</div>\n\n\n<p><a href=\"#comment-221090969\" class=\"permalink\"><time datetime=\"2009-07-17T16:23:10\">2009-07-17T16:23:10</time></a></p>\n</div>\n\n\n<div class=\"content\"><p>@Animal: Why can't you write a web app to use it?  It's in the HTML5 spec, works in Fx3.5 and Safari 4 / WebKit.  It doesn't have universal support yet, or course, but new standards never do.</p></div>\n\n\n</li>\n<li class=\"comment\" id=\"comment-221090970\">\n<div class=\"meta\">\n<div class=\"author\">\n<a class=\"avatar image\" rel=\"nofollow\" href=\"http://www.crearedesign.co.uk\"><img src=\"http://www.gravatar.com/avatar.php?gravatar_id=87bf21798e390d9043dda7240c1b60f7&amp;size=32&amp;default=http://mediacdn.disqus.com/1320279820/images/noavatar32.png\" width=\"\" height=\"\"></a>\n<a class=\"avatar name\" rel=\"nofollow\" href=\"http://www.crearedesign.co.uk\">paul</a>\n</div>\n\n\n<p><a href=\"#comment-221090970\" class=\"permalink\"><time datetime=\"2009-07-21T08:08:26\">2009-07-21T08:08:26</time></a></p>\n</div>\n\n\n<div class=\"content\"><p>very nice indeed! i like this, it has definitely opened up new avenues for interaction without using flash. but it will take time before people upgrade to the new browser. a lot of people who browse the web wont realise what the technology will bring and will use their current browser because it does the job!</p></div>\n\n\n</li>\n<li class=\"comment\" id=\"comment-221090971\">\n<div class=\"meta\">\n<div class=\"author\">\n<a class=\"avatar image\" rel=\"nofollow\" href=\"\"><img src=\"http://www.gravatar.com/avatar.php?gravatar_id=04de859cfd6ef0b75e4ea3cbea143190&amp;size=32&amp;default=http://mediacdn.disqus.com/1320279820/images/noavatar32.png\" width=\"\" height=\"\"></a>\n<a class=\"avatar name\" rel=\"nofollow\" href=\"\">Joel</a>\n</div>\n\n\n<p><a href=\"#comment-221090971\" class=\"permalink\"><time datetime=\"2009-07-21T14:36:04\">2009-07-21T14:36:04</time></a></p>\n</div>\n\n\n<div class=\"content\"><p>Excellent demos of the new features.</p>\n<p>When using a feedback image on a zoomed in page, should the image not also be scaled up automatically?</p></div>\n\n\n</li>\n<li class=\"comment\" id=\"comment-221090973\">\n<div class=\"meta\">\n<div class=\"author\">\n<a class=\"avatar image\" rel=\"nofollow\" href=\"https://bugzilla.mozilla.org/show_bug.cgi?id=41708\"><img src=\"http://www.gravatar.com/avatar.php?gravatar_id=6d3bf986abdbb431991c3b02eb6e2335&amp;size=32&amp;default=http://mediacdn.disqus.com/1320279820/images/noavatar32.png\" width=\"\" height=\"\"></a>\n<a class=\"avatar name\" rel=\"nofollow\" href=\"https://bugzilla.mozilla.org/show_bug.cgi?id=41708\">RenegadeX</a>\n</div>\n\n\n<p><a href=\"#comment-221090973\" class=\"permalink\"><time datetime=\"2009-07-22T04:13:46\">2009-07-22T04:13:46</time></a></p>\n</div>\n\n\n<div class=\"content\"><p>Dragging &amp; dropping <em>is</em> as you say, a \"one of the most fundamental interations\" that users of computer graphical interfaces have come to know, and expect.</p>\n<p>It therefore completes dumbfounds me how it is that we <em>still</em> can not natively drag &amp; scroll (&amp; then drop) in Firefox. We can only drag &amp; drop an item within the currently visible portion of a Firefox webpage or tab, no further up, no further down.</p>\n<p>That is should be limited makes absolutely no sense. Microsoft built the function into their Windows 3.x (file) Explorer, and then when visual browsers came along, naturally carried it through into Internet Explorer. </p>\n<p>Firefox Bug 41708, \"Should be able to scroll in the viewport while dragging\" was opened in June, 2000 (yes, 9 years ago!) and remains open, and is disregarded by Firefox developers as little more than a trivial little annoyance, and therefore is and should be treated as a low-importance 'enhancement' rather than as the 'standard feature' it should really be.</p>\n<p>If it weren't for the extension 'DragToScroll', which has been around for 3-1/2 years now (not updated in a long time but still works if you override version compatibility), I would have dumped Firefox and switched to a different browser (Maxthon 3, most likely).</p>\n<p>So, I'm wondering (and hoping) -- does the new HTML5 drag and drop specification include anything that if implemented properly would make it possible to scroll &amp; drag?</p></div>\n\n\n</li>\n<li class=\"comment\" id=\"comment-221090974\">\n<div class=\"meta\">\n<div class=\"author\">\n<a class=\"avatar image\" rel=\"nofollow\" href=\"http://www.decafbad.com\"><img src=\"http://www.gravatar.com/avatar.php?gravatar_id=2377f34a68801b861c3e54e1301f0dce&amp;size=32&amp;default=http://mediacdn.disqus.com/1320279820/images/noavatar32.png\" width=\"\" height=\"\"></a>\n<a class=\"avatar name\" rel=\"nofollow\" href=\"http://www.decafbad.com\">l.m.orchard</a>\n</div>\n\n\n<p><a href=\"#comment-221090974\" class=\"permalink\"><time datetime=\"2009-07-22T13:57:42\">2009-07-22T13:57:42</time></a></p>\n</div>\n\n\n<div class=\"content\"><p>@RenegadeX: Ugh.  I don't work on the browser itself, but I noticed that unexpected behavior on drag &amp; drop.  The window really should scroll when you get toward the top or bottom while dragging - and, in fact, most pre-HTML5 JS frameworks do that in their own drag &amp; drop abstractions.  </p>\n<p>Until / unless Firefox gets this fixed, the same sort of auto-scrolling could be hacked in to HTML5 drag and drop.  Not perfect, but it's doable.  That is, in the drag event, you can check if the mouse is near the upper or lower edge of the viewport - and if so, start scrolling appropriately. That's pretty much how the JS frameworks do it with old-school D&amp;D</p></div>\n\n\n</li>\n<li class=\"comment\" id=\"comment-221090975\">\n<div class=\"meta\">\n<div class=\"author\">\n<a class=\"avatar image\" rel=\"nofollow\" href=\"http://www.copperbot.net\"><img src=\"http://www.gravatar.com/avatar.php?gravatar_id=df48b2c2a3a2be51b1e15f10c5fb05da&amp;size=32&amp;default=http://mediacdn.disqus.com/1320279820/images/noavatar32.png\" width=\"\" height=\"\"></a>\n<a class=\"avatar name\" rel=\"nofollow\" href=\"http://www.copperbot.net\">CopperBot</a>\n</div>\n\n\n<p><a href=\"#comment-221090975\" class=\"permalink\"><time datetime=\"2009-07-23T21:41:07\">2009-07-23T21:41:07</time></a></p>\n</div>\n\n\n<div class=\"content\"><p>Very cool article! Thanks for sharing. HTML5 really is going to change everything about how we use and develop for the web. Pretty awesome!</p></div>\n\n\n</li>\n<li class=\"comment\" id=\"comment-221090976\">\n<div class=\"meta\">\n<div class=\"author\">\n<a class=\"avatar image\" rel=\"nofollow\" href=\"http://www.AmnesiaGames.cl\"><img src=\"http://www.gravatar.com/avatar.php?gravatar_id=14ad888c23e28c85c222a73b6c633570&amp;size=32&amp;default=http://mediacdn.disqus.com/1320279820/images/noavatar32.png\" width=\"\" height=\"\"></a>\n<a class=\"avatar name\" rel=\"nofollow\" href=\"http://www.AmnesiaGames.cl\">Alexos</a>\n</div>\n\n\n<p><a href=\"#comment-221090976\" class=\"permalink\"><time datetime=\"2009-07-26T05:05:44\">2009-07-26T05:05:44</time></a></p>\n</div>\n\n\n<div class=\"content\"><p>Hi, would DD work for uploading files? How can I display a progress bar?\nThanks! \nI've been looking for that several days, and found only applets which I can't use in my proyect :-)</p></div>\n\n\n</li>\n<li class=\"comment\" id=\"comment-221090977\">\n<div class=\"meta\">\n<div class=\"author\">\n<a class=\"avatar image\" rel=\"nofollow\" href=\"http://www.sjlwebdesign.co.uk\"><img src=\"http://www.gravatar.com/avatar.php?gravatar_id=185cd965e0e8ccd15df2f90977cbeaf3&amp;size=32&amp;default=http://mediacdn.disqus.com/1320279820/images/noavatar32.png\" width=\"\" height=\"\"></a>\n<a class=\"avatar name\" rel=\"nofollow\" href=\"http://www.sjlwebdesign.co.uk\">Sam</a>\n</div>\n\n\n<p><a href=\"#comment-221090977\" class=\"permalink\"><time datetime=\"2009-07-28T13:54:26\">2009-07-28T13:54:26</time></a></p>\n</div>\n\n\n<div class=\"content\"><p>Looks fantastic, going to try it out now (once I have upgraded my FF)</p></div>\n\n\n</li>\n<li class=\"comment\" id=\"comment-221090978\">\n<div class=\"meta\">\n<div class=\"author\">\n<a class=\"avatar image\" rel=\"nofollow\" href=\"http://www.dankantor.com\"><img src=\"http://www.gravatar.com/avatar.php?gravatar_id=60fc8331f617fc905fd682bc4f41ce8d&amp;size=32&amp;default=http://mediacdn.disqus.com/1320279820/images/noavatar32.png\" width=\"\" height=\"\"></a>\n<a class=\"avatar name\" rel=\"nofollow\" href=\"http://www.dankantor.com\">Dan Kantor</a>\n</div>\n\n\n<p><a href=\"#comment-221090978\" class=\"permalink\"><time datetime=\"2009-07-30T03:10:25\">2009-07-30T03:10:25</time></a></p>\n</div>\n\n\n<div class=\"content\"><p>Looks like effectAllowed and dropEffect are not working for FF 3.5 on the Mac. I see effects on Windows and Safari 4 on Mac. I've been playing around with adding borders to the drop target, but the + icon for copy really helps a lot. Hopefully Mozilla will fix this next update.</p></div>\n\n\n</li>\n<li class=\"comment\" id=\"comment-221090979\">\n<div class=\"meta\">\n<div class=\"author\">\n<a class=\"avatar image\" rel=\"nofollow\" href=\"http://www.thecssninja.com/\"><img src=\"http://www.gravatar.com/avatar.php?gravatar_id=8677c9f7c0f6d947bf318c1430d00bfd&amp;size=32&amp;default=http://mediacdn.disqus.com/1320279820/images/noavatar32.png\" width=\"\" height=\"\"></a>\n<a class=\"avatar name\" rel=\"nofollow\" href=\"http://www.thecssninja.com/\">Ryan</a>\n</div>\n\n\n<p><a href=\"#comment-221090979\" class=\"permalink\"><time datetime=\"2009-09-01T02:33:06\">2009-09-01T02:33:06</time></a></p>\n</div>\n\n\n<div class=\"content\"><p>Great article it's good to see developments in this area. I wrote an article on the further extensions Firefox 3.6 has done with the dataTransfer method by adding the file attribute so you can access local files and upload them without the need for file inputs. http://www.thecssninja.com/javascript/drag-and-drop-upload</p></div>\n\n\n</li>\n<li class=\"comment\" id=\"comment-221090982\">\n<div class=\"meta\">\n<div class=\"author\">\n<a class=\"avatar image\" rel=\"nofollow\" href=\"\"><img src=\"http://www.gravatar.com/avatar.php?gravatar_id=1ed4bbef573bfc014d32356d53103ca2&amp;size=32&amp;default=http://mediacdn.disqus.com/1320279820/images/noavatar32.png\" width=\"\" height=\"\"></a>\n<a class=\"avatar name\" rel=\"nofollow\" href=\"\">phil swenson</a>\n</div>\n\n\n<p><a href=\"#comment-221090982\" class=\"permalink\"><time datetime=\"2009-09-03T22:58:36\">2009-09-03T22:58:36</time></a></p>\n</div>\n\n\n<div class=\"content\"><p>Why not a first class WYSIWYG rich text editor with copy from clipboard image support?  </p>\n<p><em>NO ONE</em> has built a decent text editor in JavaScript - At least not that I've seen.  And browsers don't allow image paste for reasons I don't understand.  </p>\n<p>And by decent I mean just like you'd get in textmate or another editor.  Have the standard text editor features everyone expects:  tab, select indent/select unindent, resize image, home, end, duplicate line, delete line, styling, etc.</p>\n<p>would push the browser to the next level in killing the desktop.  non-techies hate wikis.  They want a real editor.  I do too actually.... would be great for forums, bug tracking system (imagine pasting screen shots in line with your bug desc), email, etc.</p></div>\n\n\n</li>\n<li class=\"comment\" id=\"comment-221090983\">\n<div class=\"meta\">\n<div class=\"author\">\n<a class=\"avatar image\" rel=\"nofollow\" href=\"\"><img src=\"http://www.gravatar.com/avatar.php?gravatar_id=deed51cddc830e162557b8f01383a057&amp;size=32&amp;default=http://mediacdn.disqus.com/1320279820/images/noavatar32.png\" width=\"\" height=\"\"></a>\n<a class=\"avatar name\" rel=\"nofollow\" href=\"\">Jean-Denis</a>\n</div>\n\n\n<p><a href=\"#comment-221090983\" class=\"permalink\"><time datetime=\"2009-09-04T00:23:39\">2009-09-04T00:23:39</time></a></p>\n</div>\n\n\n<div class=\"content\"><p>Francisco Tomalski wrote up a nice piece on HTML 5 drag'n drop at http://www.alertdebugging.com/2009/08/16/on-html-5-drag-and-drop/</p>\n<p>where he uncovers that the proposed standard is partially broken. Any comment on his piece?</p></div>\n\n\n</li>\n<li class=\"comment\" id=\"comment-221090984\">\n<div class=\"meta\">\n<div class=\"author\">\n<a class=\"avatar image\" rel=\"nofollow\" href=\"http://html5tutorial.net/\"><img src=\"http://www.gravatar.com/avatar.php?gravatar_id=3876e030a3fc69a8b59a8c55829fb510&amp;size=32&amp;default=http://mediacdn.disqus.com/1320279820/images/noavatar32.png\" width=\"\" height=\"\"></a>\n<a class=\"avatar name\" rel=\"nofollow\" href=\"http://html5tutorial.net/\">Lisa</a>\n</div>\n\n\n<p><a href=\"#comment-221090984\" class=\"permalink\"><time datetime=\"2009-09-09T07:33:08\">2009-09-09T07:33:08</time></a></p>\n</div>\n\n\n<div class=\"content\"><p>This is a great move forward no more relying on 3rd party apps and extensions to play video or audio, i have been reading up on HTML 5 at the <a href=\"http://html5tutorial.net/\" title=\"HTML tutorials\" rel=\"nofollow\">HTML 5 Tutorials</a> website, i am now playing around with one of the free templates and was wondering how to embed audio, so thanks a lot, great information, lets hope more people lean towards HTML 5 and SOON!!!</p>\n<p>The drag and drop feature i did not notice was already working in FF 3.5, i was told to get Safari to see HTML 5 in action. Thanks for a great post</p></div>\n\n\n</li>\n<li class=\"comment\" id=\"comment-221090985\">\n<div class=\"meta\">\n<div class=\"author\">\n<a class=\"avatar image\" rel=\"nofollow\" href=\"http://www.useragentman.com\"><img src=\"http://www.gravatar.com/avatar.php?gravatar_id=9a579fa051b35266678735c8a3751771&amp;size=32&amp;default=http://mediacdn.disqus.com/1320279820/images/noavatar32.png\" width=\"\" height=\"\"></a>\n<a class=\"avatar name\" rel=\"nofollow\" href=\"http://www.useragentman.com\">Zoltan Hawryluk</a>\n</div>\n\n\n<p><a href=\"#comment-221090985\" class=\"permalink\"><time datetime=\"2010-01-11T15:14:48\">2010-01-11T15:14:48</time></a></p>\n</div>\n\n\n<div class=\"content\"><p>A million thank yous!  This article was great introduction to HTML5 D+D.  With it, I was able to extend it to other browsers.  It was a little painful at first because the browser implementations diverge in significant, but manageable ways.</p>\n<p>If you are interested, check out my article at http://www.useragentman.com/blog/2010/01/10/cross-browser-html5-drag-and-drop/ if you are interested in my results.</p>\n<p>I noticed you haven't blogged in a while - I hope you haven't stopped totally and continue to share with the webdev community.</p></div>\n\n\n</li>\n<li class=\"comment\" id=\"comment-221090986\">\n<div class=\"meta\">\n<div class=\"author\">\n<a class=\"avatar image\" rel=\"nofollow\" href=\"http://www.lingua-franka.com\"><img src=\"http://www.gravatar.com/avatar.php?gravatar_id=e65f416e42c12571ba1c86ae2dadd99f&amp;size=32&amp;default=http://mediacdn.disqus.com/1320279820/images/noavatar32.png\" width=\"\" height=\"\"></a>\n<a class=\"avatar name\" rel=\"nofollow\" href=\"http://www.lingua-franka.com\">Raul</a>\n</div>\n\n\n<p><a href=\"#comment-221090986\" class=\"permalink\"><time datetime=\"2011-04-26T23:56:02\">2011-04-26T23:56:02</time></a></p>\n</div>\n\n\n<div class=\"content\"><p>Hi, Leslie. I've just come across a problem that's driving me nuts. I'm not fully comfortable with D&amp;D, but managed to move a crosshairs image over a map to very precisely controlled positions. It worked great on FF 3.6 and FF 4. After a couple of days of successful testing, the image suddenly refused to de dropped after being dragged (it rather flew back to its previous position). Do you know if there is a bug in FF that might cause this? </p>\n<p>BTW, during the programming process I updated Firebug, which also is getting a little cranky.</p>\n<p>Thanks for your prompt answer, Raul</p></div>\n\n\n</li>\n<li class=\"comment\" id=\"comment-324410737\">\n<div class=\"meta\">\n<div class=\"author\">\n<a class=\"avatar image\" rel=\"nofollow\" href=\"\"><img src=\"http://disqus.com/api/users/avatars/google-4014af7ac4ea5d00df95bef4503b78dd.jpg\" width=\"\" height=\"\"></a>\n<a class=\"avatar name\" rel=\"nofollow\" href=\"\">Alexander Plutov</a>\n</div>\n\n\n<p><a href=\"#comment-324410737\" class=\"permalink\"><time datetime=\"2011-10-01T11:51:12\">2011-10-01T11:51:12</time></a></p>\n</div>\n\n\n<div class=\"content\">Good post about Drag &amp; Drop http://plutov.by/post/html5_drag_and_drop</div>\n\n\n</li>\n</ul>\n\n\n</div>\n\n\n",
  "body": "<p><i>\r\nOh hey, look! It's another blog post—and this one\r\n<a href=\"http://hacks.mozilla.org/2009/07/html5-drag-and-drop/\">is cross-posted on hacks.mozilla.com</a>.\r\nI won't say this is the start of a renewed blogging habit, but let's see what happens.\r\n</i></p>\r\n\r\n<style type=\"text/css\">\r\ndl { margin-left: 2em; }\r\ndd { margin-left: 2em; margin-bottom: 0.25em; }\r\n</style>\r\n<div id=\"introduction\">\r\n<p>\r\nDrag and drop is one of the most fundamental interactions\r\nafforded by graphical user interfaces.  In one gesture, it\r\nallows users to pair the selection of an object with the\r\nexecution of an action, often including a second object in the\r\noperation.  It's a simple yet powerful UI concept used to\r\nsupport copying, list reordering, deletion (ala the Trash / Recycle Bin),\r\nand even the creation of link relationships.\r\n</p><p>\r\nSince it's so fundamental, offering drag and drop in web\r\napplications has been a no-brainer ever since browsers first\r\noffered mouse events in DHTML.  But, although\r\n<code>mousedown</code>, <code>mousemove</code>, and\r\n<code>mouseup</code> made it possible, the implementation has been\r\nlimited to the bounds of the browser window.  Additionally,\r\nsince these events refer only to the object being dragged,\r\nthere's a challenge to find the subject of the drop when\r\nthe interaction is completed.\r\n</p><p>\r\nOf course, that doesn't prevent most modern JavaScript\r\nframeworks from abstracting away most of the problems and\r\nthrowing in some flourishes while they're at it.  But, wouldn't\r\nit be nice if browsers offered first-class support for drag and\r\ndrop, and maybe even extended it beyond the window sandbox?\r\n</p><p>\r\nAs it turns out, this very wish is answered by the HTML 5 specification \r\n<a target=\"_new\" href=\"http://www.whatwg.org/specs/web-apps/current-work/multipage/editing.html#dnd\">section on new drag-and-drop events</a>, and \r\n<a target=\"_new\" href=\"https://developer.mozilla.org/En/DragDrop/Drag_and_Drop\">Firefox 3.5 includes an implementation</a> of those events.\r\n</p><p>\r\nIf you want to jump straight to the code, I've put together \r\n<a target=\"_new\" target=\"_new\" target=\"_new\" href=\"http://decafbad.com/2009/07/drag-and-drop/api-demos.html\">some simple demos</a> \r\nof the new events.  \r\n</p><p>\r\nI've even scratched an itch of my own and\r\nbuilt <a target=\"_new\" target=\"_new\" target=\"_new\" href=\"http://decafbad.com/2009/07/drag-and-drop/outline.html\">the beginnings of an outline editor</a>,\r\nwhere every draggable element is also a drop target—of which\r\nthere could be dozens to hundreds in a complex document, something\r\nthat gave me some minor hair-tearing moments in the past\r\nwhile trying to make do with plain old mouse events.\r\n</p><p>\r\nAnd, all the above can be downloaded or cloned from \r\n<a href=\"http://github.com/lmorchard/fx35-drag-and-drop\">a GitHub repository</a>\r\nI've created especially for this article—which continues after the jump.\r\n</p>\r\n</div>\r\n\r\n<!--more-->\r\n\r\n<div id=\"events\">\r\n<h2>The New Drag and Drop Events</h2>\r\n<p>\r\nSo, with no further ado, here are the new drag and drop events,\r\nin roughly the order you might expect to see them fired:\r\n</p>\r\n<dl>\r\n<dt><code>dragstart</code></dt>\r\n<dd>\r\nA drag has been initiated, with the dragged element as the\r\nevent target.\r\n</dd>\r\n<dt><code>drag</code></dt>\r\n<dd>\r\nThe mouse has moved, with the dragged element as the event target.\r\n</dd>\r\n<dt><code>dragenter</code></dt>\r\n<dd>\r\nThe dragged element has been moved into a drop listener,\r\nwith the drop listener element as the event target.\r\n</dd>\r\n<dt><code>dragover</code></dt>\r\n<dd>\r\nThe dragged element has been moved over a drop listener,\r\nwith the drop listener element as the event target.  Since\r\nthe default behavior is to cancel drops, returning\r\n<code>false</code> or calling <code>preventDefault()</code> in\r\nthe event handler indicates that a drop is allowed here.\r\n</dd>\r\n<dt><code>dragleave</code></dt>\r\n<dd>\r\nThe dragged element has been moved out of a drop listener,\r\nwith the drop listener element as the event target.\r\n</dd>\r\n<dt><code>drop</code></dt>\r\n<dd>\r\nThe dragged element has been successfully dropped on a drop\r\nlistener, with the drop listener element as the event\r\ntarget.\r\n</dd>\r\n<dt><code>dragend</code></dt>\r\n<dd>\r\nA drag has been ended, successfully or not, with the\r\ndragged element as the event target.\r\n</dd>\r\n</dl>\r\n<p>\r\nLike the mouse events of yore, listeners can be attached to\r\nelements using <code>addEventListener()</code> \r\ndirectly or by way of your favorite JS library.  \r\n</p><p>\r\nConsider the following example using jQuery, \r\n<a target=\"_new\" target=\"_new\" target=\"_new\" href=\"http://decafbad.com/2009/07/drag-and-drop/api-demos.html#newschool\">also available as a live demo</a>:\r\n</p>\r\n<pre lang=\"javascript\" line=\"1\">\r\n<div id=\"newschool\">\r\n<div class=\"dragme\">Drag me!</div>\r\n<div class=\"drophere\">Drop here!</div>\r\n</div>\r\n\r\n<script type=\"text/javascript\">\r\n$(document).ready(function() {\r\n$('#newschool .dragme')\r\n.attr('draggable', 'true')\r\n.bind('dragstart', function(ev) {\r\nvar dt = ev.originalEvent.dataTransfer;\r\ndt.setData(\"Text\", \"Dropped in zone!\");\r\nreturn true;\r\n})\r\n.bind('dragend', function(ev) {\r\nreturn false;\r\n});\r\n$('#newschool .drophere')\r\n.bind('dragenter', function(ev) {\r\n$(ev.target).addClass('dragover');\r\nreturn false;\r\n})\r\n.bind('dragleave', function(ev) {\r\n$(ev.target).removeClass('dragover');\r\nreturn false;\r\n})\r\n.bind('dragover', function(ev) {\r\nreturn false;\r\n})\r\n.bind('drop', function(ev) {\r\nvar dt = ev.originalEvent.dataTransfer;\r\nalert(dt.getData('Text'));\r\nreturn false;\r\n});\r\n});\r\n</script>\r\n\r\n<p>\r\nThanks to the new events and jQuery, this example is both short\r\nand simple—but it packs in a lot of functionality, as the rest\r\nof this article will explain.  \r\n</p><p>\r\nBefore moving on, there are at least three things about the above\r\ncode that are worth mentioning:\r\n</p>\r\n<ul>\r\n<li>\r\n<p>\r\nDrop targets are enabled by virtue of having\r\nlisteners for drop events.  But, \r\n<a target=\"_new\" href=\"http://www.whatwg.org/specs/web-apps/current-work/multipage/editing.html#drag-and-drop-processing-model\">per the HTML 5 spec</a>,\r\ndraggable elements need an\r\nattribute of <code>draggable=\"true\"</code>, set either in\r\nmarkup or in JavaScript.  \r\n</p>\r\n<p>\r\nThus, <code>$('#newschool&nbsp;.dragme').attr('draggable', 'true')</code>.\r\n</p>\r\n</li>\r\n<li>\r\n<p>\r\nThe original DOM event (as opposed to jQuery's event\r\nwrapper) offers a property called <code>dataTransfer</code>.\r\nBeyond just manipulating elements, the new drag and drop\r\nevents accomodate the transmission of user-definable data\r\nduring the course of the interaction.  \r\n</p>\r\n</li>\r\n<li>\r\n<p>\r\nSince these are first-class events, you can apply \r\n<a target=\"_new\" href=\"http://icant.co.uk/sandbox/eventdelegation/\">the technique of Event Delegation</a>.\r\n</p><p>\r\nWhat's that?  Well, imagine you have a list of 1000\r\nlist items—as part of a deeply-nested outline document,\r\nfor instance.  Rather than needing to attach listeners\r\nor otherwise fiddle with all 1000 items, simply attach\r\na listener to the parent node (eg. the\r\n<code><ul></code> element) and all events from\r\nthe children will propagate up to the single parent listener.\r\nAs a bonus, all new child elements added after page\r\nload will enjoy the same benefits.\r\n</p><p>\r\n<a target=\"_new\" target=\"_new\" target=\"_new\" href=\"http://decafbad.com/2009/07/drag-and-drop/api-demos.html#delegated\">Check out this demo</a>, \r\nand \r\n<a target=\"_new\" target=\"_new\" href=\"http://decafbad.com/2009/07/drag-and-drop/js/drag-delegated.js\">the associated JS code</a> \r\nto see more about these events and Event Delegation.\r\n</p>\r\n</li>\r\n</ul>\r\n</div>\r\n\r\n<div id=\"datatransfer\">\r\n<h2>Using dataTransfer</h2>\r\n<p>\r\nAs mentioned in the last section, the new drag and drop events\r\nlet you send data along with a dragged element.  But, it's even\r\nbetter than that:  Your drop targets can receive data\r\ntransferred by content objects dragged into the window from \r\nother browser windows, and even <i>other applications</i>.\r\n</p><p>\r\nSince the example is a bit longer,  \r\n<a target=\"_new\" target=\"_new\" href=\"http://decafbad.com/2009/07/drag-and-drop/api-demos.html#data_transfer\">check out the live demo</a>\r\nand \r\n<a target=\"_new\" href=\"http://decafbad.com/2009/07/drag-and-drop/js/drag-datatransfer.js\">associated code</a>\r\nto get an idea of what's possible with <code>dataTransfer</code>.\r\n</p><p>\r\nIn a nutshell, the stars of this show are the\r\n<code>setData()</code> and <code>getData()</code> methods of\r\nthe <code>dataTransfer</code> property exposed by the Event object.\r\n</p>\r\n<p>\r\nThe <code>setData()</code> method is typically called in the \r\n<code>dragstart</code> listener, loading <code>dataTransfer</code>\r\nup with one or more strings of content with associated\r\n<a href=\"https://developer.mozilla.org/En/DragDrop/Recommended_Drag_Types#link\">recommended content types</a>.\r\n</p>\r\n<p>\r\nFor illustration, here's a quick snippet from the example code:\r\n</p>\r\n<pre lang=\"javascript\" line=\"1\">\r\nvar dt = ev.originalEvent.dataTransfer;    \r\ndt.setData('text/plain', $('#logo').parent().text());\r\ndt.setData('text/html', $('#logo').parent().html());\r\ndt.setData('text/uri-list', $('#logo')[0].src);\r\n</pre>\r\n</p><p>\r\nOn the other end, <code>getData()</code> allows you to query\r\nfor content by type (eg. <code>text/html</code> followed by\r\n<code>text/plain</code>).  This, in turn, allows you to decide\r\non acceptable content types at the time of the\r\n<code>drop</code> event or even during <code>dragover</code>\r\nto offer feedback for unacceptable types during the drag.\r\n</p><p>\r\nHere's another example from the receiving end of the example code:\r\n</p>\r\n<pre lang=\"javascript\" line=\"1\">\r\nvar dt = ev.originalEvent.dataTransfer;    \r\n$('.content_url .content').text(dt.getData('text/uri-list'));\r\n$('.content_text .content').text(dt.getData('text/plain'));\r\n$('.content_html .content').html(dt.getData('text/html'));\r\n</pre>\r\n\r\n<p>\r\nWhere <code>dataTransfer</code> really shines, though, is that\r\nit allows your drop targets to receive content from \r\nsources outside your defined draggable elements and even from\r\noutside the browser altogether.  Firefox accepts such drags, \r\nand attempts to populate <code>dataTransfer</code> with\r\nappropriate content types extracted from the external object.\r\n</p><p>\r\nThus, you could select some text in a word processor window and\r\ndrop it into one of your elements, and at least expect to find\r\nit available as <code>text/plain</code> content.  \r\n</p><p>\r\nYou can also select content in \r\nanother browser window, and expect to see <code>text/html</code>\r\nappear in your events.  Check out the \r\n<a target=\"_new\" href=\"http://decafbad.com/2009/07/drag-and-drop/outline.html\">outline editing demo</a>\r\nand see what happens when you try dragging various elements \r\n(eg. images, tables, and lists) and highlighted content from\r\nother windows onto the items there.\r\n</p>\r\n\r\n</div>\r\n\r\n<div id=\"dragfeedback\">\r\n<h2>Using Drag Feedback Images</h2>\r\n<p>\r\nAn important aspect of the drag and drop interaction is a\r\nrepresentation of the thing being dragged.  By default in\r\nFirefox, this is a \"ghost\" image of the dragged element itself.  But,\r\nthe <code>dataTransfer</code> property of the original Event\r\nobject exposes the method <code>setDragImage()</code> for use\r\nin customizing this representation.\r\n</p><p>\r\nThere's\r\n<a target=\"_new\" href=\"http://decafbad.com/2009/07/drag-and-drop/api-demos.html#feedback_image\">a live demo</a> of this feature, as well as\r\n<a target=\"_new\" href=\"http://decafbad.com/2009/07/drag-and-drop/js/drag-feedback-images.js\">associated JS code</a> \r\navailable.  The gist, however, is sketched out in these code snippets:\r\n</p>\r\n<pre lang=\"javascript\" line=\"1\">\r\nvar dt = ev.originalEvent.dataTransfer;    \r\n\r\ndt.setDragImage( $('#feedback_image h2')[0], 0, 0);\r\n\r\ndt.setDragImage( $('#logo')[0], 32, 32); \r\n\r\nvar canvas = document.createElement(\"canvas\");\r\ncanvas.width = canvas.height = 50;\r\n\r\nvar ctx = canvas.getContext(\"2d\");\r\nctx.lineWidth = 8;\r\nctx.moveTo(25,0);\r\nctx.lineTo(50, 50);\r\nctx.lineTo(0, 50);\r\nctx.lineTo(25, 0);\r\nctx.stroke();\r\n\r\ndt.setDragImage(canvas, 25, 25);\r\n</pre>\r\n<p>\r\nYou can supply a DOM node as the first parameter to \r\n<code>setDragImage()</code>, which includes everything from\r\ntext to images to <code>canvas</code> elements.  The\r\nsecond two parameters indicate at what left and top offset\r\nthe mouse should appear in the image while dragging.\r\n</p><p>\r\nFor example, since the <code>#logo</code> image is 64x64,\r\nthe parameters in the second <code>setDragImage()</code>\r\nmethod places the mouse right in the center of the image.\r\nOn the other hand, the first call positions the feedback\r\nimage such that the mouse rests in the upper left corner.\r\n</p><p>\r\n</p>\r\n</div>\r\n\r\n<div id=\"dragfeedback\">\r\n<h2>Using Drop Effects</h2>\r\n<p>\r\nAs mentioned at the start of this article, the drag and drop\r\ninteraction has been used to support actions such as copying,\r\nmoving, and linking.  Accordingly, the HTML 5 specification \r\naccomodates these operations in the form of the \r\n<code>effectAllowed</code> and <code>dropEffect</code>\r\nproperties exposed by the Event object.\r\n</p>\r\n<p>\r\nFor a quick fix, check out the\r\n<a target=\"_new\" href=\"http://decafbad.com/2009/07/drag-and-drop/api-demos.html#drag_effects\">a live demo</a> \r\nof this feature, as well as the\r\n<a target=\"_new\" href=\"http://decafbad.com/2009/07/drag-and-drop/js/drag-effects.js\">associated JS code</a>.\r\n</p><p>\r\nThe basic idea is that the <code>dragstart</code> event\r\nlistener can set a value for <code>effectAllowed</code> like so:\r\n</p>\r\n<pre lang=\"javascript\" line=\"1\">\r\nvar dt = ev.originalEvent.dataTransfer;\r\nswitch (ev.target.id) {\r\ncase 'effectdrag0': dt.effectAllowed = 'copy'; break;\r\ncase 'effectdrag1': dt.effectAllowed = 'move'; break;\r\ncase 'effectdrag2': dt.effectAllowed = 'link'; break;\r\ncase 'effectdrag3': dt.effectAllowed = 'all'; break;\r\ncase 'effectdrag4': dt.effectAllowed = 'none'; break;\r\n}\r\n</pre>\r\n<p>The choices available for this property include the following:</p>\r\n<dl> \r\n<dt><code>none</code></dt><dd>no operation is permitted </dd>\r\n<dt><code>copy</code></dt><dd>copy only </dd>\r\n<dt><code>move</code></dt><dd>move only </dd>\r\n<dt><code>link</code></dt><dd>link only </dd>\r\n<dt><code>copyMove</code></dt><dd>copy or move only </dd>\r\n<dt><code>copyLink</code></dt><dd>copy or link only </dd>\r\n<dt><code>linkMove</code></dt><dd>link or move only </dd>\r\n<dt><code>all</code></dt><dd>copy, move, or link </dd>\r\n</dl>\r\n<p>\r\nOn the other end, the <code>dragover</code> event listener \r\ncan set the value of the\r\n<code>dropEffect</code> property to indicate the expected effect\r\ninvoked on a successful drop.  If the value does\r\nnot match up with <code>effectAllowed</code>, the drop will\r\nbe considered cancelled on completion.\r\n</p><p>\r\nIn the \r\n<a target=\"_new\" href=\"http://decafbad.com/2009/07/drag-and-drop/api-demos.html#drag_effects\">a live demo</a>,\r\nyou should be able to see that only elements with matching\r\neffects can be dropped into the appropriate drop zones.  This\r\nis accomplished with code like the following:\r\n</p>\r\n<pre lang=\"javascript\" line=\"1\">\r\nvar dt = ev.originalEvent.dataTransfer;\r\nswitch (ev.target.id) {\r\ncase 'effectdrop0': dt.dropEffect = 'copy'; break;\r\ncase 'effectdrop1': dt.dropEffect = 'move'; break;\r\ncase 'effectdrop2': dt.dropEffect = 'link'; break;\r\ncase 'effectdrop3': dt.dropEffect = 'all'; break;\r\ncase 'effectdrop4': dt.dropEffect = 'none'; break;\r\n}\r\n</pre>\r\n<p>\r\nAlthough the OS itself can provide some feedback, you \r\ncan also use these properties to update your own visible \r\nfeedback, both on the dragged element and on the drop zone\r\nitself.\r\n</p>\r\n</div>\r\n\r\n<div id=\"conclusion\">\r\n<h2>Conclusion</h2>\r\n<p>\r\nThe new first-class drag and drop events in HTML5 and Firefox\r\nmake supporting this form of UI interaction simple, concise,\r\nand powerful in the browser.  But beyond the new simplicity of\r\nthese events, the ability to transfer content between\r\napplications opens brand new avenues for web-based applications\r\nand collaboration with desktop software in general.\r\n</p><p>\r\n</p><p>\r\n</p>\r\n</div>\r\n\r\n\r\n<div id=\"comments\" class=\"comments archived-comments\">\r\n            <h3>Archived Comments</h3>\r\n        <ul class=\"comments\">\r\n        <li class=\"comment\" id=\"comment-221090962\">\r\n            <div class=\"meta\">\r\n                <div class=\"author\">\r\n                    <a class=\"avatar image\" rel=\"nofollow\" \r\n                       href=\"http://lmframework.com\"><img src=\"http://www.gravatar.com/avatar.php?gravatar_id=03dc722b1852367f02b0b21f02b10675&amp;size=32&amp;default=http://mediacdn.disqus.com/1320279820/images/noavatar32.png\"/></a>\r\n                    <a class=\"avatar name\" rel=\"nofollow\" \r\n                       href=\"http://lmframework.com\">David Semeria</a>\r\n                </div>\r\n                <a href=\"#comment-221090962\" class=\"permalink\"><time datetime=\"2009-07-16T17:56:52\">2009-07-16T17:56:52</time></a>\r\n            </div>\r\n            <div class=\"content\"><p>Wow - thanks for a great introduction to D+D in HTML 5, I'm really looking forward to giving it a thorough road test. </p>\r\n\r\n<p>The key part of the implementation are the target listeners, because, as I'm sure you're aware, onmouseover would historically never fire over the target element because the dragged item would always 'cover it up'. BTW, my proposed solution was to add an 'event transparency' property, which would have made the dragged item invisible from the point of view of selected events, eg onmouseover.</p>\r\n\r\n<p>This implementation is going to take a lot of pain away. You have no idea how many hoops I had to jump through to get a fully generic D+D implementation working without these new calls.</p>\r\n\r\n<p>If you're interested, you can see it working here: http://lmframework.com/page.php?id=vd_twig_short_2</p></div>\r\n            \r\n        </li>\r\n    \r\n        <li class=\"comment\" id=\"comment-221090964\">\r\n            <div class=\"meta\">\r\n                <div class=\"author\">\r\n                    <a class=\"avatar image\" rel=\"nofollow\" \r\n                       href=\"\"><img src=\"http://www.gravatar.com/avatar.php?gravatar_id=cee7ac3f63d7e8c1367e170bec302c14&amp;size=32&amp;default=http://mediacdn.disqus.com/1320279820/images/noavatar32.png\"/></a>\r\n                    <a class=\"avatar name\" rel=\"nofollow\" \r\n                       href=\"\">Alex</a>\r\n                </div>\r\n                <a href=\"#comment-221090964\" class=\"permalink\"><time datetime=\"2009-07-17T00:13:23\">2009-07-17T00:13:23</time></a>\r\n            </div>\r\n            <div class=\"content\"><p>Hey,</p>\r\n\r\n<p>Looks great and useful article.  For dragging from external applications (such as the Desktop) is a normal webpage able to get the data from the drop?  I was just playing with it and seem to always get what seems to be a security error with getData or mozGetDataAt.  However, the documentation seems to state that on drop that data should be made available to the page.  Likewise, in the same way an image can be dragged off the page onto the desktop, can an arbitrary element be dragged onto the desktop with whatever file content to be saved?  Thanks for the help.</p>\r\n\r\n<p>Alex</p></div>\r\n            \r\n        </li>\r\n    \r\n        <li class=\"comment\" id=\"comment-221090966\">\r\n            <div class=\"meta\">\r\n                <div class=\"author\">\r\n                    <a class=\"avatar image\" rel=\"nofollow\" \r\n                       href=\"http://paulisageek.com/\"><img src=\"http://www.gravatar.com/avatar.php?gravatar_id=b3bb70a4bace7f9bd49f48b149ab95f9&amp;size=32&amp;default=http://mediacdn.disqus.com/1320279820/images/noavatar32.png\"/></a>\r\n                    <a class=\"avatar name\" rel=\"nofollow\" \r\n                       href=\"http://paulisageek.com/\">Paul Tarjan</a>\r\n                </div>\r\n                <a href=\"#comment-221090966\" class=\"permalink\"><time datetime=\"2009-07-17T04:52:54\">2009-07-17T04:52:54</time></a>\r\n            </div>\r\n            <div class=\"content\"><p>Very nice, I didn't know that FF 3.5 actually had this implemented. Time to start playing :)</p>\r\n\r\n<p>Also, how did you do your code posts? Was it just pasting in HTML or do you have a better setup?</p></div>\r\n            \r\n        </li>\r\n    \r\n        <li class=\"comment\" id=\"comment-221090967\">\r\n            <div class=\"meta\">\r\n                <div class=\"author\">\r\n                    <a class=\"avatar image\" rel=\"nofollow\" \r\n                       href=\"\"><img src=\"http://www.gravatar.com/avatar.php?gravatar_id=066d1e75c9b938053ee6b3d48b1c0f6a&amp;size=32&amp;default=http://mediacdn.disqus.com/1320279820/images/noavatar32.png\"/></a>\r\n                    <a class=\"avatar name\" rel=\"nofollow\" \r\n                       href=\"\">Animal</a>\r\n                </div>\r\n                <a href=\"#comment-221090967\" class=\"permalink\"><time datetime=\"2009-07-17T14:35:21\">2009-07-17T14:35:21</time></a>\r\n            </div>\r\n            <div class=\"content\"><p>Seems pretty pointless pressing ahead with this when you just can't write a web app to use it. There's no support. All a bunch of whizzy fun I'm sure, but sod-all use.</p></div>\r\n            \r\n        </li>\r\n    \r\n        <li class=\"comment\" id=\"comment-221090969\">\r\n            <div class=\"meta\">\r\n                <div class=\"author\">\r\n                    <a class=\"avatar image\" rel=\"nofollow\" \r\n                       href=\"http://www.decafbad.com\"><img src=\"http://www.gravatar.com/avatar.php?gravatar_id=2377f34a68801b861c3e54e1301f0dce&amp;size=32&amp;default=http://mediacdn.disqus.com/1320279820/images/noavatar32.png\"/></a>\r\n                    <a class=\"avatar name\" rel=\"nofollow\" \r\n                       href=\"http://www.decafbad.com\">l.m.orchard</a>\r\n                </div>\r\n                <a href=\"#comment-221090969\" class=\"permalink\"><time datetime=\"2009-07-17T16:23:10\">2009-07-17T16:23:10</time></a>\r\n            </div>\r\n            <div class=\"content\"><p>@Animal: Why can't you write a web app to use it?  It's in the HTML5 spec, works in Fx3.5 and Safari 4 / WebKit.  It doesn't have universal support yet, or course, but new standards never do.</p></div>\r\n            \r\n        </li>\r\n    \r\n        <li class=\"comment\" id=\"comment-221090970\">\r\n            <div class=\"meta\">\r\n                <div class=\"author\">\r\n                    <a class=\"avatar image\" rel=\"nofollow\" \r\n                       href=\"http://www.crearedesign.co.uk\"><img src=\"http://www.gravatar.com/avatar.php?gravatar_id=87bf21798e390d9043dda7240c1b60f7&amp;size=32&amp;default=http://mediacdn.disqus.com/1320279820/images/noavatar32.png\"/></a>\r\n                    <a class=\"avatar name\" rel=\"nofollow\" \r\n                       href=\"http://www.crearedesign.co.uk\">paul</a>\r\n                </div>\r\n                <a href=\"#comment-221090970\" class=\"permalink\"><time datetime=\"2009-07-21T08:08:26\">2009-07-21T08:08:26</time></a>\r\n            </div>\r\n            <div class=\"content\"><p>very nice indeed! i like this, it has definitely opened up new avenues for interaction without using flash. but it will take time before people upgrade to the new browser. a lot of people who browse the web wont realise what the technology will bring and will use their current browser because it does the job!</p></div>\r\n            \r\n        </li>\r\n    \r\n        <li class=\"comment\" id=\"comment-221090971\">\r\n            <div class=\"meta\">\r\n                <div class=\"author\">\r\n                    <a class=\"avatar image\" rel=\"nofollow\" \r\n                       href=\"\"><img src=\"http://www.gravatar.com/avatar.php?gravatar_id=04de859cfd6ef0b75e4ea3cbea143190&amp;size=32&amp;default=http://mediacdn.disqus.com/1320279820/images/noavatar32.png\"/></a>\r\n                    <a class=\"avatar name\" rel=\"nofollow\" \r\n                       href=\"\">Joel</a>\r\n                </div>\r\n                <a href=\"#comment-221090971\" class=\"permalink\"><time datetime=\"2009-07-21T14:36:04\">2009-07-21T14:36:04</time></a>\r\n            </div>\r\n            <div class=\"content\"><p>Excellent demos of the new features.</p>\r\n\r\n<p>When using a feedback image on a zoomed in page, should the image not also be scaled up automatically?</p></div>\r\n            \r\n        </li>\r\n    \r\n        <li class=\"comment\" id=\"comment-221090973\">\r\n            <div class=\"meta\">\r\n                <div class=\"author\">\r\n                    <a class=\"avatar image\" rel=\"nofollow\" \r\n                       href=\"https://bugzilla.mozilla.org/show_bug.cgi?id=41708\"><img src=\"http://www.gravatar.com/avatar.php?gravatar_id=6d3bf986abdbb431991c3b02eb6e2335&amp;size=32&amp;default=http://mediacdn.disqus.com/1320279820/images/noavatar32.png\"/></a>\r\n                    <a class=\"avatar name\" rel=\"nofollow\" \r\n                       href=\"https://bugzilla.mozilla.org/show_bug.cgi?id=41708\">RenegadeX</a>\r\n                </div>\r\n                <a href=\"#comment-221090973\" class=\"permalink\"><time datetime=\"2009-07-22T04:13:46\">2009-07-22T04:13:46</time></a>\r\n            </div>\r\n            <div class=\"content\"><p>Dragging &amp; dropping <em>is</em> as you say, a \"one of the most fundamental interations\" that users of computer graphical interfaces have come to know, and expect.</p>\r\n\r\n<p>It therefore completes dumbfounds me how it is that we <em>still</em> can not natively drag &amp; scroll (&amp; then drop) in Firefox. We can only drag &amp; drop an item within the currently visible portion of a Firefox webpage or tab, no further up, no further down.</p>\r\n\r\n<p>That is should be limited makes absolutely no sense. Microsoft built the function into their Windows 3.x (file) Explorer, and then when visual browsers came along, naturally carried it through into Internet Explorer. </p>\r\n\r\n<p>Firefox Bug 41708, \"Should be able to scroll in the viewport while dragging\" was opened in June, 2000 (yes, 9 years ago!) and remains open, and is disregarded by Firefox developers as little more than a trivial little annoyance, and therefore is and should be treated as a low-importance 'enhancement' rather than as the 'standard feature' it should really be.</p>\r\n\r\n<p>If it weren't for the extension 'DragToScroll', which has been around for 3-1/2 years now (not updated in a long time but still works if you override version compatibility), I would have dumped Firefox and switched to a different browser (Maxthon 3, most likely).</p>\r\n\r\n<p>So, I'm wondering (and hoping) -- does the new HTML5 drag and drop specification include anything that if implemented properly would make it possible to scroll &amp; drag?</p></div>\r\n            \r\n        </li>\r\n    \r\n        <li class=\"comment\" id=\"comment-221090974\">\r\n            <div class=\"meta\">\r\n                <div class=\"author\">\r\n                    <a class=\"avatar image\" rel=\"nofollow\" \r\n                       href=\"http://www.decafbad.com\"><img src=\"http://www.gravatar.com/avatar.php?gravatar_id=2377f34a68801b861c3e54e1301f0dce&amp;size=32&amp;default=http://mediacdn.disqus.com/1320279820/images/noavatar32.png\"/></a>\r\n                    <a class=\"avatar name\" rel=\"nofollow\" \r\n                       href=\"http://www.decafbad.com\">l.m.orchard</a>\r\n                </div>\r\n                <a href=\"#comment-221090974\" class=\"permalink\"><time datetime=\"2009-07-22T13:57:42\">2009-07-22T13:57:42</time></a>\r\n            </div>\r\n            <div class=\"content\"><p>@RenegadeX: Ugh.  I don't work on the browser itself, but I noticed that unexpected behavior on drag &amp; drop.  The window really should scroll when you get toward the top or bottom while dragging - and, in fact, most pre-HTML5 JS frameworks do that in their own drag &amp; drop abstractions.  </p>\r\n\r\n<p>Until / unless Firefox gets this fixed, the same sort of auto-scrolling could be hacked in to HTML5 drag and drop.  Not perfect, but it's doable.  That is, in the drag event, you can check if the mouse is near the upper or lower edge of the viewport - and if so, start scrolling appropriately. That's pretty much how the JS frameworks do it with old-school D&D</p></div>\r\n            \r\n        </li>\r\n    \r\n        <li class=\"comment\" id=\"comment-221090975\">\r\n            <div class=\"meta\">\r\n                <div class=\"author\">\r\n                    <a class=\"avatar image\" rel=\"nofollow\" \r\n                       href=\"http://www.copperbot.net\"><img src=\"http://www.gravatar.com/avatar.php?gravatar_id=df48b2c2a3a2be51b1e15f10c5fb05da&amp;size=32&amp;default=http://mediacdn.disqus.com/1320279820/images/noavatar32.png\"/></a>\r\n                    <a class=\"avatar name\" rel=\"nofollow\" \r\n                       href=\"http://www.copperbot.net\">CopperBot</a>\r\n                </div>\r\n                <a href=\"#comment-221090975\" class=\"permalink\"><time datetime=\"2009-07-23T21:41:07\">2009-07-23T21:41:07</time></a>\r\n            </div>\r\n            <div class=\"content\"><p>Very cool article! Thanks for sharing. HTML5 really is going to change everything about how we use and develop for the web. Pretty awesome!</p></div>\r\n            \r\n        </li>\r\n    \r\n        <li class=\"comment\" id=\"comment-221090976\">\r\n            <div class=\"meta\">\r\n                <div class=\"author\">\r\n                    <a class=\"avatar image\" rel=\"nofollow\" \r\n                       href=\"http://www.AmnesiaGames.cl\"><img src=\"http://www.gravatar.com/avatar.php?gravatar_id=14ad888c23e28c85c222a73b6c633570&amp;size=32&amp;default=http://mediacdn.disqus.com/1320279820/images/noavatar32.png\"/></a>\r\n                    <a class=\"avatar name\" rel=\"nofollow\" \r\n                       href=\"http://www.AmnesiaGames.cl\">Alexos</a>\r\n                </div>\r\n                <a href=\"#comment-221090976\" class=\"permalink\"><time datetime=\"2009-07-26T05:05:44\">2009-07-26T05:05:44</time></a>\r\n            </div>\r\n            <div class=\"content\"><p>Hi, would DD work for uploading files? How can I display a progress bar?\r\nThanks! \r\nI've been looking for that several days, and found only applets which I can't use in my proyect :-)</p></div>\r\n            \r\n        </li>\r\n    \r\n        <li class=\"comment\" id=\"comment-221090977\">\r\n            <div class=\"meta\">\r\n                <div class=\"author\">\r\n                    <a class=\"avatar image\" rel=\"nofollow\" \r\n                       href=\"http://www.sjlwebdesign.co.uk\"><img src=\"http://www.gravatar.com/avatar.php?gravatar_id=185cd965e0e8ccd15df2f90977cbeaf3&amp;size=32&amp;default=http://mediacdn.disqus.com/1320279820/images/noavatar32.png\"/></a>\r\n                    <a class=\"avatar name\" rel=\"nofollow\" \r\n                       href=\"http://www.sjlwebdesign.co.uk\">Sam</a>\r\n                </div>\r\n                <a href=\"#comment-221090977\" class=\"permalink\"><time datetime=\"2009-07-28T13:54:26\">2009-07-28T13:54:26</time></a>\r\n            </div>\r\n            <div class=\"content\"><p>Looks fantastic, going to try it out now (once I have upgraded my FF)</p></div>\r\n            \r\n        </li>\r\n    \r\n        <li class=\"comment\" id=\"comment-221090978\">\r\n            <div class=\"meta\">\r\n                <div class=\"author\">\r\n                    <a class=\"avatar image\" rel=\"nofollow\" \r\n                       href=\"http://www.dankantor.com\"><img src=\"http://www.gravatar.com/avatar.php?gravatar_id=60fc8331f617fc905fd682bc4f41ce8d&amp;size=32&amp;default=http://mediacdn.disqus.com/1320279820/images/noavatar32.png\"/></a>\r\n                    <a class=\"avatar name\" rel=\"nofollow\" \r\n                       href=\"http://www.dankantor.com\">Dan Kantor</a>\r\n                </div>\r\n                <a href=\"#comment-221090978\" class=\"permalink\"><time datetime=\"2009-07-30T03:10:25\">2009-07-30T03:10:25</time></a>\r\n            </div>\r\n            <div class=\"content\"><p>Looks like effectAllowed and dropEffect are not working for FF 3.5 on the Mac. I see effects on Windows and Safari 4 on Mac. I've been playing around with adding borders to the drop target, but the + icon for copy really helps a lot. Hopefully Mozilla will fix this next update.</p></div>\r\n            \r\n        </li>\r\n    \r\n        <li class=\"comment\" id=\"comment-221090979\">\r\n            <div class=\"meta\">\r\n                <div class=\"author\">\r\n                    <a class=\"avatar image\" rel=\"nofollow\" \r\n                       href=\"http://www.thecssninja.com/\"><img src=\"http://www.gravatar.com/avatar.php?gravatar_id=8677c9f7c0f6d947bf318c1430d00bfd&amp;size=32&amp;default=http://mediacdn.disqus.com/1320279820/images/noavatar32.png\"/></a>\r\n                    <a class=\"avatar name\" rel=\"nofollow\" \r\n                       href=\"http://www.thecssninja.com/\">Ryan</a>\r\n                </div>\r\n                <a href=\"#comment-221090979\" class=\"permalink\"><time datetime=\"2009-09-01T02:33:06\">2009-09-01T02:33:06</time></a>\r\n            </div>\r\n            <div class=\"content\"><p>Great article it's good to see developments in this area. I wrote an article on the further extensions Firefox 3.6 has done with the dataTransfer method by adding the file attribute so you can access local files and upload them without the need for file inputs. http://www.thecssninja.com/javascript/drag-and-drop-upload</p></div>\r\n            \r\n        </li>\r\n    \r\n        <li class=\"comment\" id=\"comment-221090982\">\r\n            <div class=\"meta\">\r\n                <div class=\"author\">\r\n                    <a class=\"avatar image\" rel=\"nofollow\" \r\n                       href=\"\"><img src=\"http://www.gravatar.com/avatar.php?gravatar_id=1ed4bbef573bfc014d32356d53103ca2&amp;size=32&amp;default=http://mediacdn.disqus.com/1320279820/images/noavatar32.png\"/></a>\r\n                    <a class=\"avatar name\" rel=\"nofollow\" \r\n                       href=\"\">phil swenson</a>\r\n                </div>\r\n                <a href=\"#comment-221090982\" class=\"permalink\"><time datetime=\"2009-09-03T22:58:36\">2009-09-03T22:58:36</time></a>\r\n            </div>\r\n            <div class=\"content\"><p>Why not a first class WYSIWYG rich text editor with copy from clipboard image support?  </p>\r\n\r\n<p><em>NO ONE</em> has built a decent text editor in JavaScript - At least not that I've seen.  And browsers don't allow image paste for reasons I don't understand.  </p>\r\n\r\n<p>And by decent I mean just like you'd get in textmate or another editor.  Have the standard text editor features everyone expects:  tab, select indent/select unindent, resize image, home, end, duplicate line, delete line, styling, etc.</p>\r\n\r\n<p>would push the browser to the next level in killing the desktop.  non-techies hate wikis.  They want a real editor.  I do too actually.... would be great for forums, bug tracking system (imagine pasting screen shots in line with your bug desc), email, etc.</p></div>\r\n            \r\n        </li>\r\n    \r\n        <li class=\"comment\" id=\"comment-221090983\">\r\n            <div class=\"meta\">\r\n                <div class=\"author\">\r\n                    <a class=\"avatar image\" rel=\"nofollow\" \r\n                       href=\"\"><img src=\"http://www.gravatar.com/avatar.php?gravatar_id=deed51cddc830e162557b8f01383a057&amp;size=32&amp;default=http://mediacdn.disqus.com/1320279820/images/noavatar32.png\"/></a>\r\n                    <a class=\"avatar name\" rel=\"nofollow\" \r\n                       href=\"\">Jean-Denis</a>\r\n                </div>\r\n                <a href=\"#comment-221090983\" class=\"permalink\"><time datetime=\"2009-09-04T00:23:39\">2009-09-04T00:23:39</time></a>\r\n            </div>\r\n            <div class=\"content\"><p>Francisco Tomalski wrote up a nice piece on HTML 5 drag'n drop at http://www.alertdebugging.com/2009/08/16/on-html-5-drag-and-drop/</p>\r\n\r\n<p>where he uncovers that the proposed standard is partially broken. Any comment on his piece?</p></div>\r\n            \r\n        </li>\r\n    \r\n        <li class=\"comment\" id=\"comment-221090984\">\r\n            <div class=\"meta\">\r\n                <div class=\"author\">\r\n                    <a class=\"avatar image\" rel=\"nofollow\" \r\n                       href=\"http://html5tutorial.net/\"><img src=\"http://www.gravatar.com/avatar.php?gravatar_id=3876e030a3fc69a8b59a8c55829fb510&amp;size=32&amp;default=http://mediacdn.disqus.com/1320279820/images/noavatar32.png\"/></a>\r\n                    <a class=\"avatar name\" rel=\"nofollow\" \r\n                       href=\"http://html5tutorial.net/\">Lisa</a>\r\n                </div>\r\n                <a href=\"#comment-221090984\" class=\"permalink\"><time datetime=\"2009-09-09T07:33:08\">2009-09-09T07:33:08</time></a>\r\n            </div>\r\n            <div class=\"content\"><p>This is a great move forward no more relying on 3rd party apps and extensions to play video or audio, i have been reading up on HTML 5 at the <a href=\"http://html5tutorial.net/\" title=\"HTML tutorials\" rel=\"nofollow\">HTML 5 Tutorials</a> website, i am now playing around with one of the free templates and was wondering how to embed audio, so thanks a lot, great information, lets hope more people lean towards HTML 5 and SOON!!!</p>\r\n\r\n<p>The drag and drop feature i did not notice was already working in FF 3.5, i was told to get Safari to see HTML 5 in action. Thanks for a great post</p></div>\r\n            \r\n        </li>\r\n    \r\n        <li class=\"comment\" id=\"comment-221090985\">\r\n            <div class=\"meta\">\r\n                <div class=\"author\">\r\n                    <a class=\"avatar image\" rel=\"nofollow\" \r\n                       href=\"http://www.useragentman.com\"><img src=\"http://www.gravatar.com/avatar.php?gravatar_id=9a579fa051b35266678735c8a3751771&amp;size=32&amp;default=http://mediacdn.disqus.com/1320279820/images/noavatar32.png\"/></a>\r\n                    <a class=\"avatar name\" rel=\"nofollow\" \r\n                       href=\"http://www.useragentman.com\">Zoltan Hawryluk</a>\r\n                </div>\r\n                <a href=\"#comment-221090985\" class=\"permalink\"><time datetime=\"2010-01-11T15:14:48\">2010-01-11T15:14:48</time></a>\r\n            </div>\r\n            <div class=\"content\"><p>A million thank yous!  This article was great introduction to HTML5 D+D.  With it, I was able to extend it to other browsers.  It was a little painful at first because the browser implementations diverge in significant, but manageable ways.</p>\r\n\r\n<p>If you are interested, check out my article at http://www.useragentman.com/blog/2010/01/10/cross-browser-html5-drag-and-drop/ if you are interested in my results.</p>\r\n\r\n<p>I noticed you haven't blogged in a while - I hope you haven't stopped totally and continue to share with the webdev community.</p></div>\r\n            \r\n        </li>\r\n    \r\n        <li class=\"comment\" id=\"comment-221090986\">\r\n            <div class=\"meta\">\r\n                <div class=\"author\">\r\n                    <a class=\"avatar image\" rel=\"nofollow\" \r\n                       href=\"http://www.lingua-franka.com\"><img src=\"http://www.gravatar.com/avatar.php?gravatar_id=e65f416e42c12571ba1c86ae2dadd99f&amp;size=32&amp;default=http://mediacdn.disqus.com/1320279820/images/noavatar32.png\"/></a>\r\n                    <a class=\"avatar name\" rel=\"nofollow\" \r\n                       href=\"http://www.lingua-franka.com\">Raul</a>\r\n                </div>\r\n                <a href=\"#comment-221090986\" class=\"permalink\"><time datetime=\"2011-04-26T23:56:02\">2011-04-26T23:56:02</time></a>\r\n            </div>\r\n            <div class=\"content\"><p>Hi, Leslie. I've just come across a problem that's driving me nuts. I'm not fully comfortable with D&amp;D, but managed to move a crosshairs image over a map to very precisely controlled positions. It worked great on FF 3.6 and FF 4. After a couple of days of successful testing, the image suddenly refused to de dropped after being dragged (it rather flew back to its previous position). Do you know if there is a bug in FF that might cause this? </p>\r\n\r\n<p>BTW, during the programming process I updated Firebug, which also is getting a little cranky.</p>\r\n\r\n<p>Thanks for your prompt answer, Raul</p></div>\r\n            \r\n        </li>\r\n    \r\n        <li class=\"comment\" id=\"comment-324410737\">\r\n            <div class=\"meta\">\r\n                <div class=\"author\">\r\n                    <a class=\"avatar image\" rel=\"nofollow\" \r\n                       href=\"\"><img src=\"http://disqus.com/api/users/avatars/google-4014af7ac4ea5d00df95bef4503b78dd.jpg\"/></a>\r\n                    <a class=\"avatar name\" rel=\"nofollow\" \r\n                       href=\"\">Alexander Plutov</a>\r\n                </div>\r\n                <a href=\"#comment-324410737\" class=\"permalink\"><time datetime=\"2011-10-01T11:51:12\">2011-10-01T11:51:12</time></a>\r\n            </div>\r\n            <div class=\"content\">Good post about Drag & Drop http://plutov.by/post/html5_drag_and_drop</div>\r\n            \r\n        </li>\r\n    \r\n        </ul>\r\n    \r\n        </div>\r\n    ",
  "parentPath": "./content/posts/archives/2009",
  "path": "2009/07/15/html5-drag-and-drop",
  "summary": "Oh hey, look! It's another blog post—and this one\nis cross-posted on hacks.mozilla.com.\nI won't say this is the start of a renewed blogging habit, but let's see what happens.\n\n\n\n\n\nDrag and drop is one of the most fundamental interactions\nafforded by graphical user interfaces.  In one gesture, it\nallows users to pair the selection of an object with the\nexecution of an action, often including a second object in the\noperation.  It's a simple yet powerful UI concept used to\nsupport copying, list reordering, deletion (ala the Trash / Recycle Bin),\nand even the creation of link relationships.\n\nSince it's so fundamental, offering drag and drop in web\napplications has been a no-brainer ever since browsers first\noffered mouse events in DHTML.  But, although\nmousedown, mousemove, and\nmouseup made it possible, the implementation has been\nlimited to the bounds of the browser window.  Additionally,\nsince these events refer only to the object being dragged,\nthere's a challenge to find the subject of the drop when\nthe interaction is completed.\n\nOf course, that doesn't prevent most modern JavaScript\nframeworks from abstracting away most of the problems and\nthrowing in some flourishes while they're at it.  But, wouldn't\nit be nice if browsers offered first-class support for drag and\ndrop, and maybe even extended it beyond the window sandbox?\n\nAs it turns out, this very wish is answered by the HTML 5 specification \nsection on new drag-and-drop events, and \nFirefox 3.5 includes an implementation of those events.\n\nIf you want to jump straight to the code, I've put together \nsome simple demos \nof the new events.  \n\nI've even scratched an itch of my own and\nbuilt the beginnings of an outline editor,\nwhere every draggable element is also a drop target—of which\nthere could be dozens to hundreds in a complex document, something\nthat gave me some minor hair-tearing moments in the past\nwhile trying to make do with plain old mouse events.\n\nAnd, all the above can be downloaded or cloned from \na GitHub repository\nI've created especially for this article—which continues after the jump.",
  "needsBuild": true,
  "prevPostPath": "2009/05/30/controlled-monetization",
  "prevPostTitle": "Controlled Monetization",
  "nextPostPath": "2009/08/20/professional-javascript-frameworks-is-a-real-book",
  "nextPostTitle": "Professional JavaScript Frameworks is a real book!"
}