In order to prevent users to paste content with formatted text, and instead, get only its text the following chunk of cross-browser code:
var _$ta = $('textarea.richText').cleditor({
// options
}),
_clEdit = _$ta.cleditor()[0];
$(_clEdit.$frame[0].contentWindow.document)
.on('rightclick', function (e) {
e.preventDefault();
})
.on('paste', function (e) { // Paste as plain text
var content = '';
e.preventDefault();
if (e.originalEvent.clipboardData) {
content = (e.originalEvent
|| e).clipboardData.getData('text/plain');
}
else if (window.clipboardData) {
content = window.clipboardData.getData('Text');
}
content = content.replace(/\n/g, "<br />");
_clEdit.execCommand('inserthtml', content);
});
No comments:
Post a Comment