Added feature #16114: htmlArea RTE: cleanup some js code generation code
authorStanislas Rolland <typo3@sjbr.ca>
Sat, 23 Oct 2010 01:23:14 +0000 (01:23 +0000)
committerStanislas Rolland <typo3@sjbr.ca>
Sat, 23 Oct 2010 01:23:14 +0000 (01:23 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@9194 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
typo3/sysext/rtehtmlarea/ChangeLog
typo3/sysext/rtehtmlarea/class.tx_rtehtmlarea_base.php
typo3/sysext/rtehtmlarea/pi2/class.tx_rtehtmlarea_pi2.php

index e5c0e2d..43a8e14 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2010-10-22  Stanislas Rolland  <typo3@sjbr.ca>
+
+       * Added feature #16114: htmlArea RTE: cleanup some js code generation code
+
 2010-10-22  Ernesto Baschny  <ernst@cron-it.de>
 
        * Fixed bug #16094: Label "on-click" for formerly "click-enlarge" does not make sense
index ccf6857..282dc3b 100644 (file)
@@ -1,3 +1,7 @@
+2010-10-22  Stanislas Rolland  <typo3@sjbr.ca>
+
+       * Added feature #16114: htmlArea RTE: cleanup some js code generation code
+
 2010-10-20  Stanislas Rolland  <typo3@sjbr.ca>
 
        * Added feature #16079: htmlArea RTE: Register RTE scripts with the autoloader
index aebc41a..26fab87 100644 (file)
@@ -734,10 +734,8 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                }
                $this->buildJSMainLangFile($RTEcounter);
                        // Avoid re-initialization on AJax call when RTEarea object was already initialized
-               $loadJavascriptCode = '
-               <script type="text/javascript" src="' . $this->doConcatenate($RTEcounter) . '"></script>
-               <script type="text/javascript">
-               /*<![CDATA[*/
+               $loadJavascriptCode = '<script type="text/javascript" src="' . $this->doConcatenate($RTEcounter) . '"></script>'. LF;
+               $loadJavascriptCode .= t3lib_div::wrapJS('
                        if (typeof(RTEarea) == "undefined") {
                                RTEarea = new Object();
                                RTEarea[0] = new Object();
@@ -763,9 +761,8 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                                                HTMLArea.initEditor(editorNumber);
                                        }
                                };
-                       }
-               /*]]>*/
-               </script>';
+                       }'
+               );
                return $loadJavascriptCode;
        }
 
@@ -777,11 +774,7 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
         * @return      string          the Javascript code for initializing the RTE
         */
        function loadJScode($RTEcounter) {
-               return (!$this->is_FE() ? '' : '
-               ' . '/*<![CDATA[*/') . '
-                       RTEarea.init();' . (!$this->is_FE() ? '' : '
-               /*]]>*/
-               ');
+               return TAB . 'RTEarea.init();';
        }
 
        /**
@@ -795,9 +788,7 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
         * @return      string          the Javascript code for configuring the RTE
         */
        function registerRTEinJS($RTEcounter, $table='', $uid='', $field='', $textAreaId = '') {
-
-               $configureRTEInJavascriptString = (!$this->is_FE() ? '' : '
-                       ' . '/*<![CDATA[*/') . '
+               $configureRTEInJavascriptString = '
                        if (typeof(configureEditorInstance) == "undefined") {
                                configureEditorInstance = new Object();
                        }
@@ -912,8 +903,7 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                        RTEarea.initEditor(editornumber);
                                }
                        };
-                       configureEditorInstance["' . $textAreaId . '"]();'. (!$this->is_FE() ? '' : '
-                       /*]]>*/');
+                       configureEditorInstance["' . $textAreaId . '"]();';
                return $configureRTEInJavascriptString;
        }
 
index 73fd12b..3a241cc 100644 (file)
@@ -221,7 +221,7 @@ class tx_rtehtmlarea_pi2 extends tx_rtehtmlarea_base {
                $pageRenderer->addJsFile($this->siteURL . 't3lib/js/extjs/ux/ext.resizable.js');
                $pageRenderer->addJsFile($this->siteURL . '/t3lib/js/extjs/notifications.js');
                if ($this->TCEform->RTEcounter == 1) {
-                       $this->TCEform->additionalJS_pre['rtehtmlarea-loadJScode'] = $this->loadJScode($this->TCEform->RTEcounter);
+                       $this->TCEform->additionalJS_pre['rtehtmlarea-loadJScode'] = $this->wrapCDATA($this->loadJScode($this->TCEform->RTEcounter));
                }
                $this->TCEform->additionalJS_initial = $this->loadJSfiles($this->TCEform->RTEcounter);
                $resizableSettings = array(
@@ -252,7 +252,7 @@ class tx_rtehtmlarea_pi2 extends tx_rtehtmlarea_base {
                $textAreaId = htmlspecialchars(preg_replace('/^[^a-zA-Z]/', 'x', $textAreaId)) . '_' . strval($this->TCEform->RTEcounter);
 
                        // Register RTE in JS:
-               $this->TCEform->additionalJS_post[] = $this->registerRTEinJS($this->TCEform->RTEcounter, '', '', '',$textAreaId);
+               $this->TCEform->additionalJS_post[] = $this->wrapCDATA($this->registerRTEinJS($this->TCEform->RTEcounter, '', '', '',$textAreaId));
 
                        // Set the save option for the RTE:
                $this->TCEform->additionalJS_submit[] = $this->setSaveRTE($this->TCEform->RTEcounter, $this->TCEform->formName, $textAreaId);
@@ -318,6 +318,23 @@ class tx_rtehtmlarea_pi2 extends tx_rtehtmlarea_base {
                }
                return $this->pageRenderer;
        }
+       /**
+        * Wrap input string in CDATA enclosure
+        *
+        * @param       string          $string: input to be wrapped
+        *
+        * @return      string          wrapped string
+        */
+       public function wrapCDATA ($string) {
+               return implode(LF,
+                       array(
+                               '',
+                               '/*<![CDATA[*/',
+                               $string,
+                               '/*]]>*/'
+                       )
+               );
+       }
 }
 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/pi2/class.tx_rtehtmlarea_pi2.php']) {
        include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/pi2/class.tx_rtehtmlarea_pi2.php']);