Drag and Drop redux
It seems that each of the various drag and drop event handlers only know about either the object being dragged, or the area into which it's being dropped. Not both. This means that when dropping an object its receiver can't know what's arriving.
There is a dataTransfer object that can be seen by both ends, which acts as a clipboard onto which you can paste relevant information: but seemingly only either text or a URL (presumably for dragging text or images respectively) - not the object itself.
This means I've had to resort to the terrible hack:
function makeMovable() {
event.dataTransfer.setData("Text", event.srcElement.id);
event.dataTransfer.setData("URL", "http://ok/");
}
function dropItem() {
if (! isMovable()) return;
...
}
function isMovable() {
return ((event.dataTransfer.getData("URL") == "http://ok/")
&& event.dataTransfer.getData("Text"));
}
[I tried just setting both and making sure both were set, but text dragged from an href has both set already :( ]
This can't be the best way to do this.
7:37:04 PM
|