[TASK] Cleanup inline JavaScript in Backend 54/54254/4
authorBenni Mack <benni@typo3.org>
Mon, 2 Oct 2017 07:39:01 +0000 (09:39 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Tue, 3 Oct 2017 21:16:48 +0000 (23:16 +0200)
This patch removes the global "TS." JavaScript option, as well as
unused code in EditDocumentController, BackendController and
PreviewController.

Resolves: #82631
Releases: master
Change-Id: I5de0af0acbac798bc9a57875a0631766a8016fa8
Reviewed-on: https://review.typo3.org/54254
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/backend/Classes/Controller/BackendController.php
typo3/sysext/backend/Classes/Controller/EditDocumentController.php
typo3/sysext/backend/Resources/Public/JavaScript/LoginRefresh.js
typo3/sysext/backend/Resources/Public/JavaScript/UserPassLogin.js
typo3/sysext/backend/Resources/Public/JavaScript/backend.js
typo3/sysext/workspaces/Classes/Controller/PreviewController.php

index 2c5200d..e4d689f 100644 (file)
@@ -626,23 +626,12 @@ class BackendController
         }
         $t3Configuration = [
             'username' => htmlspecialchars($beUser->user['username']),
-            'uniqueID' => GeneralUtility::shortMD5(uniqid('', true)),
             'pageModule' => $pageModule,
             'inWorkspace' => $beUser->workspace !== 0,
             'showRefreshLoginPopup' => isset($GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup']) ? (int)$GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup'] : false
         ];
         $this->js .= '
        TYPO3.configuration = ' . json_encode($t3Configuration) . ';
-
-       /**
-        * TypoSetup object.
-        */
-       function typoSetup() {  //
-               this.username = TYPO3.configuration.username;
-               this.uniqueID = TYPO3.configuration.uniqueID;
-       }
-       var TS = new typoSetup();
-               //backwards compatibility
        /**
         * Frameset Module object
         *
@@ -651,12 +640,11 @@ class BackendController
         *              if (top.fsMod) top.fsMod.recentIds["web"] = "\'.(int)$this->id.\'";
         *              if (top.fsMod) top.fsMod.recentIds["file"] = "...(file reference/string)...";
         */
-       function fsModules() {  //
-               this.recentIds=new Array();                                     // used by frameset modules to track the most recent used id for list frame.
-               this.navFrameHighlightedID=new Array();         // used by navigation frames to track which row id was highlighted last time
-               this.currentBank="0";
-       }
-       var fsMod = new fsModules();
+       var fsMod = {
+               recentIds: [],                                  // used by frameset modules to track the most recent used id for list frame.
+               navFrameHighlightedID: [],              // used by navigation frames to track which row id was highlighted last time
+               currentBank: "0"
+       };
 
        top.goToModule = function(modName, cMR_flag, addGetVars) {
                TYPO3.ModuleMenu.App.showModule(modName, addGetVars);
index 844d2ea..567490b 100644 (file)
@@ -733,39 +733,22 @@ class EditDocumentController extends AbstractModule
                                        formEl.checked = formEl.checked ? 0 : 1;
                                }
                        }
-'
-        );
-        $t3Configuration = [];
-
-        $javascript = '
-                       TYPO3.configuration = ' . json_encode($t3Configuration) . ';
-                       // Object: TS:
-                       // TS object overwrites the object declared in tbe_editor.js
-                       function typoSetup() {  //
-                               this.uniqueID = "";
-                       }
-                       var TS = new typoSetup();
 
                                // Info view:
