Web Development with jQuery®

(Elliott) #1

Implementing Drag-and-Drop File Uploads (^) ❘ 301
{
file.name = file.fileName;
}
if (!file.size && file.fileSize)
{
file.size = file.fileSize;
}
this.files.push(file);
var tr = $('tr.finderDragAndDropDialogueTemplate').clone(true);
tr.removeClass('finderDragAndDropDialogueTemplate');
// Preview image uploads by showing a thumbnail of the image
if (file.type.match(/^image\/.*$/) && FileReader)
{
var img = document.createElement('img');
img.file = file;
tr.find('td.finderDragAndDropDialogueFileIcon')
.html(img);
var reader = new FileReader();
reader.onload = function(event)
{
img.src = event.target.result;
};
reader.readAsDataURL(file);
}
tr.find('td.finderDragAndDropDialogueFile')
.text(file.name);
tr.find('td.finderDragAndDropDialogueFileSize')
.text(this.getFileSize(file.size));
tr.attr('title', file.name);
$('div#finderDragAndDropDialogueFiles tbody').append(tr);
},
http : null,
upload : function()
{
this.http = new XMLHttpRequest();
if (this.http.upload && this.http.upload.addEventListener)
{
this.http.upload.addEventListener(
http://www.it-ebooks.info

Free download pdf