Request #9369: Use IMP HTML editor configuration for all Horde_Editor instances
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 9 Nov 2010 08:43:56 +0000 (01:43 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 9 Nov 2010 08:44:01 +0000 (01:44 -0700)
imp/compose.php
imp/lib/Prefs/Ui.php
imp/lib/Ui/Compose.php
imp/lib/Ui/Editor.php [new file with mode: 0644]
imp/lib/Views/Compose.php

index bf8ec65..c69ec87 100644 (file)
@@ -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');
 }
 
index 0d39282..b98d90d 100644 (file)
@@ -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');
index 651eef9..56f1be8 100644 (file)
@@ -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 <BR> on
-             * enter instead of <P>. */
-            // 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 (file)
index 0000000..58a7e29
--- /dev/null
@@ -0,0 +1,87 @@
+<?php
+/**
+ * THis class provices a place to share common code relating to IMP's
+ * setup and configuration of the browser HTML editor.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author   Michael Slusarz <slusarz@horde.org>
+ * @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 <BR> on
+             * enter instead of <P>. */
+            // 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) . '}'
+        ));
+    }
+
+}
index 3ba3169..609d17b 100644 (file)
@@ -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. */