Skip to content

Instantly share code, notes, and snippets.

@mikelehen
Created August 29, 2013 00:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikelehen/6373026 to your computer and use it in GitHub Desktop.
Save mikelehen/6373026 to your computer and use it in GitHub Desktop.
Simple drag/drop of images into Firepad... probably not production-ready, but seems to work.
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