user3755867
user3755867

Reputation: 57

Remove attribute of new created element in ckeditor

i want to remove the atrribute/class of new created element using enter key press event in ckeditor ,so how to remove it. ckeditor version is 4.3 i have following code

     <p placeholder="start here.." class='test'></p>

Now i write something and press enter between text then it recreate the same tag with attributes. i have idea to use editor.on() ot config.allowedcontent , but i m not get how exactly do that so i can remove this class or change attribute.

I dont want to use any plugin.

Upvotes: 0

Views: 1960

Answers (1)

Edson Perotoni
Edson Perotoni

Reputation: 131

   CKEDITOR.on( 'instanceReady', function( ev )
{
	var editor = ev.editor;
 	
    editor.on('key', function(event) {
        var kc = event.data.keyCode,
        		csa = ~(CKEDITOR.CTRL | CKEDITOR.SHIFT | CKEDITOR.ALT),
                classname;
        if ( kc==13 && (kc & csa)==13){ //enter
        setTimeout(function(){
             var element = editor.getSelection().getStartElement();
             if (element.hasAscendant( 'p' ))
                element = element.getAscendant('p');
             if (element.getName() == 'p') {
                if (element.hasAttribute("class")){
                        classname=element.getAttribute("class");
                        element.removeAttribute("class");
	              }
             }
        },400);    
            
        }
    });
        	
});

http://jsfiddle.net/f63qctjp/2/

Upvotes: 1

Related Questions