For the event "data" property to be shared across different event
handlers, there are two approaches.
1) Bind the handlers at the same time, and declare an object literal
in the bind method.
$( elements ).bind("dropstart drop", {}, function( ev ){
if ( ev.type == "dropstart" )
ev.data.time = new Date().getTime();
if ( ev.type == "drop" )
console.log( ev.data.time );
});
This means you must handle the events seperately in the same handler.
2) Declare the data object once and use a reference in each event
binding.
var data = {};
$( elements ).bind("dropstart", data, function( ev ){
ev.data.time = new Date().getTime();
});
$( elements ).bind("drop", data, function( ev ){
console.log( ev.data.time );
});
Because the data object is declared in the same scope as the event
bindings, and the handler functions are also declared in the same
scope, this could just use closures instead of using the event data.
var data = {};
$( elements ).bind("dropstart", function(){
data.time = new Date().getTime();
});
$( elements ).bind("drop", function(){
console.log( data.time );
});
Another aspect to keep in mind when using the drag/drop special
events, is that the data object also configures certain settings in
the drag/drop interactions, so be careful as to how you declare your
object. Some of the labels may have other meaning to the special
event.
Hope this helps.