[rt-users] toggle FCKeditor on and off for Correspondence

Allen allen+rtlist at crystalfontz.com
Mon Aug 24 19:59:00 EDT 2009


Most of our staff have decided they like the plaintext editor
preference better than the WYSIWYG editor. (One reason is because the
browser's spellchecker is better than the Rich text editor.)

However, once in a while, they need to paste something with specific
formatting, like chunks of code with indenting, and for that the HTML
editor works better. So I wanted a way to let staff easily switch or
revert from plaintext to the FCKeditor.

The code to swap plaintext for Rich text editor is below.

Does anyone have any Javascript for going in reverse -- from FCKeditor
to plaintext textarea? There are some entity transformations that take
place going from plain to rich that need to be reversed, and hidden
html elements that get attached to the DOM that need to be removed.



--- /usr/share/request-tracker3.8/html/Elements/HeaderJavascript
 2009-06-16 14:57:46.000000000 -0700
+++ HeaderJavascript    2009-08-24 16:57:28.000000000 -0700
@@ -54,27 +54,49 @@
 <script type="text/javascript"
src="<%RT->Config->Get('WebPath')%>/NoAuth/js/ahah.js"></script>
 <script type="text/javascript"
src="<%RT->Config->Get('WebPath')%>/NoAuth/js/prototype/prototype.js"></script>
 <script type="text/javascript"
src="<%RT->Config->Get('WebPath')%>/NoAuth/js/scriptaculous/scriptaculous.js?load=effects,controls"></script>
-% if ( RT->Config->Get('MessageBoxRichText',  $session{'CurrentUser'}) ) {
 <script type="text/javascript"
src="<%RT->Config->Get('WebPath')%>/NoAuth/RichText/fckeditor.js"></script>
-% }
+
+% if($m->{'top_path'} =~ /(Update\.html)/) { # try to only do this on
Comment/Reply page
+%     # if FCK is OFF in preferences, give option to turn it on
+%     if (! RT->Config->Get('MessageBoxRichText',  $session{'CurrentUser'})) {
+<script type="text/javascript">
+// <![CDATA[
+    Event.observe(window, 'load', function() {
+        $('UpdateContent').up().insert({ top: "<div><a
id='FCKtoggler' href='#'>Enable Rich Text Editor</a></div>" });
+        Event.observe('FCKtoggler', 'click', function(event) {
+            ReplaceAllTextareas("UpdateContent");
+            $('FCKtoggler').up().remove();
+            Event.stop(event);
+        });
+    });
+// ]]>
+</script>
+%     } # end had WYSIWYG editor OFF in preferences
+% } # end was on Update.html
+
 <script type="text/javascript"><!--
     doOnLoad(loadTitleBoxStates);
 % if ( $focus ) {
     doOnLoad(function () { focusElementById('<% $focus %>') });
 % }

-% if ( $onload ) {
-    doOnLoad(<% $onload |n %>);
-% }
-
-% if ( RT->Config->Get('MessageBoxRichText',  $session{'CurrentUser'})) {
-    function ReplaceAllTextareas() {
+    function ReplaceAllTextareas(textAreaElementId) {
         if (!FCKeditor_IsCompatibleBrowser())
             return false;

         // replace all content and signature message boxes
         var allTextAreas = document.getElementsByTagName("textarea");

+        // if function was called for just 1 textarea, just do that one
+        if(textAreaElementId)
+        {
+            var oneTextArea = document.getElementById(textAreaElementId);
+            if(oneTextArea)
+            {
+                allTextAreas = [ oneTextArea ];
+            }
+        }
+
         for (var i=0; i < allTextAreas.length; i++) {
             var textArea = allTextAreas[i];
             if ( (textArea.getAttribute('class') == 'messagebox')
@@ -114,6 +136,12 @@
             }
         }
     }
+
+% if ( RT->Config->Get('MessageBoxRichText',  $session{'CurrentUser'})) {
     doOnLoad(ReplaceAllTextareas);
 % }
+
+% if ( $onload ) {
+    doOnLoad(<% $onload |n %>);
+% }
 --></script>



More information about the rt-users mailing list