The HTML5 drag and drop disaster
quirksmode.org
quirksmode.org
While I agree that this might sound strange at first, if the default behaviour was to allow drag per default, how exactly would you select content in a webpage?
There needs to be some kind of toggle to enable or disable the beginning of a dragging operation. While there is this attribute in Mozilla (and a CSS style in Safari), right now, the formalized way to enable dragging is to disable the default operation (which is starting the text selection process).
I don't think this is such a problem.
Maybe I'll come back later and comment on other parts of this rant.
The correct way to do this is to allow the programmer to start a drag. As it stands, it is impossible to do things such as only allow vertical drags and not horizontal drags since the API is completely declarative and takes place on an element-by-element basis.
I wish the text selection tools were more powerful in css/js as well, its reasonably problematic to make text unselectable.
If these events had "permit the drag & drop operation" as their default action, selecting text would be impossible.
This is why drag & drop is disabled by default and the method in which it is disabled is by making the events fire but have their default action to not allow drag & drop which then leads to the selection action being used.
If you need the attribute (or even a class="draggable" to achieve your goal without changing the standard), you can use libraries like jQuery.
What I'm saying is:
* I disagree with the author of the articles assumption that the default event action is wrongly set. If it was the other way around, selection of page elements would not be possible.
* The events is what we have in the standard. I would probably prefer the flag aswell, but from a architecture standpoint, using the events is probably much easier to implement.
* If I want to have that attribute, I can easily add it to my sites script code using one or two lines of jQuery-code.
I wouldn't expect much to be done about this however. Of the concerns I listed in my blog post, I chose the absolute most conservative one, which could be added in a completely backwards compatible way such that no existing browser implementation would break, and I was basically told to wait for HTML 6.
For the curious: http://www.mail-archive.com/whatwg@lists.whatwg.org/msg18003...
Here's lookin at 2015.
In general, I think the HTML5 Working Group needs to be more aware of how standardization of deficient solutions can hurt the web. In this case, many people were blissfully ignorant of IE's awful drag and drop implementation until HTML5 threw a spotlight on it. It seems to me that the Working Group, then, has significantly raised the chances of this horrible API becoming further ingrained, rather than merely allowing it to die in deserved obscurity.
It also makes sense that when you drag it over a potential target, that target gets to decide if you can drop that particular item or not. At least, that's what I'm used to. What's the alternative - having to turn off dropping on all other elements that might not want it?
Rather than saying "I want to be a drag source" and "I want to be a drop target" you are saying "I don't want to not be a drag source" and "I don't want to not be a drop target".
It's bad design.
if (obj.IsFoo) { ... }
than
if (! obj.IsNotFoo) { ... }
Still, changing a name is minor as far as design goes.
I suppose my ideal setup would be to have most events handled entirely by the web browser. The page then only has to define the corner cases of interest, namely:
- A single JavaScript event for drags, to retrieve the promised data.
- A single JavaScript event for drops, where one of the arguments is the specific type of data (pulled from the property of the source).
- A single element property to indicate that the entire element is draggable. This property's value is a "type" (perhaps based on Apple's UTIs, e.g. "public.jpeg" or "public.xml") to indicate what kind of data is represented, e.g. <div id="abc" dragtypes="public.xml" ondrag="...">...</div>.
- An element property to indicate that the entire element accepts drops of one or more types, e.g. <div id="foo" droptypes="public.jpeg public.png" ondrop="...">...</div>.
- New CSS classes, similar to :hover, to define presentation for the drag-and-drop cases, such as ":drag-source", ":drop-pending" and ":drop-disallowed". This allows elements to automatically change appearance, without any JavaScript at all, as drags occur.
Not having implemented a web browser, I don't understand all the nuances, but I'm not sure why it can't be as simple as the above. I know that the above is what I would want to have.
> What follows is a rant laced with profanity. No apologies. Drag and drop deserves no better.
Still, I can tell the author's pretty pissed off about it.
That's an entirely new way of using arse for me, not that as an American, I ever use it much, but...
I'd be happy to read an article (or a comment here on HN) on this topic that points out the issues in a more readable manner. Any pointers?
I like "This is a strange inconsistency, especially since the spec is supposed to be based on the IE implementation."
That kinda explains why it's counter-logical then, it's based on some voodoo from IE6 (!).
Thankfully when PPK works it all out he usually makes some lovely examples up and posts them to quirksmode, press on my friend, press on. [I guess that should be drag on]
Well, writing such an article shows he does care. Also, a good rule of thumb is: if you are not proposing something better you do not have the right to criticize!
This is the dilemma the HTML5 people have to deal with.
If the spec had been sane from the start, Firefox and Safari would probably already implement the sane version.