Fixed bug #9596: htmlArea RTE does not work in IRRE subelements
authorStanislas Rolland <typo3@sjbr.ca>
Thu, 8 Jan 2009 21:10:33 +0000 (21:10 +0000)
committerStanislas Rolland <typo3@sjbr.ca>
Thu, 8 Jan 2009 21:10:33 +0000 (21:10 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/branches/TYPO3_4-2@4670 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
typo3/sysext/rtehtmlarea/ChangeLog
typo3/sysext/rtehtmlarea/class.tx_rtehtmlarea_base.php
typo3/sysext/rtehtmlarea/htmlarea/htmlarea-gecko.js
typo3/sysext/rtehtmlarea/htmlarea/htmlarea.js
typo3/sysext/rtehtmlarea/htmlarea/plugins/TYPO3HtmlParser/typo3html-parser.js
typo3/sysext/rtehtmlarea/pi2/class.tx_rtehtmlarea_pi2.php

index 6d93e8b..3b2d207 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2009-01-08  Stanislas Rolland  <typo3@sjbr.ca>
+
+       * Fixed bug #9596: htmlArea RTE does not work in IRRE subelements
+
 2009-01-08  Oliver Hader  <oliver@typo3.org>
 
        * Fixed bug #9893: Syntax error in TCA types definitions of tt_content
index cf97ccd..db9184f 100644 (file)
@@ -1,3 +1,7 @@
+2009-01-08  Stanislas Rolland  <typo3@sjbr.ca>
+
+       * Fixed bug #9596: htmlArea RTE does not work in IRRE subelements
+
 2008-12-02  Stanislas Rolland  <typo3@sjbr.ca>
 
        * Updated htmlArea RTE version to 1.7.8 for TYPO3 4.2.4
index 409f675..794af11 100644 (file)
@@ -385,12 +385,20 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                                $GLOBALS['TSFE']->additionalHeaderData['rtehtmlarea-contentCSS'] = $this->getPageStyle();
                                $GLOBALS['TSFE']->additionalHeaderData['rtehtmlarea-skin'] = $this->getSkin();
                        } else {
-                               $GLOBALS['SOBE']->doc->additionalHeaderData['rtehtmlarea-contentCSS'] = $this->getPageStyle();
-                               $GLOBALS['SOBE']->doc->additionalHeaderData['rtehtmlarea-skin'] = $this->getSkin();
+                                       // If it was not known that an RTE-enabled field would be created when the page was first created, the css would not have been added to head
+                               if (is_object($this->TCEform->inline) && $this->TCEform->inline->isAjaxCall) {
+                                       $this->TCEform->additionalCode_pre['rtehtmlarea-contentCSS'] = $this->getPageStyle();
+                                       $this->TCEform->additionalCode_pre['rtehtmlarea-skin'] = $this->getSkin();
+                               } else {
+                                       $GLOBALS['SOBE']->doc->additionalHeaderData['rtehtmlarea-contentCSS'] = $this->getPageStyle();
+                                       $GLOBALS['SOBE']->doc->additionalHeaderData['rtehtmlarea-skin'] = $this->getSkin();
+                               }
                        }
                                // Loading JavaScript files and code
-                       $this->TCEform->additionalCode_pre['rtehtmlarea-loadJSfiles'] = $this->loadJSfiles($this->TCEform->RTEcounter);
-                       $this->TCEform->additionalJS_pre['rtehtmlarea-loadJScode'] = $this->loadJScode($this->TCEform->RTEcounter);
+                       if ($this->TCEform->RTEcounter == 1) {
+                               $this->TCEform->additionalCode_pre['rtehtmlarea-loadJSfiles'] = $this->loadJSfiles($this->TCEform->RTEcounter);
+                               $this->TCEform->additionalJS_pre['rtehtmlarea-loadJScode'] = $this->loadJScode($this->TCEform->RTEcounter);
+                       }
 
                        /* =======================================
                         * DRAW THE EDITOR
@@ -408,6 +416,7 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                        }
                                // Register RTE windows
                        $this->TCEform->RTEwindows[] = $PA['itemFormElName'];
+                       $textAreaId = htmlspecialchars($PA['itemFormElName']);
 
                                // Check if wizard_rte called this for fullscreen edtition; if so, change the size of the RTE to fullscreen using JS
                        if (basename(PATH_thisScript) == 'wizard_rte.php') {
@@ -420,21 +429,22 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                                $editorWrapWidth = '100%';
                                $editorWrapHeight = '100%';
                                $this->RTEdivStyle = 'position:relative; left:0px; top:0px; height:100%; width:100%; border: 1px solid black; padding: 2px 0px 2px 2px;';
-                               $this->TCEform->additionalJS_post[] = $this->setRTEsizeByJS('RTEarea'.$this->TCEform->RTEcounter, $height, $width);
+                               $this->TCEform->additionalJS_post[] = $this->setRTEsizeByJS('RTEarea' . $textAreaId, $height, $width);
                        }
 
                                // Register RTE in JS:
-                       $this->TCEform->additionalJS_post[] = $this->registerRTEinJS($this->TCEform->RTEcounter, $table, $row['uid'], $field);
+                       $this->TCEform->additionalJS_post[] = $this->registerRTEinJS($this->TCEform->RTEcounter, $table, $row['uid'], $field, $textAreaId);
 
                                // Set the save option for the RTE:
-                       $this->TCEform->additionalJS_submit[] = $this->setSaveRTE($this->TCEform->RTEcounter, $this->TCEform->formName, htmlspecialchars($PA['itemFormElName']));
+                       $this->TCEform->additionalJS_submit[] = $this->setSaveRTE($this->TCEform->RTEcounter, $this->TCEform->formName, $textAreaId);
+                       $this->TCEform->additionalJS_delete[] = $this->setDeleteRTE($this->TCEform->RTEcounter, $this->TCEform->formName, $textAreaId);
 
                                // Draw the textarea
                        $visibility = 'hidden';
                        $item = $this->triggerField($PA['itemFormElName']).'
-                               <div id="pleasewait' . $this->TCEform->RTEcounter . '" class="pleasewait" style="display: none;" >' . $LANG->getLL('Please wait') . '</div>
-                               <div id="editorWrap' . $this->TCEform->RTEcounter . '" class="editorWrap" style="width:' . $editorWrapWidth . '; height:' . $editorWrapHeight . ';">
-                               <textarea id="RTEarea'.$this->TCEform->RTEcounter.'" name="'.htmlspecialchars($PA['itemFormElName']).'" style="'.t3lib_div::deHSCentities(htmlspecialchars($this->RTEdivStyle)).'">'.t3lib_div::formatForTextarea($value).'</textarea>
+                               <div id="pleasewait' . $textAreaId . '" class="pleasewait" style="display: block;" >' . $LANG->getLL('Please wait') . '</div>
+                               <div id="editorWrap' . $textAreaId . '" class="editorWrap" style="visibility: hidden; width:' . $editorWrapWidth . '; height:' . $editorWrapHeight . ';">
+                               <textarea id="RTEarea' . $textAreaId . '" name="'.htmlspecialchars($PA['itemFormElName']).'" style="'.t3lib_div::deHSCentities(htmlspecialchars($this->RTEdivStyle)).'">'.t3lib_div::formatForTextarea($value).'</textarea>
                                </div>' . ($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableDebugMode'] ? '<div id="HTMLAreaLog"></div>' : '') . '
                                ';
                }
@@ -763,33 +773,52 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
        function loadJSfiles($RTEcounter) {
                global $TYPO3_CONF_VARS;
                
+               $loadPluginCode = '
+                                               HTMLArea_plugins = new Array();';
+               foreach ($this->pluginEnabledCumulativeArray[$RTEcounter] as $pluginId) {
+                       $extensionKey = is_object($this->registeredPlugins[$pluginId]) ? $this->registeredPlugins[$pluginId]->getExtensionKey() : $this->ID;
+                       $loadPluginCode .= '
+                                               HTMLArea_plugins.push("' . $this->writeTemporaryFile('EXT:' . $extensionKey . '/htmlarea/plugins/' . $pluginId . '/' . strtolower(preg_replace('/([a-z])([A-Z])([a-z])/', "$1".'-'."$2"."$3", $pluginId)) . '.js', $pluginId) . '");';
+               }
+                       // Avoid re-initialization on AJax call when RTEarea object was already initialized
                $loadJavascriptCode = '
                <script type="text/javascript">
                /*<![CDATA[*/
-                       i=1;
-                       while (document.getElementById("pleasewait" + i)) {
-                               document.getElementById("pleasewait" + i).style.display = "block";
-                               document.getElementById("editorWrap" + i).style.visibility = "hidden";
-                               i++;
-                       };
-                       RTEarea = new Array();
-                       RTEarea[0] = new Object();
-                       RTEarea[0]["version"] = "' . $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['version'] . '";'
-                       . (($this->client['BROWSER'] == 'msie') ? ('
-                       RTEarea[0]["htmlarea-ie"] = "' . $this->writeTemporaryFile('EXT:' . $this->ID . '/htmlarea/htmlarea-ie.js', "htmlarea-ie") . '";')
-                       : ('
-                       RTEarea[0]["htmlarea-gecko"] = "' . $this->writeTemporaryFile('EXT:' . $this->ID . '/htmlarea/htmlarea-gecko.js', "htmlarea-gecko") . '";')) . '
-                       _editor_url = "' . $this->extHttpPath . 'htmlarea";
-                       _editor_lang = "' . $this->language . '";
-                       _editor_CSS = "' . $this->editorCSS . '";
-                       _editor_skin = "' . dirname($this->editorCSS) . '";
-                       _editor_edited_content_CSS = "' .  $this->editedContentCSS  . '";
-                       _typo3_host_url = "' . $this->hostURL . '";
-                       _editor_debug_mode = ' . ($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableDebugMode'] ? 'true' : 'false') . ';
-                       _editor_compressed_scripts = ' . ($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableCompressedScripts'] ? 'true' : 'false') . ';'
-                       . (($this->client['BROWSER'] == 'gecko') ? ('
-                       _editor_mozAllowClipboard_url = "' . ($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['mozAllowClipboardURL'] ? $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['mozAllowClipboardURL'] : '') . '";')
-                       : '') . '
+                       if (typeof(RTEarea) == "undefined") {
+                               RTEarea = new Object();
+                               RTEarea.init = function() {
+                                       if (typeof(HTMLArea) == "undefined") {
+                                               window.setTimeout("RTEarea.init();", 40);
+                                       } else {'
+                                               . $loadPluginCode . '
+                                               HTMLArea.init();
+                                       }
+                               };
+                               RTEarea.initEditor = function(editorNumber) {
+                                       if (typeof(HTMLArea) == "undefined") {
+                                               window.setTimeout("RTEarea.initEditor(\'" + editorNumber + "\');", 40);
+                                       } else {
+                                               HTMLArea.initEditor(editorNumber);
+                                       }
+                               };
+                               RTEarea[0] = new Object();
+                               RTEarea[0].version = "' . $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['version'] . '";'
+                               . (($this->client['BROWSER'] == 'msie') ? ('
+                               RTEarea[0]["htmlarea-ie"] = "' . $this->writeTemporaryFile('EXT:' . $this->ID . '/htmlarea/htmlarea-ie.js', "htmlarea-ie") . '";')
+                               : ('
+                               RTEarea[0]["htmlarea-gecko"] = "' . $this->writeTemporaryFile('EXT:' . $this->ID . '/htmlarea/htmlarea-gecko.js', "htmlarea-gecko") . '";')) . '
+                               _editor_url = "' . $this->extHttpPath . 'htmlarea";
+                               _editor_lang = "' . $this->language . '";
+                               _editor_CSS = "' . $this->editorCSS . '";
+                               _editor_skin = "' . dirname($this->editorCSS) . '";
+                               _editor_edited_content_CSS = "' .  $this->editedContentCSS  . '";
+                               _typo3_host_url = "' . $this->hostURL . '";
+                               _editor_debug_mode = ' . ($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableDebugMode'] ? 'true' : 'false') . ';
+                               _editor_compressed_scripts = ' . ($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableCompressedScripts'] ? 'true' : 'false') . ';'
+                               . (($this->client['BROWSER'] == 'gecko') ? ('
+                               _editor_mozAllowClipboard_url = "' . ($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['mozAllowClipboardURL'] ? $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['mozAllowClipboardURL'] : '') . '";')
+                               : '') . '
+                       }
                /*]]>*/
                </script>';
                $loadJavascriptCode .= '
@@ -808,18 +837,9 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
         */
         
        function loadJScode($RTEcounter) {
-               
-               $loadPluginCode = '';
-               foreach ($this->pluginEnabledCumulativeArray[$RTEcounter] as $pluginId) {
-                       $extensionKey = is_object($this->registeredPlugins[$pluginId]) ? $this->registeredPlugins[$pluginId]->getExtensionKey() : $this->ID;
-                       $loadPluginCode .= '
-                       HTMLArea.loadPlugin("' . $pluginId . '", true, "' . $this->writeTemporaryFile('EXT:' . $extensionKey . '/htmlarea/plugins/' . $pluginId . '/' . strtolower(preg_replace('/([a-z])([A-Z])([a-z])/', "$1".'-'."$2"."$3", $pluginId)) . '.js', $pluginId) . '");';
-               }
                return (!$this->is_FE() ? '' : '
-               ' . '/*<![CDATA[*/') . ($this->is_FE() ? '' : '
-                       RTEarea[0]["RTEtsConfigParams"] = "&RTEtsConfigParams=' . rawurlencode($this->RTEtsConfigParams()) . '";')
-                       . $loadPluginCode .  '
-                       HTMLArea.init();' . (!$this->is_FE() ? '' : '
+               ' . '/*<![CDATA[*/') . '
+                       RTEarea.init();' . (!$this->is_FE() ? '' : '
                /*]]>*/
                ');
        }
@@ -834,63 +854,74 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
         *
         * @return      string          the Javascript code for configuring the RTE
         */
-       function registerRTEinJS($RTEcounter, $table='', $uid='', $field='') {
+       function registerRTEinJS($RTEcounter, $table='', $uid='', $field='', $textAreaId = '') {
                global $TYPO3_CONF_VARS;
                
                $configureRTEInJavascriptString = (!$this->is_FE() ? '' : '
                        ' . '/*<![CDATA[*/') . '
-                       RTEarea['.$RTEcounter.'] = new Object();
-                       RTEarea['.$RTEcounter.'].RTEtsConfigParams = "&RTEtsConfigParams=' . rawurlencode($this->RTEtsConfigParams()) . '";
-                       RTEarea['.$RTEcounter.'].number = '.$RTEcounter.';
-                       RTEarea['.$RTEcounter.'].id = "RTEarea'.$RTEcounter.'";
-                       RTEarea['.$RTEcounter.'].enableWordClean = ' . (trim($this->thisConfig['enableWordClean'])?'true':'false') . ';
-                       RTEarea['.$RTEcounter.']["htmlRemoveComments"] = ' . (trim($this->thisConfig['removeComments'])?'true':'false') . ';
-                       RTEarea['.$RTEcounter.'].disableEnterParagraphs = ' . (trim($this->thisConfig['disableEnterParagraphs'])?'true':'false') . ';
-                       RTEarea['.$RTEcounter.'].disableObjectResizing = ' . (trim($this->thisConfig['disableObjectResizing'])?'true':'false') . ';
-                       RTEarea['.$RTEcounter.']["removeTrailingBR"] = ' . (trim($this->thisConfig['removeTrailingBR'])?'true':'false') . ';
-                       RTEarea['.$RTEcounter.']["useCSS"] = ' . (trim($this->thisConfig['useCSS'])?'true':'false') . ';
-                       RTEarea['.$RTEcounter.']["keepButtonGroupTogether"] = ' . (trim($this->thisConfig['keepButtonGroupTogether'])?'true':'false') . ';
-                       RTEarea['.$RTEcounter.']["disablePCexamples"] = ' . (trim($this->thisConfig['disablePCexamples'])?'true':'false') . ';
-                       RTEarea['.$RTEcounter.']["statusBar"] = ' . (trim($this->thisConfig['showStatusBar'])?'true':'false') . ';
-                       RTEarea['.$RTEcounter.']["showTagFreeClasses"] = ' . (trim($this->thisConfig['showTagFreeClasses'])?'true':'false') . ';
-                       RTEarea['.$RTEcounter.']["useHTTPS"] = ' . ((trim(stristr($this->siteURL, 'https')) || $this->thisConfig['forceHTTPS'])?'true':'false') . ';
-                       RTEarea['.$RTEcounter.']["enableMozillaExtension"] = ' . (($this->client['BROWSER'] == 'gecko' && $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableMozillaExtension'])?'true':'false') . ';
-                       RTEarea['.$RTEcounter.']["tceformsNested"] = ' . (is_object($this->TCEform) && method_exists($this->TCEform, 'getDynNestedStack') ? $this->TCEform->getDynNestedStack(true) : '[]') . ';';
+                       if (typeof(configureEditorInstance) == "undefined") {
+                               configureEditorInstance = new Object();
+                       }
+                       configureEditorInstance["' . $textAreaId . '"] = function() {
+                               if (typeof(RTEarea) == "undefined" || typeof(HTMLArea) == "undefined") {
+                                       window.setTimeout("configureEditorInstance[\'' . $textAreaId . '\']();", 40);
+                               } else {
+                       editornumber = "' . $textAreaId . '";
+                       RTEarea[editornumber] = new Object();
+                       RTEarea[editornumber].RTEtsConfigParams = "&RTEtsConfigParams=' . rawurlencode($this->RTEtsConfigParams()) . '";'
+                       . ($RTEcounter ? 'RTEarea[0].RTEtsConfigParams = "&RTEtsConfigParams=' . rawurlencode($this->RTEtsConfigParams()) . '";' : '') . '
+                       RTEarea[editornumber].number = editornumber;
+                       RTEarea[editornumber].deleted = false;
+                       RTEarea[editornumber].textAreaId = "' . $textAreaId . '";
+                       RTEarea[editornumber].id = "RTEarea" + editornumber;
+                       RTEarea[editornumber].enableWordClean = ' . (trim($this->thisConfig['enableWordClean'])?'true':'false') . ';
+                       RTEarea[editornumber]["htmlRemoveComments"] = ' . (trim($this->thisConfig['removeComments'])?'true':'false') . ';
+                       RTEarea[editornumber].disableEnterParagraphs = ' . (trim($this->thisConfig['disableEnterParagraphs'])?'true':'false') . ';
+                       RTEarea[editornumber].disableObjectResizing = ' . (trim($this->thisConfig['disableObjectResizing'])?'true':'false') . ';
+                       RTEarea[editornumber]["removeTrailingBR"] = ' . (trim($this->thisConfig['removeTrailingBR'])?'true':'false') . ';
+                       RTEarea[editornumber]["useCSS"] = ' . (trim($this->thisConfig['useCSS'])?'true':'false') . ';
+                       RTEarea[editornumber]["keepButtonGroupTogether"] = ' . (trim($this->thisConfig['keepButtonGroupTogether'])?'true':'false') . ';
+                       RTEarea[editornumber]["disablePCexamples"] = ' . (trim($this->thisConfig['disablePCexamples'])?'true':'false') . ';
+                       RTEarea[editornumber]["statusBar"] = ' . (trim($this->thisConfig['showStatusBar'])?'true':'false') . ';
+                       RTEarea[editornumber]["showTagFreeClasses"] = ' . (trim($this->thisConfig['showTagFreeClasses'])?'true':'false') . ';
+                       RTEarea[editornumber]["useHTTPS"] = ' . ((trim(stristr($this->siteURL, 'https')) || $this->thisConfig['forceHTTPS'])?'true':'false') . ';
+                       RTEarea[editornumber]["enableMozillaExtension"] = ' . (($this->client['BROWSER'] == 'gecko' && $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableMozillaExtension'])?'true':'false') . ';
+                       RTEarea[editornumber].tceformsNested = ' . (is_object($this->TCEform) && method_exists($this->TCEform, 'getDynNestedStack') ? $this->TCEform->getDynNestedStack(true) : '[]') . ';';
 
                        // The following properties apply only to the backend
                if (!$this->is_FE()) {
                        $configureRTEInJavascriptString .= '
-                       RTEarea['.$RTEcounter.'].sys_language_content = "' . $this->contentLanguageUid . '";
-                       RTEarea['.$RTEcounter.'].typo3ContentLanguage = "' . $this->contentTypo3Language . '";
-                       RTEarea['.$RTEcounter.'].typo3ContentCharset = "' . $this->contentCharset . '";
-                       RTEarea['.$RTEcounter.'].userUid = "' . $this->userUid . '";';
+                       RTEarea[editornumber].sys_language_content = "' . $this->contentLanguageUid . '";
+                       RTEarea[editornumber].typo3ContentLanguage = "' . $this->contentTypo3Language . '";
+                       RTEarea[editornumber].typo3ContentCharset = "' . $this->contentCharset . '";
+                       RTEarea[editornumber].userUid = "' . $this->userUid . '";';
                }
                
                        // Setting the plugin flags
                $configureRTEInJavascriptString .= '
-                       RTEarea['.$RTEcounter.'].plugin = new Object();
-                       RTEarea['.$RTEcounter.'].pathToPluginDirectory = new Object();';
+                       RTEarea[editornumber].plugin = new Object();
+                       RTEarea[editornumber].pathToPluginDirectory = new Object();';
                foreach ($this->pluginEnabledArray as $pluginId) {
                        $configureRTEInJavascriptString .= '
-                       RTEarea['.$RTEcounter.'].plugin.'.$pluginId.' = true;';
+                       RTEarea[editornumber].plugin.'.$pluginId.' = true;';
                        if (is_object($this->registeredPlugins[$pluginId])) {
                                $pathToPluginDirectory = $this->registeredPlugins[$pluginId]->getPathToPluginDirectory();
                                if ($pathToPluginDirectory) {
                                        $configureRTEInJavascriptString .= '
-                       RTEarea['.$RTEcounter.'].pathToPluginDirectory.'.$pluginId.' = "' . $pathToPluginDirectory . '";';
+                       RTEarea[editornumber].pathToPluginDirectory.'.$pluginId.' = "' . $pathToPluginDirectory . '";';
                                }
                        }
                }
                
                        // Setting the buttons configuration
                $configureRTEInJavascriptString .= '
-                       RTEarea['.$RTEcounter.'].buttons = new Object();';
+                       RTEarea[editornumber].buttons = new Object();';
                if (is_array($this->thisConfig['buttons.'])) {
                        foreach ($this->thisConfig['buttons.'] as $buttonIndex => $conf) {
                                $button = substr($buttonIndex, 0, -1);
                                if (in_array($button,$this->toolbar)) {
                                        $configureRTEInJavascriptString .= '
-                       RTEarea['.$RTEcounter.'].buttons.'.$button.' = ' . $this->buildNestedJSArray($conf) . ';';
+                       RTEarea[editornumber].buttons.'.$button.' = ' . $this->buildNestedJSArray($conf) . ';';
                                }
                        }
                }
@@ -898,24 +929,24 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                        // Setting the list of tags to be removed if specified in the RTE config
                if (trim($this->thisConfig['removeTags']))  {
                        $configureRTEInJavascriptString .= '
-                       RTEarea['.$RTEcounter.']["htmlRemoveTags"] = /^(' . implode('|', t3lib_div::trimExplode(',', $this->thisConfig['removeTags'], 1)) . ')$/i;';
+                       RTEarea[editornumber]["htmlRemoveTags"] = /^(' . implode('|', t3lib_div::trimExplode(',', $this->thisConfig['removeTags'], 1)) . ')$/i;';
                }
                
                        // Setting the list of tags to be removed with their contents if specified in the RTE config
                if (trim($this->thisConfig['removeTagsAndContents']))  {
                        $configureRTEInJavascriptString .= '
-                       RTEarea['.$RTEcounter.']["htmlRemoveTagsAndContents"] = /^(' . implode('|', t3lib_div::trimExplode(',', $this->thisConfig['removeTagsAndContents'], 1)) . ')$/i;';
+                       RTEarea[editornumber]["htmlRemoveTagsAndContents"] = /^(' . implode('|', t3lib_div::trimExplode(',', $this->thisConfig['removeTagsAndContents'], 1)) . ')$/i;';
                }
                
                        // Process default style configuration
                $configureRTEInJavascriptString .= '
-                       RTEarea['.$RTEcounter.'].defaultPageStyle = "' . $this->hostURL . $this->writeTemporaryFile('', 'defaultPageStyle', 'css', $this->buildStyleSheet()) . '";';
-                       
+                       RTEarea[editornumber].defaultPageStyle = "' . $this->hostURL . $this->writeTemporaryFile('', 'defaultPageStyle', 'css', $this->buildStyleSheet()) . '";';
+
                        // Setting the pageStyle
                $filename = trim($this->thisConfig['contentCSS']) ? trim($this->thisConfig['contentCSS']) : 'EXT:' . $this->ID . '/res/contentcss/default.css';
                $configureRTEInJavascriptString .= '
-                       RTEarea['.$RTEcounter.'].pageStyle = "' . $this->getFullFileName($filename) .'";';
-               
+                       RTEarea[editornumber].pageStyle = "' . $this->getFullFileName($filename) .'";';
+
                        // Process classes configuration
                $classesConfigurationRequired = false;
                foreach ($this->registeredPlugins as $pluginId => $plugin) {
@@ -930,13 +961,16 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                        // Add Javascript configuration for registered plugins
                foreach ($this->registeredPlugins as $pluginId => $plugin) {
                        if ($this->isPluginEnabled($pluginId)) {
-                               $configureRTEInJavascriptString .= $plugin->buildJavascriptConfiguration($RTEcounter);
+                               $configureRTEInJavascriptString .= $plugin->buildJavascriptConfiguration('editornumber');
                        }
                }
-               
+                       // Avoid premature reference to HTMLArea when being initially loaded by IRRE Ajax call
                $configureRTEInJavascriptString .= '
-                       RTEarea['.$RTEcounter.'].toolbar = '.$this->getJSToolbarArray().';
-                       HTMLArea.initEditor('.$RTEcounter.');' . (!$this->is_FE() ? '' : '
+                       RTEarea[editornumber].toolbar = '.$this->getJSToolbarArray().';
+                       RTEarea.initEditor(editornumber);
+                               }
+                       };
+                       configureEditorInstance["' . $textAreaId . '"]();'. (!$this->is_FE() ? '' : '
                        /*]]>*/');
                return $configureRTEInJavascriptString;
        }
@@ -1013,16 +1047,16 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                $classesTagConvert = array( 'classesCharacter' => 'span', 'classesParagraph' => 'div', 'classesImage' => 'img', 'classesTable' => 'table', 'classesLinks' => 'a', 'classesTD' => 'td');
                $classesTagArray = t3lib_div::trimExplode(',' , $classesTagList);
                $configureRTEInJavascriptString = '
-                       RTEarea['.$RTEcounter.']["classesTag"] = new Object();';
+                       RTEarea[editornumber]["classesTag"] = new Object();';
                foreach ($classesTagArray as $classesTagName) {
                        $HTMLAreaJSClasses = ($this->thisConfig[$classesTagName])?('"' . $this->cleanList($this->thisConfig[$classesTagName]) . '";'):'null;';
                        $configureRTEInJavascriptString .= '
-                       RTEarea['.$RTEcounter.']["classesTag"]["'. $classesTagConvert[$classesTagName] .'"] = '. $HTMLAreaJSClasses;
+                       RTEarea[editornumber]["classesTag"]["'. $classesTagConvert[$classesTagName] .'"] = '. $HTMLAreaJSClasses;
                }
                
                        // Include JS arrays of configured classes
                $configureRTEInJavascriptString .= '
-                       RTEarea['.$RTEcounter.']["classesUrl"] = "' . $this->hostURL . $this->writeTemporaryFile('', 'classes_'.$LANG->lang, 'js', $this->buildJSClassesArray()) . '";';
+                       RTEarea[editornumber]["classesUrl"] = "' . $this->hostURL . $this->writeTemporaryFile('', 'classes_'.$LANG->lang, 'js', $this->buildJSClassesArray()) . '";';
                
                return $configureRTEInJavascriptString;
        }
@@ -1418,17 +1452,23 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
         * @return      string          Javascript code
         */
        function setSaveRTE($RTEcounter, $formName, $textareaId) {
-               return '
-               editornumber = '.$RTEcounter.';
-               if (RTEarea[editornumber]) {
-                       document.'.$formName.'["'.$textareaId.'"].value = RTEarea[editornumber]["editor"].getHTML();
-               }
-               else {
-                       OK=0;
-               }
-               ';
+               return 'if (RTEarea[\'' . $textareaId . '\']) { document.' . $formName . '[\'' . $textareaId . '\'].value = RTEarea[\'' . $textareaId . '\'][\'editor\'].getHTML(); } else { OK = 0; };';
        }
-       
+
+       /**
+        * Return the Javascript code for copying the HTML code from the editor into the hidden input field.
+        * This is for submit function of the form.
+        *
+        * @param       integer         $RTEcounter: The index number of the current RTE editing area within the form.
+        * @param       string          $formName: the name of the form
+        * @param       string          $textareaId: the id of the textarea
+        *
+        * @return      string          Javascript code
+        */
+       function setDeleteRTE($RTEcounter, $formName, $textareaId) {
+               return 'if (RTEarea[\'' . $textareaId . '\']) { RTEarea[\'' . $textareaId . '\'].deleted = true;}';
+       }
+
        /**
         * Return true if we are in the FE, but not in the FE editing feature of BE.
         *
index 7411e3b..9ac2676 100644 (file)
@@ -3,7 +3,7 @@
 *
 *  (c) 2002-2004, interactivetools.com, inc.
 *  (c) 2003-2004 dynarch.com
-*  (c) 2004-2008 Stanislas Rolland <stanislas.rolland(arobas)fructifor.ca>
+*  (c) 2004-2008 Stanislas Rolland <typo3(arobas)sjbr.ca>
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -66,7 +66,7 @@ HTMLArea.prototype._initEditMode = function () {
                        if (HTMLArea.is_wamcom) {
                                this._doc.open();
                                this._doc.close();
-                               this._initIframeTimer = window.setTimeout("HTMLArea.initIframe(" + this._editorNumber + ");", 500);
+                               this._initIframeTimer = window.setTimeout("HTMLArea.initIframe(\'" + this._editorNumber + "\');", 500);
                                return false;
                        }
                }
index 6843dcf..80afcc1 100644 (file)
 /***************************************************
  *  EDITOR INITIALIZATION AND CONFIGURATION
  ***************************************************/
-
-/*
- * Set some basic paths
- */
-if (typeof(_editor_url) == "string") {
-               // Leave exactly one backslash at the end of _editor_url
-       _editor_url = _editor_url.replace(/\x2f*$/, '/');
-} else {
-       alert("WARNING: _editor_url is not set!");
-       var _editor_url = '';
-}
-if (typeof(_editor_skin) == "string") _editor_skin = _editor_skin.replace(/\x2f*$/, '/');
-       else var _editor_skin = _editor_url + "skins/default/";
-if (typeof(_editor_CSS) != "string") var _editor_CSS = _editor_url + "skins/default/htmlarea.css";
-if (typeof(_editor_edited_content_CSS) != "string") var _editor_edited_content_CSS = _editor_skin + "htmlarea-edited-content.css";
-if (typeof(_editor_lang) == "string") _editor_lang = _editor_lang ? _editor_lang.toLowerCase() : "en";
+       // Avoid re-starting on Ajax call
+if (typeof(HTMLArea) != "function") {
 
 /*
  * HTMLArea object constructor.
  */
-var HTMLArea = function(textarea, config) {
+HTMLArea = function(textarea, config) {
        if (HTMLArea.checkSupportedBrowser()) {
                if (typeof(config) == "undefined") this.config = new HTMLArea.Config();
                        else this.config = config;
@@ -74,8 +60,6 @@ var HTMLArea = function(textarea, config) {
        }
 };
 
-HTMLArea.editorCSS = _editor_CSS;
-
 /*
  * Browser identification
  */
@@ -91,9 +75,6 @@ HTMLArea.is_wamcom = (HTMLArea.agt.indexOf("wamcom") != -1) || (HTMLArea.is_geck
 /*
  * A log for troubleshooting
  */
-HTMLArea._debugMode = false;
-if (typeof(_editor_debug_mode) != "undefined") HTMLArea._debugMode = _editor_debug_mode;
-
 HTMLArea._appendToLog = function(str){
        if(HTMLArea._debugMode) {
                var log = document.getElementById("HTMLAreaLog");
@@ -105,38 +86,6 @@ HTMLArea._appendToLog = function(str){
 };
 
 /*
- * Using compressed scripts
- */
-HTMLArea._compressedScripts = false;
-if (typeof(_editor_compressed_scripts) != "undefined") HTMLArea._compressedScripts = _editor_compressed_scripts;
-
-/*
- * Localization of core script
- */
-HTMLArea.I18N = HTMLArea_langArray;
-
-/*
- * Build array of scripts to be loaded
- */
-HTMLArea.is_loaded = false;
-HTMLArea.onload = function(){
-       HTMLArea.is_loaded = true;
-       HTMLArea._appendToLog("All scripts successfully loaded.");
-};
-HTMLArea.loadTimer;
-HTMLArea._scripts = [];
-HTMLArea._scriptLoaded = [];
-HTMLArea._request = [];
-HTMLArea.loadScript = function(url, plugin) {
-       if (plugin) url = _editor_url + "/plugins/" + plugin + '/' + url;
-       if (HTMLArea.is_opera) url = _typo3_host_url + url;
-       if (HTMLArea._compressedScripts && url.indexOf("compressed") == -1) url = url.replace(/\.js$/gi, "_compressed.js");
-       HTMLArea._scripts.push(url);
-};
-if(HTMLArea.is_gecko) HTMLArea.loadScript(RTEarea[0]["htmlarea-gecko"] ? RTEarea[0]["htmlarea-gecko"] : _editor_url + "htmlarea-gecko.js");
-if(HTMLArea.is_ie) HTMLArea.loadScript(RTEarea[0]["htmlarea-ie"] ? RTEarea[0]["htmlarea-ie"] : _editor_url + "htmlarea-ie.js");
-
-/*
  * Get a script using asynchronous XMLHttpRequest
  */
 HTMLArea.MSXML_XMLHTTP_PROGIDS = new Array("Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "Msxml2.XMLHTTP.3.0", "Msxml2.XMLHTTP", "Microsoft.XMLHTTP");
@@ -173,6 +122,7 @@ HTMLArea._getScript = function (i,asynchronous,url) {
                }
        var request = HTMLArea._request[i];
        if (request) {
+               HTMLArea._appendToLog("[HTMLArea::getScript]: Requesting script " + url);
                request.open("GET", url, asynchronous);
                if (asynchronous) request.onreadystatechange = HTMLArea.XMLHTTPResponseHandler(i);
                if (window.XMLHttpRequest) request.send(null);
@@ -213,28 +163,70 @@ HTMLArea.checkInitialLoad = function() {
                return false;
        }
 };
-
 /*
- * Get all the scripts
+ * Build stack of scripts to be loaded
+ */
+HTMLArea.loadScript = function(url, plugin) {
+       if (plugin) url = _editor_url + "/plugins/" + plugin + '/' + url;
+       if (HTMLArea.is_opera) url = _typo3_host_url + url;
+       if (HTMLArea._compressedScripts && url.indexOf("compressed") == -1) url = url.replace(/\.js$/gi, "_compressed.js");
+       HTMLArea._scripts.push(url);
+};
+/*
+ * Initial load
  */
 HTMLArea.init = function() {
-       HTMLArea._eventCache = HTMLArea._eventCacheConstructor();
-       if (window.XMLHttpRequest || window.ActiveXObject) {
-               try {
-                       var success = true;
-                       for (var i = 0, n = HTMLArea._scripts.length; i < n && success; i++) {
-                               success = success && HTMLArea._getScript(i);
+       if (typeof(_editor_url) != "string") {
+               window.setTimeout("HTMLArea.init();", 50);
+       } else {
+                       // Set some basic paths
+                       // Leave exactly one backslash at the end of _editor_url
+               _editor_url = _editor_url.replace(/\x2f*$/, '/');
+               if (typeof(_editor_skin) == "string") _editor_skin = _editor_skin.replace(/\x2f*$/, '/');
+                       else _editor_skin = _editor_url + "skins/default/";
+               if (typeof(_editor_CSS) != "string") _editor_CSS = _editor_url + "skins/default/htmlarea.css";
+               if (typeof(_editor_edited_content_CSS) != "string") _editor_edited_content_CSS = _editor_skin + "htmlarea-edited-content.css";
+               if (typeof(_editor_lang) == "string") _editor_lang = _editor_lang ? _editor_lang.toLowerCase() : "en";
+               HTMLArea.editorCSS = _editor_CSS;
+                       // Initialize event cache
+               HTMLArea._eventCache = HTMLArea._eventCacheConstructor();
+                       // Set troubleshooting mode
+               HTMLArea._debugMode = false;
+               if (typeof(_editor_debug_mode) != "undefined") HTMLArea._debugMode = _editor_debug_mode;
+                       // Using compressed scripts
+               HTMLArea._compressedScripts = false;
+               if (typeof(_editor_compressed_scripts) != "undefined") HTMLArea._compressedScripts = _editor_compressed_scripts;
+                       // Localization of core script
+               HTMLArea.I18N = HTMLArea_langArray;
+                       // Build array of scripts to be loaded
+               HTMLArea.is_loaded = false;
+               HTMLArea.loadTimer;
+               HTMLArea._scripts = [];
+               HTMLArea._scriptLoaded = [];
+               HTMLArea._request = [];
+               if (HTMLArea.is_gecko) HTMLArea.loadScript(RTEarea[0]["htmlarea-gecko"] ? RTEarea[0]["htmlarea-gecko"] : _editor_url + "htmlarea-gecko.js");
+               if (HTMLArea.is_ie) HTMLArea.loadScript(RTEarea[0]["htmlarea-ie"] ? RTEarea[0]["htmlarea-ie"] : _editor_url + "htmlarea-ie.js");
+               for (var i = 0, n = HTMLArea_plugins.length; i < n; i++) {
+                       HTMLArea.loadScript(HTMLArea_plugins[i]);
+               }
+                       // Get all the scripts
+               if (window.XMLHttpRequest || window.ActiveXObject) {
+                       try {
+                               var success = true;
+                               for (var i = 0, n = HTMLArea._scripts.length; i < n && success; i++) {
+                                       success = success && HTMLArea._getScript(i);
+                               }
+                       } catch (e) {
+                               HTMLArea._appendToLog("ERROR [HTMLArea::init]: Unable to use XMLHttpRequest: "+ e);
+                       }
+                       if (success) {
+                               HTMLArea.checkInitialLoad();
+                       } else {
+                               if (HTMLArea.is_ie) window.setTimeout('alert(HTMLArea.I18N.msg["ActiveX-required"]);', 200);
                        }
-               } catch (e) {
-                       HTMLArea._appendToLog("ERROR [HTMLArea::init]: Unable to use XMLHttpRequest: "+ e);
-               }
-               if (success) {
-                       HTMLArea.checkInitialLoad();
                } else {
-                       if (HTMLArea.is_ie) window.setTimeout('if (window.document.getElementById("pleasewait1")) { window.document.getElementById("pleasewait1").innerHTML = HTMLArea.I18N.msg["ActiveX-required"]; } else { alert(HTMLArea.I18N.msg["ActiveX-required"]); };', 200);
+                       if (HTMLArea.is_ie) alert(HTMLArea.I18N.msg["ActiveX-required"]);
                }
-       } else {
-               if (HTMLArea.is_ie) alert(HTMLArea.I18N.msg["ActiveX-required"]);
        }
 };
 
@@ -253,7 +245,6 @@ HTMLArea.RE_url      = /(https?:\/\/)?(([a-z0-9_]+:[a-z0-9_]+@)?[a-z0-9_-]{2,}(\
 /*
  * Editor configuration object constructor
  */
-
 HTMLArea.Config = function () {
        this.width = "auto";
        this.height = "auto";
@@ -987,15 +978,15 @@ HTMLArea.initIframe = function(editorNumber) {
 HTMLArea.prototype.initIframe = function() {
        if (this._initIframeTimer) window.clearTimeout(this._initIframeTimer);
        if (!this._iframe || (!this._iframe.contentWindow && !this._iframe.contentDocument)) {
-               this._initIframeTimer = window.setTimeout("HTMLArea.initIframe(" + this._editorNumber + ");", 50);
+               this._initIframeTimer = window.setTimeout("HTMLArea.initIframe(\'" + this._editorNumber + "\');", 50);
                return false;
        } else if (this._iframe.contentWindow && !HTMLArea.is_safari) {
                if (!this._iframe.contentWindow.document || !this._iframe.contentWindow.document.documentElement) {
-                       this._initIframeTimer = window.setTimeout("HTMLArea.initIframe(" + this._editorNumber + ");", 50);
+                       this._initIframeTimer = window.setTimeout("HTMLArea.initIframe(\'" + this._editorNumber + "\');", 50);
                        return false;
                }
        } else if (!this._iframe.contentDocument.documentElement || !this._iframe.contentDocument.body) {
-               this._initIframeTimer = window.setTimeout("HTMLArea.initIframe(" + this._editorNumber + ");", 50);
+               this._initIframeTimer = window.setTimeout("HTMLArea.initIframe(\'" + this._editorNumber + "\');", 50);
                return false;
        }
        var doc = this._iframe.contentWindow ? this._iframe.contentWindow.document : this._iframe.contentDocument;
@@ -1078,7 +1069,7 @@ HTMLArea.prototype.stylesLoaded = function() {
        }
        if (!stylesAreLoaded && !HTMLArea.is_wamcom) {
                HTMLArea._appendToLog("[HTMLArea::initIframe]: Failed attempt at loading stylesheets: " + errorText + " Retrying...");
-               this._stylesLoadedTimer = window.setTimeout("HTMLArea.stylesLoaded(" + this._editorNumber + ");", 100);
+               this._stylesLoadedTimer = window.setTimeout("HTMLArea.stylesLoaded(\'" + this._editorNumber + "\');", 100);
                return false;
        }
        HTMLArea._appendToLog("[HTMLArea::initIframe]: Stylesheets successfully loaded.");
@@ -1122,7 +1113,7 @@ HTMLArea.prototype.stylesLoaded = function() {
        if (HTMLArea.is_ie) doc.documentElement._editorNo = this._editorNumber;
 
                // Start undo snapshots
-       if (this._customUndo) this._timerUndo = window.setInterval("HTMLArea.undoTakeSnapshot(" + this._editorNumber + ");", this.config.undoTimeout);
+       if (this._customUndo) this._timerUndo = window.setInterval("HTMLArea.undoTakeSnapshot(\'" + this._editorNumber + "\');", this.config.undoTimeout);
 
                // intercept events for updating the toolbar & for keyboard handlers
        HTMLArea._addEvents((HTMLArea.is_ie ? doc.body : doc), ["keydown","keypress","mousedown","mouseup","drag"], HTMLArea._editorEvent, true);
@@ -1133,10 +1124,7 @@ HTMLArea.prototype.stylesLoaded = function() {
                HTMLArea._addEvent((this._iframe.contentWindow ? this._iframe.contentWindow : this._iframe.contentDocument), "unload", HTMLArea.removeEditorEvents);
        }
 
-               // set enableWordClean and intercept paste, dragdrop and drop events for wordClean
-       //if (this.config.enableWordClean) HTMLArea._addEvents((HTMLArea.is_ie ? doc.body : doc), ["paste","dragdrop","drop"], HTMLArea.wordClean, true);
-
-       window.setTimeout("HTMLArea.generatePlugins(" + this._editorNumber + ");", 100);
+       window.setTimeout("HTMLArea.generatePlugins(\'" + this._editorNumber + "\');", 100);
 };
 
 HTMLArea.generatePlugins = function(editorNumber) {
@@ -1193,17 +1181,19 @@ HTMLArea.removeEditorEvents = function(ev) {
        if (HTMLArea._eventCache) {
                HTMLArea._eventCache.flush();
        }
-       for (var editorNumber = RTEarea.length; --editorNumber > 0 ;) {
-               var editor = RTEarea[editorNumber].editor;
-               if (editor) {
-                       RTEarea[editorNumber].editor = null;
-                               // save the HTML content into the original textarea for submit, back/forward, etc.
-                       editor._textArea.value = editor.getHTML();
-                               // release undo/redo snapshots
-                       window.clearInterval(editor._timerUndo);
-                       editor._undoQueue = null;
-                               // do final cleanup
-                       HTMLArea.cleanup(editor);
+       for (var editorNumber in RTEarea) {
+               if (RTEarea.hasOwnProperty(editorNumber)) {
+                       var editor = RTEarea[editorNumber].editor;
+                       if (editor) {
+                               RTEarea[editorNumber].editor = null;
+                                       // save the HTML content into the original textarea for submit, back/forward, etc.
+                               editor._textArea.value = editor.getHTML();
+                                       // release undo/redo snapshots
+                               window.clearInterval(editor._timerUndo);
+                               editor._undoQueue = null;
+                                       // do final cleanup
+                               HTMLArea.cleanup(editor);
+                       }
                }
        }
 };
@@ -1263,7 +1253,10 @@ HTMLArea.cleanup = function (editor) {
                        var obj = editor._toolbarObjects[txt];
                        obj.state = null;
                        obj.cmd = null;
-                       document.getElementById(obj.elementId)._obj = null;
+                       var element = document.getElementById(obj.elementId);
+                       if (element) {
+                               element._obj = null;
+                       }
                        editor._toolbarObjects[txt] = null;
                }
        }
@@ -2085,7 +2078,7 @@ HTMLArea._editorEvent = function(ev) {
                                                }
                                                        // update the toolbar state after some time
                                                if (editor._timerToolbar) window.clearTimeout(editor._timerToolbar);
-                                               editor._timerToolbar = window.setTimeout("HTMLArea.updateToolbar(" + editor._editorNumber + ");", 100);
+                                               editor._timerToolbar = window.setTimeout("HTMLArea.updateToolbar(\'" + editor._editorNumber + "\');", 100);
                                                return false;
                                        }
                                        break;
@@ -2096,7 +2089,7 @@ HTMLArea._editorEvent = function(ev) {
                                        }
                                                // update the toolbar state after some time
                                        if (editor._timerToolbar) window.clearTimeout(editor._timerToolbar);
-                                       editor._timerToolbar = window.setTimeout("HTMLArea.updateToolbar(" + editor._editorNumber + ");", 50);
+                                       editor._timerToolbar = window.setTimeout("HTMLArea.updateToolbar(\'" + editor._editorNumber + "\');", 50);
                                        break;
                                case 9: // KEY horizontal tab
                                        var newkey = (ev.shiftKey ? "SHIFT-" : "") + "TAB";
@@ -2113,7 +2106,7 @@ HTMLArea._editorEvent = function(ev) {
                                case 40: // DOWN arrow key
                                        if (HTMLArea.is_ie) {
                                                if (editor._timerToolbar) window.clearTimeout(editor._timerToolbar);
-                                               editor._timerToolbar = window.setTimeout("HTMLArea.updateToolbar(" + editor._editorNumber + ");", 10);
+                                               editor._timerToolbar = window.setTimeout("HTMLArea.updateToolbar(\'" + editor._editorNumber + "\');", 10);
                                                return true;
                                        }
                        }
@@ -2122,7 +2115,7 @@ HTMLArea._editorEvent = function(ev) {
                        // mouse event
                if (editor._timerToolbar) window.clearTimeout(editor._timerToolbar);
                if (ev.type == "mouseup") editor.updateToolbar();
-                       else editor._timerToolbar = window.setTimeout("HTMLArea.updateToolbar(" + editor._editorNumber + ");", 50);
+                       else editor._timerToolbar = window.setTimeout("HTMLArea.updateToolbar(\'" + editor._editorNumber + "\');", 50);
        }
 };
 
@@ -2666,7 +2659,7 @@ var setRTEsizeByJS = function(divId, height, width) {
  */
 var lorem_ipsum = function(element,text) {
        if (element.tagName.toLowerCase() == "textarea" && element.id && element.id.substr(0,7) == "RTEarea") {
-               var editor = RTEarea[element.id.substr(7,8)]["editor"];
+               var editor = RTEarea[element.id.substr(7, element.id.length)]["editor"];
                editor.insertHTML(text);
                editor.updateToolbar();
        }
@@ -2675,7 +2668,7 @@ var lorem_ipsum = function(element,text) {
 /*
  * Initialize the editor, configure the toolbar, setup the plugins, etc.
  */
-HTMLArea.initTimer = [];
+HTMLArea.initTimer = new Object();
 
 HTMLArea.onGenerateHandler = function(editorNumber) {
        return (function() {
@@ -2691,9 +2684,10 @@ HTMLArea.initEditor = function(editorNumber) {
                document.getElementById('editorWrap' + editorNumber).style.visibility = 'hidden';
                if(HTMLArea.initTimer[editorNumber]) window.clearTimeout(HTMLArea.initTimer[editorNumber]);
                if(!HTMLArea.is_loaded) {
-                       HTMLArea.initTimer[editorNumber] = window.setTimeout( "HTMLArea.initEditor(" + editorNumber + ");", 150);
+                       HTMLArea.initTimer[editorNumber] = window.setTimeout("HTMLArea.initEditor(\'" + editorNumber + "\');", 150);
                } else {
                        var RTE = RTEarea[editorNumber];
+                       HTMLArea._appendToLog("[HTMLArea::initEditor]: Initializing editor with editor Id: " + editorNumber + ".");
 
                                // Get the configuration properties
                        var config = new HTMLArea.Config();
@@ -3836,4 +3830,5 @@ HTMLArea.Dialog = HTMLArea.Base.extend({
                }
        }
 });
+};
 
index 7912132..76af13f 100644 (file)
@@ -133,7 +133,7 @@ TYPO3HtmlParser.wordCleanHandler = function (ev) {
        if (typeof(HTMLArea.Dialog) != "undefined" && HTMLArea.Dialog.TYPO3Image) {
                HTMLArea.Dialog.TYPO3Image.close();
        } else {
-               window.setTimeout("TYPO3HtmlParser.cleanLater(" + editor._editorNumber + ");", 250);
+               window.setTimeout("TYPO3HtmlParser.cleanLater(\'" + editor._editorNumber + "\');", 250);
        }
 };
 
index 2207eb2..400b647 100644 (file)
@@ -239,8 +239,10 @@ class tx_rtehtmlarea_pi2 extends tx_rtehtmlarea_base {
                        // Loading RTE skin style sheets
                $GLOBALS['TSFE']->additionalHeaderData['rtehtmlarea-skin'] = $this->getSkin();
                        // Loading JavaScript files and code
-               $this->TCEform->additionalJS_initial = $this->loadJSfiles($this->TCEform->RTEcounter);
-               $this->TCEform->additionalJS_pre['rtehtmlarea-loadJScode'] = $this->loadJScode($this->TCEform->RTEcounter);
+               if ($this->TCEform->RTEcounter == 1) {
+                       $this->TCEform->additionalJS_initial = $this->loadJSfiles($this->TCEform->RTEcounter);
+                       $this->TCEform->additionalJS_pre['rtehtmlarea-loadJScode'] = $this->loadJScode($this->TCEform->RTEcounter);
+               }
 
                /* =======================================
                 * DRAW THE EDITOR
@@ -258,19 +260,19 @@ class tx_rtehtmlarea_pi2 extends tx_rtehtmlarea_base {
                
                        // Register RTE windows:
                $this->TCEform->RTEwindows[] = $PA['itemFormElName'];
-               
+               $textAreaId = htmlspecialchars($PA['itemFormElName']);
+
                        // Register RTE in JS:
-               $this->TCEform->additionalJS_post[] = $this->registerRTEinJS($this->TCEform->RTEcounter);
-               
+               $this->TCEform->additionalJS_post[] = $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, htmlspecialchars($PA['itemFormElName']));
-               
+               $this->TCEform->additionalJS_submit[] = $this->setSaveRTE($this->TCEform->RTEcounter, $this->TCEform->formName, $textAreaId);
+
                        // draw the textarea
-               $visibility = 'hidden';
                $item = $this->triggerField($PA['itemFormElName']).'
-                       <div id="pleasewait' . $this->TCEform->RTEcounter . '" class="pleasewait" style="display: none;" >' . $TSFE->csConvObj->conv($TSFE->getLLL('Please wait',$this->LOCAL_LANG), $this->charset, $TSFE->renderCharset) . '</div>
-                       <div id="editorWrap' . $this->TCEform->RTEcounter . '" class="editorWrap" style="'. htmlspecialchars($this->RTEWrapStyle). '">
-                       <textarea id="RTEarea'.$this->TCEform->RTEcounter.'" name="'.htmlspecialchars($PA['itemFormElName']).'" style="'.htmlspecialchars($this->RTEdivStyle).'">'.t3lib_div::formatForTextarea($value).'</textarea>
+                       <div id="pleasewait' . $textAreaId . '" class="pleasewait" style="display: block;" >' . $TSFE->csConvObj->conv($TSFE->getLLL('Please wait',$this->LOCAL_LANG), $this->charset, $TSFE->renderCharset) . '</div>
+                       <div id="editorWrap' . $textAreaId . '" class="editorWrap" style="visibility: hidden; '. htmlspecialchars($this->RTEWrapStyle). '">
+                       <textarea id="RTEarea' . $textAreaId . '" name="'.htmlspecialchars($PA['itemFormElName']).'" style="'.htmlspecialchars($this->RTEdivStyle).'">'.t3lib_div::formatForTextarea($value).'</textarea>
                        </div>' . ($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableDebugMode'] ? '<div id="HTMLAreaLog"></div>' : '') . '
                        ';
                return $item;
@@ -282,24 +284,22 @@ class tx_rtehtmlarea_pi2 extends tx_rtehtmlarea_base {
         *
         * @param       integer         $RTEcounter: The index number of the RTE editing area.
         * @param       string          $form: the name of the form
-        * @param       string          $textarea: the name of the textarea
+        * @param       string          $textareaId: the id of the textarea
         *
         * @return      string          the JS-Code
         */
-       function setSaveRTE($RTEcounter, $form, $textarea) {
+       function setSaveRTE($RTEcounter, $form, $textareaId) {
                return '
-               editornumber = '.$RTEcounter.';
-               if (RTEarea[editornumber]) {
-                       fields = document.getElementsByName(\'' . $textarea . '\');
+               if (RTEarea[\'' . $textareaId . '\'] && !RTEarea[\'' . $textareaId . '\'].deleted) {
+                       fields = document.getElementsByName(\'' . $textareaId . '\');
                        field = fields.item(0);
-                       if(field && field.tagName.toLowerCase() == \'textarea\') field.value = RTEarea[editornumber][\'editor\'].getHTML();
-               }
-               else {
-                       OK=0;
-               }
-               ';
+                       if (field && field.nodeName.toLowerCase() == \'textarea\') { 
+                               field.value = RTEarea[\'' . $textareaId . '\'][\'editor\'].getHTML();
+                       }
+               } else {
+                       OK = 0;
+               }';
        }
-       
 }
 
 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/pi2/class.tx_rtehtmlarea_pi2.php'])       {