Skip to content

Instantly share code, notes, and snippets.

@pazguille
Created October 23, 2012 10:38
Show Gist options
  • Save pazguille/3938102 to your computer and use it in GitHub Desktop.
Save pazguille/3938102 to your computer and use it in GitHub Desktop.
Simple and tiny in-place Editor
(function (window) {
'use strict';
var document = window.document,
console = window.console;
document.addEventListener('keydown', function (event) {
event = event || window.event;
var target = event.target || event.srcElement,
esc = (event.which === 27),
enter = (event.which === 13);
if (target.contentEditable === 'true') {
if (esc) {
document.execCommand('undo');
target.blur();
} else if (enter) {
target.blur();
} else {
console.log('Editing!');
}
}
});
}(this));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment