Good day. Can you please tell me how in Ckeditor 4.5.x to do the opposite action by pressing the same button? For example, as it happens when you press the B (bold) button.

An example of code that inserts the tag ... in the selected text:

 var PlugName = 'norss'; var PlugDesc = 'Исключить из RSS'; CKEDITOR.plugins.add( PlugName, { icons: PlugName, init: function( editor ) { if ( editor.ui.addButton ) { editor.ui.addButton( PlugName, { label: PlugDesc, command: PlugName, toolbar: 'insert' } ); } editor.addCommand( PlugName, { exec: function( editor ) { var sel = CKEDITOR.dom.element.createFromHtml( '<span class="no_rss">' + editor.getSelectedHtml(true) + '</span>' ); editor.insertElement( sel ); } }); }, } ); 

It is necessary that the button be displayed as pressed when hovering / highlighting the code that is inside it, and when this button is “unwrapped”, this tag is removed.

    1 answer 1

    The basicstyles addon (which adds b , i , s and a number of other buttons to the panel) seems to work with the internal CKEditor API, enabling / disabling these styles. I studied the basicstyles , I did not find an explicit code for removing the style. But there is a solution, and it is quite simple.

    There is another standard add-on for CKEditor - stylescombo . It looks like this:

    enter image description here

    You can change styles in the selector, both paragraph and inline. The inline style will suit your task, so it will be embedded in the CKEditor config :

     config.stylesSet = [ { name: 'Исключить из RSS', element: 'span', attributes: { "class": 'no_rss' } } ] 

    Now in the editor you can select any text and select the item "Exclude from RSS" in this selection. The no_rss class will be applied to the no_rss .

    In the same way, you can select any text (or just put the cursor inside) with such a class already in place and in the select box remove your choice from the "Exclude from RSS" item. The class will be deleted.

    Also I wrote about stylescombo in the question " CKEditor does not save Alt text ".