Hi every body, I want to remove the format of paste content on paste event.
I tried this code but it is not working. please help me!
CKEDITOR.on('instanceReady', function (e) {
editor = e.editor;
editor.on('paste', function (e) {
editor.focus();
editor.document.$.execCommand('SelectAll', false, null );
editor.execCommand('RemoveFormat', editor.getSelection().getNative());
editor.insertHtml('additional content');
});
});
I tried this code but it is not working. please help me!
CKEDITOR.on('instanceReady', function (e) {
editor = e.editor;
editor.on('paste', function (e) {
editor.focus();
editor.document.$.execCommand('SelectAll', false, null );
editor.execCommand('RemoveFormat', editor.getSelection().getNative());
editor.insertHtml('additional content');
});
});
Re: Please help me remove the content on paste event
Paste event contains pasted data, but not yet inserted. This data is available in the event's callback in evt.data.html or evt.data.text. The latter one is plain text data, from which you don't have to remove formatting. Only the first property contains styles, however currently I don't know a way to apply removeFormat command to this data.
Fortunately, there's a second way - forcePasteAsPlainText config setting - http://docs.cksource.com/ckeditor_api/s ... sPlainText
If you set it to true, then after you press ctrl+v (or use other method for pasting data), data will be pasted to the hidden textarea (so they will be converted to plain text by browser) and finally editor will transform this plain text into HTML. However, this method leaves only text. No images, no links, etc. So if you really want the removeFormat behaviour, then you have to write your own cleanup method.
Meanwhile I reported an issue - http://dev.ckeditor.com/ticket/9306 because removeFormat should be reusable in your case.
Piotrek (Reinmar) Koszuliński
CKEditor JavaScript Developer
--
CKSource - http://cksource.com
--
Follow CKEditor on: Twitter | Facebook | Google+
Re: Please help me remove the content on paste event
I only want to remove the style but keep the tag (.e.g. <div>, <p>, <br> ...) so CKEDITOR.config.forcePasteAsPlainText is not suitable for me.
I tried to add setTimeout, so, the format action will be excuted after on-paste 1s, i can see the editor SelectAll the content after 1s but the RemoveFormat command not work, i guess that editor.getSelection().getNative() is wrong, but i don't understand how ckeditor's selection work, please help me!
CKEDITOR.on('instanceReady', function(e){
var editor = e.editor;
editor.on('paste', function(e){
setTimeout(function(){
editor.focus();
editor.document.$.execCommand('SelectAll', false, null ); // work
editor.document.$.execCommand('RemoveFormat', editor.getSelection().getNative()); // not work
}, 1000);
});
});
Re: Please help me remove the content on paste event
CKEDITOR.on('instanceReady', function(e){
var editor = e.editor;
editor.on('paste', function(e){
setTimeout(function(){
$('body').append("<div id='tmpCt'>"+ editor.getData() +"</div>");
$('#tmpCt div, #tmpCt p, #tmpCt a, #tmpCt span').removeAttr("style");
$('#requiredDescription').val($('#tmpCt').html());
$('#tmpCt').remove();
}, 100);
});
});
hope that ckeditor dev team will take my case to make removeFormat reusable, it must be better!
Re: Please help me remove the content on paste event