From 5907d00d695bffc7821333168c33b463821c3b8d Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Tue, 9 Nov 2010 01:43:56 -0700 Subject: [PATCH] Request #9369: Use IMP HTML editor configuration for all Horde_Editor instances --- imp/compose.php | 2 +- imp/lib/Prefs/Ui.php | 4 +-- imp/lib/Ui/Compose.php | 62 --------------------------------- imp/lib/Ui/Editor.php | 87 +++++++++++++++++++++++++++++++++++++++++++++++ imp/lib/Views/Compose.php | 5 ++- 5 files changed, 92 insertions(+), 68 deletions(-) create mode 100644 imp/lib/Ui/Editor.php diff --git a/imp/compose.php b/imp/compose.php index bf8ec6569..c69ec87a1 100644 --- a/imp/compose.php +++ b/imp/compose.php @@ -1040,7 +1040,7 @@ if ($redirect) { } if ($rtemode && !$redirect) { - $imp_ui->initRTE(); + IMP_Ui_Editor::init(); Horde::addInlineScript('CKEDITOR.replace("composeMessage", IMP.ckeditor_config)', 'load'); } diff --git a/imp/lib/Prefs/Ui.php b/imp/lib/Prefs/Ui.php index 0d3928233..b98d90d53 100644 --- a/imp/lib/Prefs/Ui.php +++ b/imp/lib/Prefs/Ui.php @@ -173,7 +173,7 @@ class IMP_Prefs_Ui $ui->suppress[] = 'signature_html_select'; } else { Horde::addScriptFile('signaturehtml.js', 'imp'); - $GLOBALS['injector']->getInstance('Horde_Editor')->initialize(array('id' => 'signature_html')); + IMP_Ui_Editor::init(false, 'signature_html'); } break; @@ -1747,7 +1747,7 @@ class IMP_Prefs_Ui $stationery = $GLOBALS['injector']->getInstance('IMP_Compose_Stationery'); if ($ob->type == 'html') { - $GLOBALS['injector']->getInstance('Horde_Editor')->initialize(array('id' => 'content')); + IMP_Ui_Editor::init(false, 'content'); } $t = $GLOBALS['injector']->createInstance('Horde_Template'); diff --git a/imp/lib/Ui/Compose.php b/imp/lib/Ui/Compose.php index 651eef9bf..56f1be8f4 100644 --- a/imp/lib/Ui/Compose.php +++ b/imp/lib/Ui/Compose.php @@ -148,68 +148,6 @@ class IMP_Ui_Compose } /** - * Initialize the Rich Text Editor (RTE). - * - * @param boolean $mini Load the basic ckeditor stub? - */ - public function initRTE($basic = false) - { - $GLOBALS['injector']->getInstance('Horde_Editor')->initialize(array('basic' => $basic)); - - $font_family = $GLOBALS['prefs']->getValue('compose_html_font_family'); - if (!$font_family) { - $font_family = 'Arial'; - } - - $font_size = intval($GLOBALS['prefs']->getValue('compose_html_font_size')); - $font_size = $font_size - /* Font size should be between 8 and 24 pixels. Or else recipients - * will hate us. Default to 14px. */ - ? min(24, max(8, $font_size)) . 'px' - : '14px'; - - $config = array( - /* To more closely match "normal" textarea behavior, send
on - * enter instead of

