Created
April 14, 2014 18:43
-
-
Save kevmo/10673195 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<!doctype html> | |
<html> | |
<head> | |
<style> | |
.hidden { display: none; } | |
#dead-drop { height: 200px; width: 200px; border: 1px solid #333; } | |
</style> | |
</head> | |
<body> | |
<form enctype="multipart/form-data" action="#" method="post"> | |
<input type="file" name="file" class="hidden" id="dead-drop-accept" /> | |
<div id="dead-drop"></div> | |
<input type="submit" value="Submit"/> | |
</form> | |
File: {{ file }} | |
<script> | |
function cancel(event) { | |
if (event.preventDefault) event.preventDefault(); | |
return false; | |
} | |
_supported = (function() { | |
// Method for detection shamelessly borrowed from Modernizr | |
div = document.createElement('div') | |
return ('draggable' in div) || ('ondragstart' in div && 'ondrop' in div) | |
})() | |
trgt = document.getElementById('dead-drop'); | |
file = document.getElementById('dead-drop-accept'); | |
// "Cancel" these, so the browser doesn't use its default behavior. | |
trgt.addEventListener('dragover', cancel); | |
trgt.addEventListener('dragenter', cancel); | |
trgt.addEventListener('drop', function(e) { | |
e.preventDefault(); | |
e.stopPropagation(); | |
file.files = e.dataTransfer.files; | |
trgt.innerHTML = 'Dropped file.'; | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment