Skip to content

Instantly share code, notes, and snippets.

@larsolino
Created July 30, 2016 12:32
Show Gist options
  • Save larsolino/ecbd571d50348f774d87f51c11d71ff5 to your computer and use it in GitHub Desktop.
Save larsolino/ecbd571d50348f774d87f51c11d71ff5 to your computer and use it in GitHub Desktop.
Custom Magnolia RIchText field CKEditor configuration file
CKEDITOR.plugins.addExternal("codemirror", CKEDITOR.vaadinDirUrl + "js/codemirror/");
CKEDITOR.editorConfig = function( config ) {
// MIRROR info.magnolia.ui.form.field.definition.RichTextFieldDefinition
definition = {
alignment: false,
images: true,
lists: true,
source: true,
tables: true,
colors: null,
fonts: null,
fontSizes: null
}
// MIRROR info.magnolia.ui.form.field.factory.RichTextFieldFactory
removePlugins = [];
// CONFIGURATION FROM DEFINITION
if (!definition.alignment) {
removePlugins.push("justify");
}
if (!definition.images) {
removePlugins.push("image");
}
if (!definition.lists) {
// In CKEditor 4.1.1 enterkey depends on indent which itself depends on list
removePlugins.push("enterkey");
removePlugins.push("indent");
removePlugins.push("list");
}
if (!definition.source) {
removePlugins.push("sourcearea");
}
if (!definition.tables) {
removePlugins.push("table");
removePlugins.push("tabletools");
}
if (definition.colors != null) {
config.colorButton_colors = definition.colors;
config.colorButton_enableMore = false;
removePlugins.push("colordialog");
} else {
removePlugins.push("colorbutton");
removePlugins.push("colordialog");
}
if (definition.fonts != null) {
config.font_names = definition.fonts;
} else {
config.removeButtons = "Font";
}
if (definition.fontSizes != null) {
config.fontSize_sizes = definition.fontSizes;
} else {
config.removeButtons = "FontSize";
}
if (definition.fonts == null && definition.fontSizes == null) {
removePlugins.push("font");
removePlugins.push("fontSize");
}
// DEFAULT CONFIGURATION FROM FIELD FACTORY
removePlugins.push("elementspath");
removePlugins.push("filebrowser");
config.removePlugins = removePlugins.join(",");
config.extraPlugins = "magnolialink,magnoliaFileBrowser,codemirror";
//CODEMIRROR PLUGIN CONFIGURATION
config.codemirror = {
theme: 'default',
lineNumbers: true,
lineWrapping: true,
matchBrackets: true,
autoCloseTags: true,
autoCloseBrackets: true,
enableSearchTools: true, // Whether or not to enable search tools, CTRL+F (Find), CTRL+SHIFT+F (Replace), CTRL+SHIFT+R (Replace All), CTRL+G (Find Next), CTRL+SHIFT+G (Find Previous)
enableCodeFolding: true, // Whether or not you wish to enable code folding (requires 'lineNumbers' to be set to 'true')
enableCodeFormatting: false,
autoFormatOnStart: false, // Whether or not to automatically format code should be done when the editor is loaded
autoFormatOnModeChange: false, // Whether or not to automatically format code should be done every time the source view is opened
autoFormatOnUncomment: false, // Whether or not to automatically format code which has just been uncommented
mode: 'htmlmixed', // Define the language specific mode 'htmlmixed' for html including (css, xml, javascript), 'application/x-httpd-php' for php mode including html, or 'text/javascript' for using java script only
showSearchButton: true, // Whether or not to show the search Code button on the toolbar
showTrailingSpace: true,
highlightMatches: true,
showFormatButton: true,
showCommentButton: true,
showUncommentButton: true,
showAutoCompleteButton: true,
styleActiveLine: true
};
config.baseFloatZIndex = 150;
config.resize_enabled = false;
config.toolbar = "Magnolia";
config.toolbar_Magnolia = [
{ name: "basicstyles", items: [ "Bold", "Italic", "Underline", "SpecialChar" ] },
{ name: "paragraph", items: [ "NumberedList", "BulletedList", "JustifyLeft", "JustifyCenter", "JustifyRight", "JustifyBlock", "Image", "Table" ] },
{ name: "links", items: [ "Link", "InternalLink", "DamLink", "Unlink" ] },
{ name: "styles", items: [ "Font", "FontSize", "TextColor" ] },
{ name: "clipboard", items: [ "Cut", "Copy", "Paste", "PasteText", "PasteFromWord" ] },
{ name: "undo", items: [ "Undo", "Redo" ] },
{ name: "tools", items: [ "Source" ] }
];
config.allowedContent = true; // don't filter my data
config.entities_processNumerical = false;
config.fillEmptyBlocks = false; // no &nbsp; in <p>
config.autoParagraph = false;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment