Skip to content

Instantly share code, notes, and snippets.

@mikelehen
mikelehen / entity-modification.js
Created September 28, 2013 23:05
An example of registering an 'img' entity that modifies itself on click or shift-click (see onclick handler).
firepad.registerEntity('img', {
render: function(info, handle) {
var attrs = ['src', 'alt', 'width', 'height', 'style', 'class'];
var html = '<img ';
for(var i = 0; i < attrs.length; i++) {
var attr = attrs[i];
if (attr in info) {
html += ' ' + attr + '="' + info[attr] + '"';
}
}
@mikelehen
mikelehen / firepad-drag-drop.js
Created August 29, 2013 00:30
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();