Posted by loopduplicate on December 29, 2013 at 4:27am
Last updated by loopduplicate on Sun, 2013-12-29 05:23
Last updated by loopduplicate on Sun, 2013-12-29 05:23
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);
});
}
});
})();