From fd701163782dfcdcb02f1898d3d8cf6c976e036e Mon Sep 17 00:00:00 2001 From: Lucas D Hedding Date: Tue, 26 Mar 2013 20:07:05 -0500 Subject: [PATCH] Issue #1853550 by jm.federico, rwohleb, chrisrd, klaasvw, yanniboi, kaidjohnson, TwoD | Shaun Dychko: Fixed Ckeditor 4.0 - The version of CKEditor could not be detected. --- editors/ckeditor.inc | 141 ++++++++++++++++++++++++++++++++++++++++++-- editors/js/ckeditor-3.0.js | 10 +--- 2 files changed, 138 insertions(+), 13 deletions(-) diff --git a/editors/ckeditor.inc b/editors/ckeditor.inc index fcf168e..05bca1c 100644 --- a/editors/ckeditor.inc +++ b/editors/ckeditor.inc @@ -55,7 +55,9 @@ function wysiwyg_ckeditor_editor() { * Return an install note. */ function wysiwyg_ckeditor_install_note() { - return '

' . t('Do NOT download the "CKEditor for Drupal" edition.') . '

'; + $output = '

' . t('Do NOT download the "CKEditor for Drupal" edition.') . '
'; + $output .= t('Make sure you install the full package as not all plugins work with the standard package.') . '

'; + return $output; } /** @@ -78,7 +80,8 @@ function wysiwyg_ckeditor_version($editor) { // version:'CKEditor 3.0 SVN',revision:'3665' // version:'3.0 RC',revision:'3753' // version:'3.0.1',revision:'4391' - if (preg_match('@version:\'(?:CKEditor )?([\d\.]+)(?:.+revision:\'([\d]+))?@', $line, $version)) { + // version:"4.0",revision:"769d96134b" + if (preg_match('@version:[\'"](?:CKEditor )?([\d\.]+)(?:.+revision:[\'"]([[:xdigit:]]+))?@', $line, $version)) { fclose($library); // Version numbers need to have three parts since 3.0.1. $version[1] = preg_replace('/^(\d+)\.(\d+)$/', '${1}.${2}.0', $version[1]); @@ -132,6 +135,15 @@ function wysiwyg_ckeditor_themes($editor, $profile) { * @see http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html#.stylesSet */ function wysiwyg_ckeditor_settings_form(&$form, &$form_state) { + if (version_compare($form_state['wysiwyg']['editor']['installed version'], '3.6.0', '>=')) { + $form['appearance']['default_toolbar_grouping'] = array( + '#type' => 'checkbox', + '#title' => t('Use default toolbar button grouping'), + '#default_value' => !empty($form_state['wysiwyg_profile']->settings['default_toolbar_grouping']), + '#return_value' => 1, + '#description' => t('This option gives you the ability to enable/disable the usage of default groupings for toolbar buttons. If enabled, toolbar buttons will be placed into predetermined groups instead of all in a single group.'), + ); + } if (version_compare($form_state['wysiwyg']['editor']['installed version'], '3.2.1', '>=')) { // Replace CSS classes element description to explain the advanced syntax. $form['css']['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 loaded stylesheet(s).', array( @@ -199,6 +211,7 @@ EOL; * Drupal.settings.wysiwyg.configs.{editor} */ function wysiwyg_ckeditor_settings($editor, $config, $theme) { + $default_skin = (version_compare($editor['installed version'], '4.0.0', '<') ? 'kama' : 'mono'); $settings = array( 'width' => 'auto', // For better compatibility with smaller textareas. @@ -206,7 +219,7 @@ function wysiwyg_ckeditor_settings($editor, $config, $theme) { 'height' => 420, // @todo Do not use skins as themes and add separate skin handling. 'theme' => 'default', - 'skin' => !empty($theme) ? $theme : 'kama', + 'skin' => !empty($theme) ? $theme : $default_skin, // By default, CKEditor converts most characters into HTML entities. Since // it does not support a custom definition, but Drupal supports Unicode, we // disable at least the additional character sets. CKEditor always converts @@ -273,6 +286,8 @@ function wysiwyg_ckeditor_settings($editor, $config, $theme) { } $settings['toolbar'] = array(); + $supports_groups = version_compare($editor['installed version'], '3.6.0', '>='); + $use_default_groups = $supports_groups && !empty($config['default_toolbar_grouping']); if (!empty($config['buttons'])) { $extra_plugins = array(); $plugins = wysiwyg_get_plugins($editor['name']); @@ -286,7 +301,13 @@ function wysiwyg_ckeditor_settings($editor, $config, $theme) { } // Add buttons. if ($type == 'buttons') { - $settings['toolbar'][] = $button; + if ($use_default_groups) { + $settings['toolbar'][_wysiwyg_ckeditor_group($button)][] = $button; + } + else { + // Use one button row for backwards compatibility. + $settings['toolbar'][] = $button; + } } // Add external Drupal plugins to the list of extensions. if ($type == 'buttons' && !empty($plugins[$plugin]['proxy'])) { @@ -315,8 +336,23 @@ function wysiwyg_ckeditor_settings($editor, $config, $theme) { $settings['extraPlugins'] = implode(',', $extra_plugins); } } - // For now, all buttons are placed into one row. - $settings['toolbar'] = array($settings['toolbar']); + + if ($use_default_groups) { + // Organize groups to use lables to improves accesibility + // http://docs.ckeditor.com/#!/guide/dev_toolbar-section-3. + $groups_toolbar = array(); + foreach ($settings['toolbar'] as $group => $items) { + $groups_toolbar[] = array( + 'name' => $group, + 'items' => $items, + ); + $settings['toolbar'] = $groups_toolbar; + } + } + else { + // For now, all buttons are placed into one row. + $settings['toolbar'] = array($settings['toolbar']); + } return $settings; } @@ -444,6 +480,7 @@ function wysiwyg_ckeditor_plugins($editor) { 'Maximize' => t('Maximize'), 'SpellChecker' => t('Check spelling'), 'Scayt' => t('Check spelling as you type'), 'About' => t('About'), + 'Templates' => t('Templates'), ), 'internal' => TRUE, ), @@ -462,3 +499,95 @@ function wysiwyg_ckeditor_plugins($editor) { return $plugins; } +/** + * Define grouping for ckEditor buttons. + */ +function _wysiwyg_ckeditor_group($button) { + switch ($button) { + case 'Source': + $group = 'document'; + break; + + case 'Cut': + case 'Copy': + case 'Paste': + case 'PasteText': + case 'PasteFromWord': + case 'Undo': + case 'Redo': + $group = 'clipboard'; + break; + + case 'Find': + case 'Replace': + case 'SelectAll': + case 'SpellChecker': + case 'Scayt': + $group = 'editing'; + break; + + case 'Bold': + case 'Italic': + case 'Underline': + case 'Strike': + case 'Subscript': + case 'Superscript': + case 'RemoveFormat': + $group = 'basicstyles'; + break; + + case 'NumberedList': + case 'BulletedList': + case 'Outdent': + case 'Indent': + case 'Blockquote': + case 'CreateDiv': + case 'JustifyLeft': + case 'JustifyCenter': + case 'JustifyRight': + case 'JustifyBlock': + case 'BidiLtr': + case 'BidiRtl': + $group = 'paragraph'; + break; + + case 'Link': + case 'Unlink': + case 'Anchor': + $group = 'links'; + break; + + case 'Image': + case 'Flash': + case 'Table': + case 'HorizontalRule': + case 'Smiley': + case 'SpecialChar': + case 'Iframe': + case 'Templates': + $group = 'insert'; + break; + + case 'Styles': + case 'Format': + case 'Font': + case 'FontSize': + $group = 'styles'; + break; + + case 'TextColor': + case 'BGColor': + $group = 'colors'; + break; + + case 'Maximize': + case 'ShowBlocks': + case 'About': + $group = 'tools'; + break; + + default: + $group = 'other'; + } + return $group; +} diff --git a/editors/js/ckeditor-3.0.js b/editors/js/ckeditor-3.0.js index f288928..1563f73 100644 --- a/editors/js/ckeditor-3.0.js +++ b/editors/js/ckeditor-3.0.js @@ -184,7 +184,8 @@ Drupal.wysiwyg.editor.instance.ckeditor = { editor.on('mode', function(ev) { if (ev.editor.mode == 'wysiwyg') { // Inject CSS files directly into the editing area head tag. - $('head', $('#cke_contents_' + ev.editor.name + ' iframe').eq(0).contents()).append(''); + var iframe = $('#cke_contents_' + ev.editor.name + ' iframe, #' + ev.editor.id + '_contents iframe'); + $('head', iframe.eq(0).contents()).append(''); } }); } @@ -199,12 +200,7 @@ Drupal.wysiwyg.editor.instance.ckeditor = { data.node = data.node.$; } if (selection.getType() == CKEDITOR.SELECTION_TEXT) { - if (CKEDITOR.env.ie) { - data.content = selection.getNative().createRange().text; - } - else { - data.content = selection.getNative().toString(); - } + data.content = selection.getSelectedText(); } else if (data.node) { // content is supposed to contain the "outerHTML". -- 1.7.9.5