Skip to content

Instantly share code, notes, and snippets.

@joelstein
Last active August 29, 2015 14:13
Show Gist options
  • Save joelstein/a171280c705c8fae0092 to your computer and use it in GitHub Desktop.
Save joelstein/a171280c705c8fae0092 to your computer and use it in GitHub Desktop.
CKEditor custom styles
  • If Advanced Content Filter is enabled, need to configure "extra allowed content" to let elements have classes.
  • A catch all value is *(*), which means any element can have any class added to it.
  • To refine this, you can limit available classes, like *(left, right), which will only let "left" and "right" classes be added.
  • Enhanced Image (image2 plugin) can only be targeted through a "widget" type, by defining type: 'widget' and then widget: 'image'.
/* Text Light */
div.text-light, p.text-light, blockquote.text-light {
color: #666;
}
/* Inline List */
ul.inline li {
display: inline;
}
/* Image Padding Left & Image Padding Right */
.img-padding-left {
padding-left: 10px;
}
.img-padding-right {
padding-right: 10px;
}
if (typeof(CKEDITOR) !== 'undefined') {
CKEDITOR.addStylesSet('drupal', [
// "text-light" class on multiple elements.
{
name: 'Text Light',
element: ['div', 'p', 'blockquote'],
attributes: {class: 'text-light'}
},
// "inline" class on ul elements.
{
name: 'Inline List',
element: 'ul',
attributes: {class: 'inline'}
},
// "img-padding-left" and "-right" classes on image widgets.
{
name: 'Image Padding Left',
type: 'widget',
widget: 'image',
attributes: {class: 'img-padding-left'}
},
{
name: 'Image Padding Right',
type: 'widget',
widget: 'image',
attributes: {class: 'img-padding-right'}
}
]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment