Created
October 3, 2011 13:50
-
-
Save newbamboo/1259137 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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