Created
June 20, 2012 11:38
-
-
Save renehuber/2959472 to your computer and use it in GitHub Desktop.
Plaintext contentEditable DIVs
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
/** | |
* Event handler to prevent richtext and linebreaks in contentEditable DIVs | |
*/ | |
$('body').on('keydown paste', 'div.editfield', function(e) { | |
var $field = $(e.currentTarget); | |
if (e.keyCode===13 && $field.hasClass('multiline')) { | |
return true; | |
} else if (e.keyCode===13 || e.type==='paste') { | |
setTimeout(function() { | |
$field.html($field.text()); | |
},0); | |
} | |
}); |
Thanks a lot for this hack :)
works like a charm
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Html-Elements with contentEditable go weird if the user pastes richt-text content into it or forces a line-break. This hack replaces richtext- right after pasting with simple plaintext, but works only with DIV-elements (in Firefox, as far as i know)