Skip to content

Instantly share code, notes, and snippets.

@mikelehen
Created July 24, 2014 20:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mikelehen/fa5ceab5ad6f241b6544 to your computer and use it in GitHub Desktop.
Save mikelehen/fa5ceab5ad6f241b6544 to your computer and use it in GitHub Desktop.
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