[whatwg] Proposal for public data in drag events
trevorburnham at gmail.com
Thu Jun 21 10:01:07 PDT 2012
I've been using HTML drag-and-drop (http://www.whatwg.org/specs/web-apps/current-work/multipage/dnd.html) in a project, but I've run into one limitation that seems severe to me: There is no direct way to determine what the source node is from a dragenter, dragover, or dragleave event. This makes it difficult to support use cases where elements react to those events differently depending on what is being dragged over them.
I understand that the reason for this is cross-document drags: In addition to security implications, obtaining a reference to a DOM node in another document simply wouldn't make sense. Therefore, the dataTransfer object only allows serialized data. Unfortunately, dataTransfer is only appropriate for carrying data to the drop target. There is no mechanism for providing data to intermediate drag event receivers, except for the "types" attributes on the dataTransfer object. "types" can be used to carry data that you want to make public (http://stackoverflow.com/a/11089592/66226), but this is clearly a hack and it carries some limitations. Most notably, the spec requires that data type strings be converted to ASCII lowercase.
Therefore, I'd like to propose the addition of a "publicData" object on all drag events. It would have the same interface and behavior as the dataTransfer object, with the sole exception that it would be read-only in all events where dataTransfer is protected. That is, publicData would be read/write in dragStart, and read-only in all other drag-and-drop events.
More information about the whatwg