Index: wysiwyg.admin.inc
===================================================================
--- wysiwyg.admin.inc (revision 572)
+++ wysiwyg.admin.inc (working copy)
@@ -286,7 +286,11 @@
'#type' => 'textarea',
'#title' => t('CSS classes'),
'#default_value' => $profile->settings['css_classes'],
- '#description' => t('Optionally define CSS classes for the "Font style" dropdown list.
Enter one class on each line in the format: !format. Example: !example
If left blank, CSS classes are automatically imported from all loaded stylesheet(s).', array('!format' => '[title]=[class]
', '!example' => 'My heading=header1')),
+ '#description' => t('Optionally define CSS classes for the "Font style" dropdown list.
Enter one class on each line in the format: !format. Example: !example
If left blank, CSS classes are automatically imported from all loaded stylesheet(s).',
+ $profile->editor == 'ckeditor' && version_compare($editor['installed version'], '3.2.1', '>=')
+ ? array('!format' => '[title]=[element].[class]
', '!example' => 'My heading=h1.header1')
+ : array('!format' => '[title]=[class]
', '!example' => 'My heading=header1')
+ ),
);
$form['submit'] = array(
Index: editors/ckeditor.inc
===================================================================
--- editors/ckeditor.inc (revision 572)
+++ editors/ckeditor.inc (working copy)
@@ -188,6 +188,14 @@
}
}
+ // Get additional styles, supported in ckeditor versions 3.2.1 and above.
+ if (!empty($config['css_classes'])) {
+ $styles = wysiwyg_ckeditor_get_styles_set($config['css_classes']);
+ if (!empty($styles)) {
+ $settings['stylesSet'] = $styles;
+ }
+ }
+
if (isset($config['language'])) {
$settings['language'] = $config['language'];
}
@@ -344,3 +352,50 @@
return $plugins;
}
+/**
+ * Converts the CSS classes string to an array of js settings.
+ *
+ * The CSS classes are edited in element CSS Classes, fieldset CSS
+ * of page admin/config/content/wysiwyg/profile/{filter}/edit.
+ *
+ * Note: only checking for correct format of each line. No error
+ * logging/hinting, as that should be done on the settings form.
+ *
+ * @param string $css_classes
+ * A list of classes to add to the style drop down.
+ * @return array
+ */
+function wysiwyg_ckeditor_get_styles_set($css_classes) {
+ $css_styles = array();
+ $lines = explode("\n", $css_classes);
+ foreach ($lines as $line) {
+ // This removes also Windows line endings.
+ $line = trim($line);
+ if (!empty($line)) {
+ // [name]=[element].[class] pattern expected.
+ $line_parts = explode('=', $line, 2);
+ if (count($line_parts) === 2) {
+ $selector_parts = explode('.', $line_parts[1], 2);
+ if (count($selector_parts) === 2) {
+ $style['name'] = trim($line_parts[0]);
+ $style['element'] = trim($selector_parts[0]);
+ $style['attributes']['class'] = trim($selector_parts[1]);
+ if (!empty($style['name']) && !empty($style['element']) && !empty($style['attributes']['class'])) {
+ $css_styles[] = $style;
+ }
+ }
+ }
+ }
+ }
+ return $css_styles;
+}
+
+/**
+ * load the stylesheet parser to parse the user defined stylesheets
+ */
+function ckeditor_styles_wysiwyg_editor_settings_alter(&$settings, &$context) {
+ if ($context['profile']->editor == 'ckeditor') {
+ $settings['extraPlugins'] .= ',stylesheetparser';
+ $settings['stylesSet'] = array();
+ }
+}
Index: editors/js/ckeditor-3.0.js
===================================================================
--- editors/js/ckeditor-3.0.js (revision 572)
+++ editors/js/ckeditor-3.0.js (working copy)
@@ -23,7 +23,11 @@
}
}
}
+ // Register Font styles (versions 3.2.1 and above).
+ if (CKEDITOR.stylesSet && Drupal.settings.wysiwyg.configs.ckeditor[format].stylesSet) {
+ CKEDITOR.stylesSet.add(format, Drupal.settings.wysiwyg.configs.ckeditor[format].stylesSet);
}
+ }
};