Skip to content

Instantly share code, notes, and snippets.

@alexeypegov
Created May 23, 2012 10:38
Show Gist options
  • Save alexeypegov/2774506 to your computer and use it in GitHub Desktop.
Save alexeypegov/2774506 to your computer and use it in GitHub Desktop.
dnd
Upload.initDnD = function () {
var d = $(document)[0];
d.ondragenter = function (event) {
event.preventDefault();
if (!window.drag_in_progress) {
window.drag_in_progress = true;
var drop = $(h('.drop', h('.text', 'Drop it to upload')));
$('body').append(drop);
drop[0].ondragover = function(event) {
event.preventDefault();
if (window.clear_drag) {
clearTimeout(window.clear_drag);
}
window.clear_drag = setTimeout(function () {
Upload.clearDnD();
}, 300);
};
drop[0].ondrop = function(event) {
event.preventDefault();
Upload.clearDnD();
new Upload().sendAsFormData(event.dataTransfer.files);
return false;
};
return false;
}
return false;
};
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment