CKEditor / WYSIWYG configuration example

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
You are viewing a wiki page. You are welcome to join the group and then edit it. Be bold!

Here's a quick example of how add some custom configuration to CKEditor when using the WYSIWYG module.

This was tested on CKEditor 4.3.1 and the WYSIWYG module version 7.x-2.x-dev from 2013-Oct-26.

The "Apply simple source formatting" option in the "Cleanup and output" text format options must be checked for the indentation options to take effect.

Create module:

<?php

/**
* @file
* example.module
*/

/**
* Implements hook_wysiwyg_editor_settings_alter().
*/
function example_wysiwyg_editor_settings_alter(&$settings, $context) {
  if (
$context['profile']->editor === 'ckeditor') {
   
$settings['customConfig'] = base_path() . drupal_get_path('module', 'example') . '/example_config.js';
  }
}

?>

Add JS config file:

// http://docs.ckeditor.com/#!/api/CKEDITOR.config

// Uses 2 spaces instead of a tab for indentation.
CKEDITOR.config.dataIndentationChars = '  ';
CKEDITOR.config.tabSpaces = 2;


// Resizes editor for specific fields when initially loaded.
(function(){
    var instanceNames = {
        'edit-field-my-field-und-0-value' : 200,
        'edit-field-my-other-field-und-0-value': 200,
        'edit-body-und-0-value': 350
    };

    CKEDITOR.on('instanceCreated', function(e){
        var instance = e.editor;

        if (instanceNames[instance.name] !== "undefined") {
            instance.on('instanceReady', function(e){
                var height  = instanceNames[instance.name];
                e.editor.resize('100%', height);
            });
        }
    });
})();

Wysiwyg

Group organizers

Group categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: