Forked from mikelehen/firepad-drag-drop-images.js
Last active
August 29, 2015 14:15
-
-
Save rafbm/bc2695a764858519a800 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
codeMirror.setOption('onDragEvent', function(cm, e) { | |
// Move the cursor as they drag. | |
var pos = codeMirror.coordsChar({left: e.x, top: e.y }); | |
codeMirror.setCursor(pos); | |
codeMirror.focus(); | |
var isImageDrop = e.type == 'drop' && e.dataTransfer.files && e.dataTransfer.files.length > 0 && e.dataTransfer.files[0].type && e.dataTransfer.files[0].type.indexOf('image/') > -1; | |
if (!isImageDrop) return; | |
event.preventDefault(); | |
var reader = new FileReader(); | |
reader.onload = function(event) { | |
var img = new Image(); | |
img.onload = function () { | |
firepad.insertEntity('img', { | |
'src' : event.target.result, | |
'width' : this.width, | |
'height' : this.height | |
}); | |
}; | |
img.src = event.target.result; | |
}; | |
reader.readAsDataURL(event.dataTransfer.files[0]); | |
return true; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment