1

Codewaggle's answer here got me started and I also have looked at Reinmar's answer, but I can't quite put this together.

I want to create a plugin with five custom spans (correction, deletion, suggestion...etc.) that I can then add to my CSS and have a button to apply each style using CKeditor in Drupal 7.

I don't want to use the drop-down for styles and prefer to have buttons with icons for each class added.

I used the basicstyles plugin as a jumping off point, but I have never done anything in javascript before so I am really in the dark.

I have added

config.extraPlugins = 'poligoeditstyles';

to the config file and set up the file structure of my plugin according to the guide on the CKeditor.

I assume that if all has gone according to plan I should see a button to drag into my toolbar, but, alas! No joy. I can see nothing added to my CKeditor toolbar when I add content or on the configuration page in Drupal:

admin/config/content/ckeditor/edit/Advanced

Am I missing something? Any help would be appreciated!

Here's my plugin code:

/**
 * POLIGO edit styles plug-in for CKeditor based on the Basic Styles plugin
 */

CKEDITOR.plugins.add( 'poligoeditstyles', {
    icons: 'correction,suggestion,deletion,commendation,dontunderstand', // %REMOVE_LINE_CORE%
    init: function( editor ) {
        var order = 0;
        // All buttons use the same code to register. So, to avoid
        // duplications, let's use this tool function.
        var addButtonCommand = function( buttonName, buttonLabel, commandName, styleDefiniton ) {
                // Disable the command if no definition is configured.
                if ( !styleDefiniton )
                    return;

                var style = new CKEDITOR.style( styleDefiniton );

                // Listen to contextual style activation.
                editor.attachStyleStateChange( style, function( state ) {
                    !editor.readOnly && editor.getCommand( commandName ).setState( state );
                });

                // Create the command that can be used to apply the style.
                editor.addCommand( commandName, new CKEDITOR.styleCommand( style ) );

                // Register the button, if the button plugin is loaded.
                if ( editor.ui.addButton ) {
                    editor.ui.addButton( buttonName, {
                        label: buttonLabel,
                        command: commandName,
                        toolbar: 'poligoeditstyles,' + ( order += 10 )
                    });
                }
            };

        var config = editor.config,
            lang = editor.lang;

        addButtonCommand( 'Correction', 'That's a mistake', 'correction', config.coreStyles_correction );
        addButtonCommand( 'Suggestion', 'That's OK, but I suggest...', 'suggestion', config.coreStyles_suggestion );
        addButtonCommand( 'Deletion', 'You don't need that', 'deletion', config.coreStyles_deletion );
        addButtonCommand( 'Commendation', 'Great job!', 'commendation', config.coreStyles_commendation );
        addButtonCommand( 'Dontunderstand', 'I don't understand what you mean', 'dontunderstand', config.coreStyles_dontunderstand );

    }
});

// POLIGO Editor Inline Styles.

CKEDITOR.config.coreStyles_correction = { element : 'span', attributes : { 'class': 'correction' }};
CKEDITOR.config.coreStyles_suggestion = { element : 'span', attributes : { 'class': 'suggestion' }};
CKEDITOR.config.coreStyles_deletion = { element : 'span', attributes : { 'class': 'deletion' }};
CKEDITOR.config.coreStyles_commendation = { element : 'span', attributes : { 'class': 'commendation' }};
CKEDITOR.config.coreStyles_dontunderstand = { element : 'span', attributes : { 'class': 'dontunderstand' }};
Community
  • 1
  • 1

1 Answers1

0

Shot in the dark here but have you added your button to your config.toolbar in your initialization or config somewhere else - see http://docs.cksource.com/CKEditor_3.x/Developers_Guide/Toolbar

Olirav
  • 165
  • 2
  • 12
  • Thanks for your answer. I don't think that is it. I have this in my config.js file as outlined in the doc on CKsource you referred to. `CKEDITOR.editorConfig = function( config ) { config.extraPlugins = 'poligoeditstyles'; config.toolbar = 'poligoeditstyles'; config.toolbar_poligoeditstyles = [ { name: 'poligoeditstyles', items : [ 'Correction','Suggestion','Deletion','Commendation','Dontunderstand' ] } ]; };` –  Feb 04 '13 at 16:22