I'm starting to experiment with HTML5 Drag and Drop. Then, in the dragstart event handler we should run setData()
, which receives two parameters: format and data.
function dragstart_handler(ev) {
ev.dataTransfer.setData('text/plain', 'foobar');
}
I want to drag some kind of "object" from one container into another container, inside my web application. By "object", I mean something that has multiple attributes (color, text, author, date, …).
What kind of format (or MIME Type) should I use?
text/plain
?text/x-myapp-myobjtype
?application/x-myapp-myobjtype
?application/x-myapp.myobjtype+json
?- something else?
- more than one?
How should I encode my object (the data parameter of setData()
)?
- Comma-separated (or any other delimiter) key=value pairs?
- Serialize the object using JSON?
- Just an id, and at the dropzone I must retrieve the full object using just the id?
- Send just a reference to the object, without even serializing anything? (not possible, the data argument must be a string)
(I realize that "How to enconde an object for Drag and Drop" could be another question here, but it is closely related to the choice of MIME Type)
Some references:
application/json
something too generic? Following that suggestion, then any OpenOffice document should haveapplication/zip
MIME type as well, since they are actually zipped files. – Swayneapplication/json
, then, by analogy, all SVG images should have beenapplication/xml
instead ofimage/svg+xml
, since they are also XML documents. The same logic would apply to anything that is serialized using XML (like Google Earth KML files, that currently useapplication/vnd.google-earth.kml+xml
type; or Atom feeds, that useapplication/atom+xml
). – Swayne