[TASK] Cleanup RTE remove pageRenderer and use requireJS 53/41853/10
authorFrank Nägler <typo3@naegler.net>
Wed, 22 Jul 2015 21:07:07 +0000 (23:07 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Fri, 24 Jul 2015 15:57:20 +0000 (17:57 +0200)
Resolves: #68426
Resolves: #64713
Releases: master
Change-Id: I873d67e287e181f767e3a907797382a7f0f94f89
Reviewed-on: http://review.typo3.org/41853
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/backend/Classes/Form/FormEngine.php
typo3/sysext/rtehtmlarea/Classes/Form/Element/RichTextElement.php
typo3/sysext/rtehtmlarea/Resources/Public/JavaScript/HTMLArea/HTMLArea.js
typo3/sysext/rtehtmlarea/Resources/Public/JavaScript/HTMLArea/NameSpace/NameSpace.js
typo3/sysext/rtehtmlarea/Resources/Public/JavaScript/HTMLArea/Util/Wrap.close.js [deleted file]
typo3/sysext/rtehtmlarea/Resources/Public/JavaScript/HTMLArea/Util/Wrap.open.js [deleted file]

index 2d570f2..c71fe44 100644 (file)
@@ -1251,6 +1251,13 @@ class FormEngine {
                        $pageRenderer->loadJquery();
                        $pageRenderer->loadExtJS();
                        $pageRenderer->addJsFile('sysext/backend/Resources/Public/JavaScript/tree.js');
+                       $pageRenderer->addJsFile('sysext/backend/Resources/Public/JavaScript/notifications.js');
+                       if (ExtensionManagementUtility::isLoaded('rtehtmlarea')) {
+                               // This js addition is hackish ... it will always load this file even if not RTE
+                               // is added here. But this simplifies RTE initialization a lot and is thus kept for now.
+                               $pageRenderer->addJsFile('sysext/rtehtmlarea/Resources/Public/JavaScript/HTMLArea/NameSpace/NameSpace.js');
+                       }
+
                        $beUserAuth = $this->getBackendUserAuthentication();
                        // Make textareas resizable and flexible ("autogrow" in height)
                        $textareaSettings = array(
index 2dd2cc0..b2a062d 100644 (file)
@@ -29,7 +29,6 @@ use TYPO3\CMS\Backend\Form\InlineStackProcessor;
 use TYPO3\CMS\Core\Database\DatabaseConnection;
 use TYPO3\CMS\Core\Utility\MathUtility;
 use TYPO3\CMS\Lang\LanguageService;
-use TYPO3\CMS\Core\Page\PageRenderer;
 use TYPO3\CMS\Rtehtmlarea\RteHtmlAreaApi;
 
 /**
@@ -218,7 +217,6 @@ class RichTextElement extends AbstractFormElement {
                $parameterArray = $this->globalOptions['parameterArray'];
 
                $backendUser = $this->getBackendUserAuthentication();
-               $pageRenderer = $this->getPageRenderer();
 
                $this->resultArray = $this->initializeResultArray();
                $this->defaultExtras = BackendUtility::getSpecConfParts($parameterArray['fieldConf']['defaultExtras']);
@@ -257,17 +255,18 @@ class RichTextElement extends AbstractFormElement {
                // Merge the list of enabled plugins with the lists from the previous RTE editing areas on the same form
                $this->pluginEnabledCumulativeArray = $this->pluginEnabledArray;
 
-
                $this->addInstanceJavaScriptRegistration();
 
                $this->addOnSubmitJavaScriptCode();
 
-               // Add TYPO3 notifications JavaScript
-               $pageRenderer->addJsFile('sysext/backend/Resources/Public/JavaScript/notifications.js');
                // Add RTE JavaScript
-               $this->addRteJsFiles();
-               $pageRenderer->addJsFile($this->createJavaScriptLanguageLabelsFromFiles());
-               $pageRenderer->addJsInlineCode('HTMLArea-init', $this->getRteInitJsCode(), TRUE);
+               $this->loadRequireModulesForRTE();
+
+               // Create language labels
+               $this->createJavaScriptLanguageLabelsFromFiles();
+
+               // Get RTE init JS code
+               $this->resultArray['additionalJavaScriptPost'][] = $this->getRteInitJsCode();
 
                $html = $this->getMainHtml();
 
@@ -578,63 +577,15 @@ class RichTextElement extends AbstractFormElement {
         *
         * @return void
         */
-       protected function addRteJsFiles() {
-               $pageRenderer = $this->getPageRenderer();
-               // Component files. Order is important.
-               $components = array(
-                       'Util/Wrap.open',
-                       'NameSpace/NameSpace',
-                       'UserAgent/UserAgent',
-                       'Util/Util',
-                       'Util/Color',
-                       'Util/Resizable',
-                       'Util/String',
-                       'Util/Tips',
-                       'Util/TYPO3',
-                       'Ajax/Ajax',
-                       'DOM/DOM',
-                       'Event/Event',
-                       'Event/KeyMap',
-                       'CSS/Parser',
-                       'DOM/BookMark',
-                       'DOM/Node',
-                       'DOM/Selection',
-                       'DOM/Walker',
-                       'Configuration/Config',
-                       'Toolbar/Button',
-                       'Toolbar/ToolbarText',
-                       'Toolbar/Select',
-                       'Extjs/ColorPalette',
-                       'Extjs/ux/ColorMenu',
-                       'Extjs/ux/ColorPaletteField',
-                       'LoremIpsum',
-                       'Plugin/Plugin'
-               );
-               $components2 = array(
-                       'Editor/Toolbar',
-                       'Editor/Iframe',
-                       'Editor/TextAreaContainer',
-                       'Editor/StatusBar',
-                       'Editor/Framework',
-                       'Editor/Editor',
-                       'HTMLArea',
-                       'Util/Wrap.close',
-               );
-               foreach ($components as $component) {
-                       $pageRenderer->addJsFile($this->getFullFileName('EXT:rtehtmlarea/Resources/Public/JavaScript/HTMLArea/' . $component . '.js'));
-               }
+       protected function loadRequireModulesForRTE() {
+               $this->resultArray['requireJsModules'] = array();
+               $this->resultArray['requireJsModules'][] = 'TYPO3/CMS/Rtehtmlarea/HTMLArea/HTMLArea';
                foreach ($this->pluginEnabledCumulativeArray as $pluginId) {
                        /** @var RteHtmlAreaApi $plugin */
                        $plugin = $this->registeredPlugins[$pluginId];
                        $extensionKey = is_object($plugin) ? $plugin->getExtensionKey() : 'rtehtmlarea';
-                       $fileName = 'EXT:' . $extensionKey . '/Resources/Public/JavaScript/Plugins/' . $pluginId . '.js';
-                       $absolutePath = GeneralUtility::getFileAbsFileName($fileName);
-                       if (file_exists($absolutePath)) {
-                               $pageRenderer->addJsFile($this->getFullFileName($fileName));
-                       }
-               }
-               foreach ($components2 as $component) {
-                       $pageRenderer->addJsFile($this->getFullFileName('EXT:rtehtmlarea/Resources/Public/JavaScript/HTMLArea/' . $component . '.js'));
+                       $requirePath = 'TYPO3/CMS/' . GeneralUtility::underscoredToUpperCamelCase($extensionKey);
+                       $this->resultArray['requireJsModules'][] = $requirePath . '/Plugins/' . $pluginId;
                }
        }
 
@@ -1029,9 +980,11 @@ class RichTextElement extends AbstractFormElement {
                                $labelArray[$pluginId] = $newLabels;
                        }
                }
-               $javaScriptString = 'HTMLArea.I18N = new Object();' . LF;
+               $javaScriptString = 'TYPO3.jQuery(function() {';
+               $javaScriptString .= 'HTMLArea.I18N = new Object();' . LF;
                $javaScriptString .= 'HTMLArea.I18N = ' . json_encode($labelArray);
-               return $this->writeTemporaryFile($this->language, 'js', $javaScriptString);
+               $javaScriptString .= '});';
+               $this->resultArray['additionalJavaScriptPost'][] = $javaScriptString;
        }
 
        /**
@@ -1352,11 +1305,4 @@ class RichTextElement extends AbstractFormElement {
                return $GLOBALS['TYPO3_DB'];
        }
 
-       /**
-        * @return PageRenderer
-        */
-       protected function getPageRenderer() {
-               return GeneralUtility::makeInstance(PageRenderer::class);
-       }
-
 }
index e652600..9c45d2c 100644 (file)
@@ -21,109 +21,108 @@ define('TYPO3/CMS/Rtehtmlarea/HTMLArea/HTMLArea',
        'TYPO3/CMS/Rtehtmlarea/HTMLArea/Editor/Editor'],
        function (UserAgent, Util, Config, Editor) {
 
-       var HtmlArea = {
+               var HtmlArea = {
 
-               /***************************************************
-                * COMPILED REGULAR EXPRESSIONS                    *
-                ***************************************************/
-               RE_htmlTag              : /<.[^<>]*?>/g,
-               RE_tagName              : /(<\/|<)\s*([^ \t\n>]+)/ig,
-               RE_head                 : /<head>((.|\n)*?)<\/head>/i,
-               RE_body                 : /<body>((.|\n)*?)<\/body>/i,
-               reservedClassNames      : /htmlarea/,
-               RE_email                : /([0-9a-z]+([a-z0-9_-]*[0-9a-z])*){1}(\.[0-9a-z]+([a-z0-9_-]*[0-9a-z])*)*@([0-9a-z]+([a-z0-9_-]*[0-9a-z])*\.)+[a-z]{2,9}/i,
-               RE_url                  : /(([^:/?#]+):\/\/)?(([a-z0-9_]+:[a-z0-9_]+@)?[a-z0-9_-]{2,}(\.[a-z0-9_-]{2,})+\.[a-z]{2,5}(:[0-9]+)?(\/\S+)*\/?)/i,
-               RE_numberOrPunctuation  : /[0-9.(),;:!¡?¿%#$'"_+=\\\/-]*/g,
+                       /***************************************************
+                        * COMPILED REGULAR EXPRESSIONS                    *
+                        ***************************************************/
+                       RE_htmlTag              : /<.[^<>]*?>/g,
+                       RE_tagName              : /(<\/|<)\s*([^ \t\n>]+)/ig,
+                       RE_head                 : /<head>((.|\n)*?)<\/head>/i,
+                       RE_body                 : /<body>((.|\n)*?)<\/body>/i,
+                       reservedClassNames      : /htmlarea/,
+                       RE_email                : /([0-9a-z]+([a-z0-9_-]*[0-9a-z])*){1}(\.[0-9a-z]+([a-z0-9_-]*[0-9a-z])*)*@([0-9a-z]+([a-z0-9_-]*[0-9a-z])*\.)+[a-z]{2,9}/i,
+                       RE_url                  : /(([^:/?#]+):\/\/)?(([a-z0-9_]+:[a-z0-9_]+@)?[a-z0-9_-]{2,}(\.[a-z0-9_-]{2,})+\.[a-z]{2,5}(:[0-9]+)?(\/\S+)*\/?)/i,
+                       RE_numberOrPunctuation  : /[0-9.(),;:!¡?¿%#$'"_+=\\\/-]*/g,
 
-               /***************************************************
-                * INITIALIZATION                                  *
-                ***************************************************/
-               init: function () {
-                       if (!HTMLArea.isReady) {
-                               // Apply global configuration settings
-                               Util.apply(HtmlArea, RTEarea[0]);
-                               HTMLArea.isReady = true;
-                               HtmlArea.appendToLog('', 'HTMLArea', 'init', 'Editor url set to: ' + HtmlArea.editorUrl, 'info');
-                               HtmlArea.appendToLog('', 'HTMLArea', 'init', 'Editor content skin CSS set to: ' + HtmlArea.editedContentCSS, 'info');
+                       /***************************************************
+                        * INITIALIZATION                                  *
+                        ***************************************************/
+                       init: function () {
+                               if (!HTMLArea.isReady) {
+                                       // Apply global configuration settings
+                                       Util.apply(HtmlArea, RTEarea[0]);
+                                       HTMLArea.isReady = true;
+                                       HtmlArea.appendToLog('', 'HTMLArea', 'init', 'Editor url set to: ' + HtmlArea.editorUrl, 'info');
+                                       HtmlArea.appendToLog('', 'HTMLArea', 'init', 'Editor content skin CSS set to: ' + HtmlArea.editedContentCSS, 'info');
 
-                               Util.apply(HTMLArea, HtmlArea);
-                       }
-               },
+                                       Util.apply(HTMLArea, HtmlArea);
+                               }
+                       },
 
-               /**
-                * Create an editor when HTMLArea is loaded and when Ext is ready
-                *
-                * @param       string          editorId: the id of the editor
-                * @return      boolean         false if successful
-                */
-               initEditor: function (editorId) {
-                       if (document.getElementById('pleasewait' + editorId)) {
-                               if (UserAgent.isSupported()) {
-                                       document.getElementById('pleasewait' + editorId).style.display = 'block';
-                                       document.getElementById('editorWrap' + editorId).style.visibility = 'hidden';
-                                       if (!HTMLArea.isReady) {
-                                               var self = this;
-                                               window.setTimeout(function () {
-                                                       return self.initEditor(editorId);
-                                               }, 150);
+                       /**
+                        * Create an editor when HTMLArea is loaded and when Ext is ready
+                        *
+                        * @param       string          editorId: the id of the editor
+                        * @return      boolean         false if successful
+                        */
+                       initEditor: function (editorId) {
+                               if (document.getElementById('pleasewait' + editorId)) {
+                                       if (UserAgent.isSupported()) {
+                                               document.getElementById('pleasewait' + editorId).style.display = 'block';
+                                               document.getElementById('editorWrap' + editorId).style.visibility = 'hidden';
+                                               if (!HTMLArea.isReady) {
+                                                       var self = this;
+                                                       window.setTimeout(function () {
+                                                               return self.initEditor(editorId);
+                                                       }, 150);
+                                               } else {
+                                                       // Create an editor for the textarea
+                                                       var editor = new Editor(Util.apply(new Config(editorId), RTEarea[editorId]));
+                                                       editor.generate();
+                                                       return false;
+                                               }
                                        } else {
-                                               // Create an editor for the textarea
-                                               var editor = new Editor(Util.apply(new Config(editorId), RTEarea[editorId]));
-                                               editor.generate();
-                                               return false;
+                                               document.getElementById('pleasewait' + editorId).style.display = 'none';
+                                               document.getElementById('editorWrap' + editorId).style.visibility = 'visible';
                                        }
-                               } else {
-                                       document.getElementById('pleasewait' + editorId).style.display = 'none';
-                                       document.getElementById('editorWrap' + editorId).style.visibility = 'visible';
                                }
-                       }
-                       return true;
-               },
+                               return true;
+                       },
 
-               /***************************************************
-                * LOCALIZATION                                    *
-                ***************************************************/
-               localize: function (label, plural) {
-                       var i = plural || 0;
-                       var localized = HTMLArea.I18N.dialogs[label] || HTMLArea.I18N.tooltips[label] || HTMLArea.I18N.msg[label] || '';
-                       if (typeof localized === 'object' && localized !== null && typeof localized[i] !== 'undefined') {
-                               localized = localized[i]['target'];
-                       }
-                       return localized;
-               },
+                       /***************************************************
+                        * LOCALIZATION                                    *
+                        ***************************************************/
+                       localize: function (label, plural) {
+                               var i = plural || 0;
+                               var localized = HTMLArea.I18N.dialogs[label] || HTMLArea.I18N.tooltips[label] || HTMLArea.I18N.msg[label] || '';
+                               if (typeof localized === 'object' && localized !== null && typeof localized[i] !== 'undefined') {
+                                       localized = localized[i]['target'];
+                               }
+                               return localized;
+                       },
 
-               /***************************************************
-                * LOGGING                                         *
-                ***************************************************/
-               /**
-                * Write message to JavaScript console
-                *
-                * @param       string          editorId: the id of the editor issuing the message
-                * @param       string          objectName: the name of the object issuing the message
-                * @param       string          functionName: the name of the function issuing the message
-                * @param       string          text: the text of the message
-                * @param       string          type: the type of message: 'log', 'info', 'warn' or 'error'
-                * @return      void
-                */
-               appendToLog: function (editorId, objectName, functionName, text, type) {
-                       var str = 'RTE[' + editorId + '][' + objectName + '::' + functionName + ']: ' + text;
-                       if (typeof type === 'undefined') {
-                               var type = 'info';
-                       }
-                       if (typeof console === 'object' && console !== null) {
-                               // If console is TYPO3.Backend.DebugConsole, write only error messages
-                               if (typeof console.addTab === 'function') {
-                                       if (type === 'error') {
+                       /***************************************************
+                        * LOGGING                                         *
+                        ***************************************************/
+                       /**
+                        * Write message to JavaScript console
+                        *
+                        * @param       string          editorId: the id of the editor issuing the message
+                        * @param       string          objectName: the name of the object issuing the message
+                        * @param       string          functionName: the name of the function issuing the message
+                        * @param       string          text: the text of the message
+                        * @param       string          type: the type of message: 'log', 'info', 'warn' or 'error'
+                        * @return      void
+                        */
+                       appendToLog: function (editorId, objectName, functionName, text, type) {
+                               var str = 'RTE[' + editorId + '][' + objectName + '::' + functionName + ']: ' + text;
+                               if (typeof type === 'undefined') {
+                                       var type = 'info';
+                               }
+                               if (typeof console === 'object' && console !== null) {
+                                       // If console is TYPO3.Backend.DebugConsole, write only error messages
+                                       if (typeof console.addTab === 'function') {
+                                               if (type === 'error') {
+                                                       console[type](str);
+                                               }
+                                       // IE may not have any console
+                                       } else if (typeof console[type] !== 'undefined') {
                                                console[type](str);
                                        }
-                               // IE may not have any console
-                               } else if (typeof console[type] !== 'undefined') {
-                                       console[type](str);
                                }
                        }
-               }
-       };
-
-       return Util.apply(HTMLArea, HtmlArea);
+               };
 
+               return Util.apply(HTMLArea, HtmlArea);
 });
diff --git a/typo3/sysext/rtehtmlarea/Resources/Public/JavaScript/HTMLArea/Util/Wrap.close.js b/typo3/sysext/rtehtmlarea/Resources/Public/JavaScript/HTMLArea/Util/Wrap.close.js
deleted file mode 100644 (file)
index 7c81529..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-// Avoid re-initialization on AJax call when HTMLArea object was already initialized
-}
diff --git a/typo3/sysext/rtehtmlarea/Resources/Public/JavaScript/HTMLArea/Util/Wrap.open.js b/typo3/sysext/rtehtmlarea/Resources/Public/JavaScript/HTMLArea/Util/Wrap.open.js
deleted file mode 100644 (file)
index 1a3d927..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-// Avoid re-initialization on AJax call when HTMLArea object was already initialized
-if (typeof HTMLArea === 'undefined') {