Implementing Drag-and-Drop File Uploads (^) ❘ 317
the newly moved fi le or folder object. Otherwise, each event is applied to every fi le and folder object
that is present.
applyEvents : function()
{
var context = null;
if (arguments[0])
{
context = arguments[0];
}
else
{
context = $('div.finderDirectory, div.finderFile');
}
context
The dragstart, dragend, dragenter, dragover, and dragleave events remain unchanged from
Example 11-1. The drop event has been modifi ed to accommodate drag-and-drop fi le uploads as
well as moving around existing fi les or folders.
.on(
'drop.finder',
function(event)
{
event.preventDefault();
event.stopPropagation();
var dataTransfer = event.originalEvent.dataTransfer;
var drop = $(this);
if (drop.hasClass('finderDirectory'))
{
If the user has dragged and dropped fi les for upload to the browser window, the fi les are present in
the dataTransfer.files property, and the files property has a length greater than zero. The fi les,
along with the path of the folder the fi les were dropped on, passes along to the openProgressDia-
logue() method for processing and upload.
if (dataTransfer.files && dataTransfer.files.length)
{
// Files dropped from outside the browser
dragAndDrop.openProgressDialogue(
dataTransfer.files,
node.data('path')
);
}
else
{
try
{
var html = dataTransfer.getData('text/html');
}
http://www.it-ebooks.info
elliott
(Elliott)
#1