PPK thinks HTML5 gets it wrong on Javascript drag-n-drop
Monday, September 21st, 2009PPK has an unusually harsh post about the way drag-n-drop is being implemented in HTML5.
dragthat and dragsomethingelse
In theory dragenter and dragleave could be great events, since they fire when you enter or leave an HTML element in the middle of a drag operation. If that element is a valid drop target you could change its styles ondragenter and ondragleave to indicate this fact to the user.
With the spec being based on the Microsoft API, I expected dragenter and dragleave to emulate mouseenter and mouseleave. But they didn’t. Not even in IE. They’re based on mouseover and mouseout and suck every bit as badly. And their names are wrong.
Mouseover and mouseout are terrible because they bubble up all the time and make it very hard to distinguish important events from unimportant ones. If I mouse over (or drag enter) a child element of the one that the event is set on, it also fires. And that’s exactly what we don’t want. The events will fire incessantly the whole time the mouse is above the element, and we have to work hard in order to distinguish useful events from useless ones.
Mouseenter and mouseleave, on the other hand, fire only when you enter and leave the element they’re defined on, and they don’t bubble. That makes them much easier to use.
They are Microsoft extensions, by the way, and excellent ones at that. They work only in IE.
Note that originally mouseenter and mouseleave had exactly the same IE only compatibility pattern as drag and drop. Mouseenter and mouseleave are a good idea, drag and drop … isn’t. Guess what the other browsers chose to implement?
No wonder web development is such a fucking pain with fucking morons in charge of the browsers.
Wait, that could be construed as an insult to morons.
Ah, what the fuck.
dragbullshit
Dragover, now, has nothing to do with mouseover. It’s exactly the same as the drag event, except that you can set it on any element instead of just the document. Or something. Whatever.
Why do we need the dragover event if we already have the drag event?
[ ... fume ... ]
To cancel its default action!
If we didn’t have to cancel its default action the dragbullshit event would have no fucking point!
And we can’t have pointless events in our nice specification, now, can we?
So we give it a default action. A very complicated default action.
That has to be canceled. Absolutely, positively has to be canceled.
[ ... crickets ... ]
Anybody LISTENING to what I say?
[ ... drag ... ]
I deserve a fucking MEDAL for this. Above and beyond the call of fucking DUTY.