. */ - // CKEDITOR.ENTER_BR - 'enterMode: 2', - // CKEDITOR.ENTER_P - 'shiftEnterMode: 1', - - /* Don't load the config.js file. */ - 'customConfig: ""', - - /* Disable resize of the textarea. */ - 'resize_enabled: false', - - /* Disable spell check as you type. */ - 'scayt_autoStartup: false', - - /* Convert HTML entities. */ - 'entities: false', - - /* Set language to Horde language. */ - 'language: "' . Horde_String::lower($GLOBALS['language']) . '"', - - /* Default display font. This is NOT the font used to send - * the message, however. */ - 'contentsCss: "body { font-family: ' . $font_family . '; font-size: ' . $font_size . '; }"', - 'font_defaultLabel: "' . $font_family . '"', - 'fontSize_defaultLabel: "' . $font_size . '"' - ); - - $buttons = $GLOBALS['prefs']->getValue('ckeditor_buttons'); - if (!empty($buttons)) { - $config[] = 'toolbar: ' . $GLOBALS['prefs']->getValue('ckeditor_buttons'); - } - - Horde::addInlineScript(array( - 'window.IMP = window.IMP || {}', - 'IMP.ckeditor_config = {' . implode(',', $config) . '}' - )); - } - - /** * Create the IMP_Contents objects needed to create a message. * * @param Horde_Variables $vars The variables object. diff --git a/imp/lib/Ui/Editor.php b/imp/lib/Ui/Editor.php new file mode 100644 index 000000000..58a7e29ef --- /dev/null +++ b/imp/lib/Ui/Editor.php @@ -0,0 +1,87 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @package IMP + */ +class IMP_Ui_Editor +{ + /** + * Initialize the Rich Text Editor (RTE). + * + * @param boolean $basic Load the basic ckeditor stub? + * @param string $id The DOM ID to load. If null, won't start editor + * on page load. + */ + static public function init($basic = false, $id = null) + { + global $injector, $language, $prefs; + + $injector->getInstance('Horde_Editor')->initialize(array( + 'basic' => $basic, + 'id' => $id + )); + + $font_family = $prefs->getValue('compose_html_font_family'); + if (!$font_family) { + $font_family = 'Arial'; + } + + $font_size = intval($prefs->getValue('compose_html_font_size')); + $font_size = $font_size + /* Font size should be between 8 and 24 pixels. Or else recipients + * will hate us. Default to 14px. */ + ? min(24, max(8, $font_size)) . 'px' + : '14px'; + + $config = array( + /* To more closely match "normal" textarea behavior, send
on + * enter instead of

. */ + // CKEDITOR.ENTER_BR + 'enterMode: 2', + // CKEDITOR.ENTER_P + 'shiftEnterMode: 1', + + /* Don't load the config.js file. */ + 'customConfig: ""', + + /* Disable resize of the textarea. */ + 'resize_enabled: false', + + /* Disable spell check as you type. */ + 'scayt_autoStartup: false', + + /* Convert HTML entities. */ + 'entities: false', + + /* Set language to Horde language. */ + 'language: "' . Horde_String::lower($language) . '"', + + /* Default display font. This is NOT the font used to send + * the message, however. */ + 'contentsCss: "body { font-family: ' . $font_family . '; font-size: ' . $font_size . '; }"', + 'font_defaultLabel: "' . $font_family . '"', + 'fontSize_defaultLabel: "' . $font_size . '"' + ); + + $buttons = $prefs->getValue('ckeditor_buttons'); + if (!empty($buttons)) { + $config[] = 'toolbar: ' . $prefs->getValue('ckeditor_buttons'); + } + + Horde::addInlineScript(array( + 'window.IMP = window.IMP || {}', + 'IMP.ckeditor_config = {' . implode(',', $config) . '}' + )); + } + +} diff --git a/imp/lib/Views/Compose.php b/imp/lib/Views/Compose.php index 3ba31698a..609d17b81 100644 --- a/imp/lib/Views/Compose.php +++ b/imp/lib/Views/Compose.php @@ -55,8 +55,7 @@ class IMP_Views_Compose $t->set('selected_identity', intval($identity->getDefault())); /* Generate identities list. */ - $imp_ui = $injector->getInstance('IMP_Ui_Compose'); - $result['js'] = array_merge($result['js'], $imp_ui->identityJs()); + $result['js'] = array_merge($result['js'], $injector->getInstance('IMP_Ui_Compose')->identityJs()); if ($t->get('composeCache') && count($imp_compose)) { foreach ($imp_compose as $num => $atc) { @@ -79,7 +78,7 @@ class IMP_Views_Compose $t->set('compose_html', $prefs->getValue('compose_html')); $t->set('rte', true); - $imp_ui->initRTE(!$t->get('compose_html')); + IMP_Ui_Editor::init(!$t->get('compose_html')); } /* Create list for sent-mail selection. */ -- 2.11.0