-                       function launchView(table,uid) {        //
+                       function launchView(table,uid) {
                                var thePreviewWindow = window.open(
                                        ' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('show_item') . '&table=') . ' + encodeURIComponent(table) + "&uid=" + encodeURIComponent(uid),
-                                       "ShowItem" + TS.uniqueID,
+                                       "ShowItem" + Math.random().toString(16).slice(2),
                                        "height=300,width=410,status=0,menubar=0,resizable=0,location=0,directories=0,scrollbars=1,toolbar=0"
                                );
                                if (thePreviewWindow && thePreviewWindow.focus) {
                                        thePreviewWindow.focus();
                                }
                        }
-                       function deleteRecord(table,id,url) {   //
+                       function deleteRecord(table,id,url) {
                                window.location.href = ' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('tce_db') . '&cmd[') . '+table+"]["+id+"][delete]=1&redirect="+escape(url);
                        }
-               ';
-
-        $previewCode = isset($_POST['_savedokview']) && $this->popViewId ? $this->generatePreviewCode() : '';
-        $this->moduleTemplate->addJavaScriptCode(
-            'PreviewCode',
-            $javascript . $previewCode
+               ' . (isset($_POST['_savedokview']) && $this->popViewId ? $this->generatePreviewCode() : '')
         );
         // Setting up the context sensitive menu:
         $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu');
index 02fd17c..e1a86a2 100644 (file)
@@ -278,7 +278,7 @@ define(['jquery', 'TYPO3/CMS/Backend/Notification', 'bootstrap'], function($, Ty
         * Opens the login form in a new window.
         */
        LoginRefresh.showLoginPopup = function() {
-               var vHWin = window.open(LoginRefresh.loginFramesetUrl, 'relogin_' + TYPO3.configuration.uniqueID, 'height=450,width=700,status=0,menubar=0,location=1');
+               var vHWin = window.open(LoginRefresh.loginFramesetUrl, 'relogin_' + Math.random().toString(16).slice(2), 'height=450,width=700,status=0,menubar=0,location=1');
                if (vHWin) {
                        vHWin.focus();
                }
index 7de688d..9ca7dc5 100644 (file)
@@ -94,8 +94,8 @@ define(['jquery', 'TYPO3/CMS/Backend/Login'], function($, Login) {
                // If the login screen is shown in the login_frameset window for re-login,
                // then try to get the username of the current/former login from opening windows main frame:
                try {
-                       if (parent.opener && parent.opener.TS && parent.opener.TS.username) {
-                               $usernameField.val(parent.opener.TS.username);
+                       if (parent.opener && parent.opener.TYPO3 && parent.opener.TYPO3.configuration && parent.opener.TYPO3.configuration.username) {
+                               $usernameField.val(parent.opener.TYPO3.configuration.username);
                        }
                } catch (error) {} // continue
 
index b4f8287..dd5778c 100644 (file)
@@ -76,7 +76,7 @@ function str_replace(match,replace,string)    {       //
  */
 function launchView(table, uid) {
        var thePreviewWindow = window.open(TYPO3.settings.ShowItem.moduleUrl + '&table=' + encodeURIComponent(table) + "&uid=" + encodeURIComponent(uid),
-                       "ShowItem" + TS.uniqueID,
+                       "ShowItem" + Math.random().toString(16).slice(2),
                        "width=650,height=600,status=0,menubar=0,resizable=0,location=0,directories=0,scrollbars=1,toolbar=0");
        if (thePreviewWindow && thePreviewWindow.focus) {
                thePreviewWindow.focus();
index 7945dcc..29b7659 100644 (file)
@@ -217,25 +217,12 @@ class PreviewController extends AbstractController
         }
         $t3Configuration = [
             'username' => htmlspecialchars($backendUser->user['username']),
-            'uniqueID' => GeneralUtility::shortMD5(uniqid('', true)),
             'pageModule' => $pageModule,
             'inWorkspace' => $backendUser->workspace !== 0,
             'showRefreshLoginPopup' => isset($GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup']) ? (int)$GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup'] : false
         ];
 
-        return '
-               TYPO3.configuration = ' . json_encode($t3Configuration) . ';
-
-               /**
-                * TypoSetup object.
-                */
-               function typoSetup()    {       //
-                       this.username = TYPO3.configuration.username;
-                       this.uniqueID = TYPO3.configuration.uniqueID;
-               }
-               var TS = new typoSetup();
-                       //backwards compatibility
-               ';
+        return 'TYPO3.configuration = ' . json_encode($t3Configuration) . ';';
     }
 
     /**