I have found and tried about 5 different tutorials on how to add a cutom button to CKEditor, not one has worked.

I need a basic working example of adding a button to CKEdtor for Drupal 7

Comments

VM’s picture

it would aid if you provided the code that you've already cobbled together. Otherwise, please edit this post and move it to the 'post installation' forum. Thank you.

jesterFortyEight’s picture

I have three that I have tried, this is the one I need to work.
the below code was copied and modified form one of the online tutorials I found

the lr_ckeditor.module code

<?php
function lr_ckeditor_wysiwyg_plugin($editor, $version) {
 switch ($editor) {
    case 'ckeditor':
      return array(
        'lr_ckeditor' => array(
          'path' => drupal_get_path('module', 'lr_ckeditor') . '/plugin',
          'filename' => 'plugin.js',
          'buttons' => array(
            'lr_ckeditor' => t('Add a div'),
          ),
          'load' => TRUE,
          'internal' => FALSE,
        ),
      );
      break;
  }
}

the plugin.js code

(function($) {
 CKEDITOR.plugins.add( 'lr_plugin', {
  init: function( editor )
  {
   editor.addCommand( 'lr_div_command', {
    exec : function( editor ) {
     
     editor.insertHtml( '<div class="cross-section-link"> </div>' );
    }
   });
   
   editor.ui.addButton( 'lr_plugin_button', {
    label: 'Blog Div', 
    command: 'lr_div_command',
    icon: '/sites/all/modules/ckeditor/images/buttons/creatediv.png'
   });
  }
 });
})(jQuery);

jesterFortyEight’s picture

I changed the .module code to this

<?php
function lr_ckeditor_ckeditor_plugin() {
   return array(
      'plugin_name' => array(
         // Plugin name.
            'name' => 'lr_ckeditor',
            // Plugin description - it will be displayed in the plugins management section of the profile settings.
            'desc' => t('A plugin for managing some features specific to Lowest rates'),
            // The full path to the CKEditor plugin directory, trailing slash included.
            'path' => drupal_get_path('module', 'lr_ckeditor') . '/plugin/',
            )
         );
}

but I don't know how to add the button/icon taken from here
http://docs.cksource.com/CKEditor_for_Drupal/Open_Source/Drupal_7/Plugin...

using the above gives my the option of activating the plugin on the CKEditor config page (progress)
but the js causes an error - pulled from firebug:
f is null
and as a result the editor does not load

plugin.js

(function($) {
 CKEDITOR.plugins.add( 'lr_ckeditor', {
  icons: '/sites/all/modules/ckeditor/images/buttons/creatediv.png'
  init: function( editor ){
   editor.addCommand( 'lr_div_insert_basic', {
    exec : function( editor ) {
     
     editor.insertHtml( '<div class="cross-section-link"> </div>' );
    }
   });
   editor.ui.addButton( 'lr_plugin_button', {
    label: 'LR Basic Div', 
    command: 'lr_div_insert_basic',
	toolbar: 'insert',
    
   });
  }
 });
})(jQuery);