Skip to content

Instantly share code, notes, and snippets.

@newbamboo
Created October 3, 2011 13:50
Show Gist options
  • Save newbamboo/1259137 to your computer and use it in GitHub Desktop.
Save newbamboo/1259137 to your computer and use it in GitHub Desktop.
document.addEventListener('dragenter', stopPropagation, false);
document.addEventListener('dragexit', stopPropagation, false);
document.addEventListener('dragover', stopPropagation, false);
document.addEventListener('drop', function (event) {
// ALL THIS INSIDE THE "DROP" EVENT
var fileReader = new FileReader();
// File references +++++++++++++++++++++++++++++++++++++++
var file = event.dataTransfer.files[0];
// Starts loading ++++++++++++++++++++++++++++++++++++++++
fileReader.readAsDataURL(file);
// Triggers one image data is loaded +++++++++++++++++++++++
fileReader.onloadend = function(event){
// DEBUG!
console.log( event )
var image_data = event.target.result;
// Append to body
var image = new Image()
image.src = image_data;
var body = document.getElementsByTagName('body')[0]
body.appendChild(image)
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment