Fixed bug #9136: Less JS in backend.php / Framehandling problem
authorBenni Mack <benni.mack@typo3.org>
Thu, 1 Jan 2009 15:48:57 +0000 (15:48 +0000)
committerBenni Mack <benni.mack@typo3.org>
Thu, 1 Jan 2009 15:48:57 +0000 (15:48 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@4632 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
typo3/classes/class.modulemenu.php
typo3/js/modulemenu.js

index d1cd128..c8a3e46 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2009-01-01  Benjamin Mack  <benni@typo3.org>
+
+       * Fixed bug #9136: Less JS in backend.php / Framehandling problem
+
 2008-12-30  Oliver Hader  <oliver@typo3.org>
 
        * Added feature #5610: Extend TCEFORM_confObj on Page TSconfig by property keepItems
index 1ecc0a1..a418c92 100644 (file)
@@ -143,7 +143,7 @@ class ModuleMenu {
                                $moduleLabel = '<a href="#" onclick="top.goToModule(\''.$moduleData['name'].'\');'.$onBlur.'return false;">'.$moduleLabel.'</a>';
                        }
 
-                       $menu .= '<li id="'.$moduleKey.'" class="menuSection" title="'.$moduleData['description'].'"><div class="'.($menuState ? 'collapsed' : 'expanded').'">'.$moduleData['icon']['html'].' '.$moduleLabel.'</div>';
+                       $menu .= '<li id="modmenu_' . $moduleData['name'] . '" class="menuSection" title="' . $moduleData['description'] . '"><div class="' . ($menuState ? 'collapsed' : 'expanded') . '">' . $moduleData['icon']['html'] . ' ' . $moduleLabel . '</div>';
 
                                // traverse submodules
                        if(is_array($moduleData['subitems'])) {
@@ -207,7 +207,7 @@ class ModuleMenu {
                                        .'</a>';
                        }
 
-                       $moduleMenu .= '<li id="'.$moduleData['cssId'].'">'.$submoduleLink.'</li>'."\n";
+                       $moduleMenu .= '<li id="modmenu_' . $moduleData['name'] . '">' . $submoduleLink . '</li>' . "\n";
                }
 
                return '<ul'.($menuState ? ' style="display:none;"' : '').'>'."\n".$moduleMenu.'</ul>'."\n";
@@ -240,7 +240,6 @@ class ModuleMenu {
                        $moduleLink = t3lib_div::resolveBackPath($moduleLink);
 
                        $moduleKey   = $moduleName.'_tab';
-                       $moduleCssId = 'ID_'.t3lib_div::md5int($moduleName);
                        $moduleIcon  = $this->getModuleIcon($moduleKey);
 
                        if($moduleLink && $moduleNavigationFramePrefix) {
@@ -251,7 +250,6 @@ class ModuleMenu {
                                'name'        => $moduleName,
                                'title'       => $GLOBALS['LANG']->moduleLabels['tabs'][$moduleKey],
                                'onclick'     => 'top.goToModule(\''.$moduleName.'\');',
-                               'cssId'       => $moduleCssId,
                                'icon'        => $moduleIcon,
                                'link'        => $moduleLink,
                                'prefix'      => $moduleNavigationFramePrefix,
@@ -265,7 +263,6 @@ class ModuleMenu {
                                        $submoduleNavigationFramePrefix = $this->getNavigationFramePrefix($moduleData, $submoduleData);
 
                                        $submoduleKey         = $moduleName.'_'.$submoduleName.'_tab';
-                                       $submoduleCssId       = 'ID_'.t3lib_div::md5int($moduleName.'_'.$submoduleName);
                                        $submoduleIcon        = $this->getModuleIcon($submoduleKey);
                                        $submoduleDescription = $GLOBALS['LANG']->moduleLabels['labels'][$submoduleKey.'label'];
 
@@ -278,7 +275,6 @@ class ModuleMenu {
                                                'name'         => $moduleName.'_'.$submoduleName,
                                                'title'        => $GLOBALS['LANG']->moduleLabels['tabs'][$submoduleKey],
                                                'onclick'      => 'top.goToModule(\''.$moduleName.'_'.$submoduleName.'\');',
-                                               'cssId'        => $submoduleCssId,
                                                'icon'         => $submoduleIcon,
                                                'link'         => $submoduleLink,
                                                'originalLink' => $originalLink,
@@ -330,7 +326,7 @@ class ModuleMenu {
        protected function getModuleIconAbsolute($iconFilename) {
 
                if(!t3lib_div::isAbsPath($iconFilename))        {
-                       $iconFilename = $this->backPath.$iconFilename;
+                       $iconFilename = $this->backPath . $iconFilename;
                }
 
                return $iconFilename;
@@ -344,10 +340,9 @@ class ModuleMenu {
         * @see getModuleIconAbsolute()
         */
        protected function getModuleIconRelative($iconFilename) {
-               if(t3lib_div::isAbsPath($iconFilename)) {
-                       $iconFilename = '../'.substr($iconFilename, strlen(PATH_site));
+               if (t3lib_div::isAbsPath($iconFilename)) {
+                       $iconFilename = '../' . substr($iconFilename, strlen(PATH_site));
                }
-
                return $this->backPath.$iconFilename;
        }
 
@@ -398,10 +393,11 @@ class ModuleMenu {
 
                $moduleJavascriptCommands = array();
                $rawModuleData            = $this->getRawModuleData();
+               $navFrameScripts          = array();
 
                foreach($rawModuleData as $mainModuleKey => $mainModuleData) {
-                       if($mainModuleData['subitems']) {
-                               foreach($mainModuleData['subitems'] as $subModuleKey => $subModuleData) {
+                       if ($mainModuleData['subitems']) {
+                               foreach ($mainModuleData['subitems'] as $subModuleKey => $subModuleData) {
 
                                        $parentModuleName  = substr($subModuleData['name'], 0, strpos($subModuleData['name'], '_'));
                                        $javascriptCommand = '';
@@ -412,23 +408,21 @@ class ModuleMenu {
                                                $additionalJavascript = "+'&id='+top.rawurlencodeAndRemoveSiteUrl(top.fsMod.recentIds['" . $parentModuleName . "'])";
                                        }
 
-                                       if($subModuleData['link'] && $this->linkModules) {
+                                       if ($subModuleData['link'] && $this->linkModules) {
                                                        // For condensed mode, send &cMR parameter to frameset script.
-                                               if($additionalJavascript && $GLOBALS['BE_USER']->uc['condensedMode']) {
-                                                       $additionalJavascript .= "+(cMR?'&cMR=1':'')";
+                                               if ($additionalJavascript && $GLOBALS['BE_USER']->uc['condensedMode']) {
+                                                       $additionalJavascript .= "+(cMR ? '&cMR=1' : '')";
                                                }
 
                                                $javascriptCommand = '
-                                                       $(\'content\').src = top.getModuleUrl(top.TS.PATH_typo3+"'.$this->appendQuestionmarkToLink($subModuleData['link']).'"'.$additionalJavascript.'+additionalGetVariables);
-                                                       top.fsMod.currentMainLoaded="'.$parentModuleName.'";
-                                               ';
+                               modScriptURL = "'.$this->appendQuestionmarkToLink($subModuleData['link']).'"'.$additionalJavascript.';';
 
-                                               if($subModuleData['navFrameScript']) {
+                                               if ($subModuleData['navFrameScript']) {
                                                        $javascriptCommand .= '
-                                                               top.currentSubScript="'.$subModuleData['originalLink'].'";';
+                               top.currentSubScript="'.$subModuleData['originalLink'].'";';
                                                }
 
-                                               if(!$GLOBALS['BE_USER']->uc['condensedMode'] && $subModuleData['parentNavigationFrameScript']) {
+                                               if (!$GLOBALS['BE_USER']->uc['condensedMode'] && $subModuleData['parentNavigationFrameScript']) {
                                                        $additionalJavascript = "+'&id='+top.rawurlencodeAndRemoveSiteUrl(top.fsMod.recentIds['" . $parentModuleName . "'])";
 
                                                        $submoduleNavigationFrameScript = $subModuleData['navigationFrameScript'] ? $subModuleData['navigationFrameScript'] : $subModuleData['parentNavigationFrameScript'];
@@ -436,55 +430,71 @@ class ModuleMenu {
 
                                                                // add GET parameters for sub module to the navigation script
                                                        $submoduleNavigationFrameScript = $this->appendQuestionmarkToLink($submoduleNavigationFrameScript).$subModuleData['navigationFrameScript'];
-
+                                                       $navFrameScripts[$parentModuleName] = $submoduleNavigationFrameScript;
                                                        $javascriptCommand = '
-                               if (top.content.list_frame && top.fsMod.currentMainLoaded=="'.$parentModuleName.'") {
-                                       top.currentSubScript="'.$subModuleData['originalLink'].'";
-                                       top.content.list_frame.location=top.getModuleUrl(top.TS.PATH_typo3+"'.$this->appendQuestionmarkToLink($subModuleData['originalLink']).'"'.$additionalJavascript.'+additionalGetVariables);
-                                       if(top.currentSubNavScript!="'.$submoduleNavigationFrameScript.'") {
-                                               top.currentSubNavScript="'.$submoduleNavigationFrameScript.'";
-                                               top.content.nav_frame.location=top.getModuleUrl(top.TS.PATH_typo3+"'.$submoduleNavigationFrameScript.'");
-                                       }
+                               top.currentSubScript = "'.$subModuleData['originalLink'].'";
+                               if (top.content.list_frame && top.fsMod.currentMainLoaded == mainModName) {
+                                       modScriptURL = "'.$this->appendQuestionmarkToLink($subModuleData['originalLink']).'"'.$additionalJavascript.';
+                               } else if (top.nextLoadModuleUrl) {
+                                       modScriptURL = "'.($subModuleData['prefix'] ? $this->appendQuestionmarkToLink($subModuleData['link']) . '&exScript=' : '') . 'listframe_loader.php";
                                } else {
-                                       $(\'content\').src = top.TS.PATH_typo3+(
-                                               top.nextLoadModuleUrl?
-                                               "'.($subModuleData['prefix'] ? $this->appendQuestionmarkToLink($subModuleData['link']).'&exScript=' : '').'listframe_loader.php":
-                                               "'.$this->appendQuestionmarkToLink($subModuleData['link']).'"'.$additionalJavascript.'+additionalGetVariables
-                                       );
-                                       top.fsMod.currentMainLoaded="'.$parentModuleName.'";
-                                       top.currentSubScript="'.$subModuleData['originalLink'].'";
-                               }
-                                                       ';
+                                       modScriptURL = "'.$this->appendQuestionmarkToLink($subModuleData['link']).'"'.$additionalJavascript.' + additionalGetVariables;
+                               }';
                                                }
-
-                                               $javascriptCommand .= '
-                               top.highlightModuleMenuItem("'.$subModuleData['cssId'].'");
-                                               ';
-                                               $moduleJavascriptCommands[] = "                 case '".$subModuleData['name']."': \n ".$javascriptCommand." \n                 break;";
                                        }
+                               $moduleJavascriptCommands[] = "
+                       case '".$subModuleData['name']."':".$javascriptCommand."
+                       break;";
                                }
                        } elseif(!$mainModuleData['subitems'] && !empty($mainModuleData['link'])) {
                                        // main module has no sub modules but instead is linked itself (doc module f.e.)
                                $javascriptCommand = '
-                                       top.content.location=top.getModuleUrl(top.TS.PATH_typo3+"'.$this->appendQuestionmarkToLink($mainModuleData['link']).'"+additionalGetVariables);
-                                       top.highlightModuleMenuItem("'.$mainModuleData['cssId'].'", 1);
-                               ';
-                               $moduleJavascriptCommands[] = "                 case '".$mainModuleData['name']."': \n ".$javascriptCommand." \n                        break;";
+                               modScriptURL = "'.$this->appendQuestionmarkToLink($mainModuleData['link']).'";';
+                               $moduleJavascriptCommands[] = "
+                       case '".$mainModuleData['name']."':".$javascriptCommand."
+                       break;";
                        }
                }
 
                $javascriptCode = 'function(modName, cMR_flag, addGetVars) {
+               var useCondensedMode = '.($GLOBALS['BE_USER']->uc['condensedMode'] ? 'true' : 'false').';
+               var mainModName = (modName.slice(0, modName.indexOf("_")) || modName);
+
                var additionalGetVariables = "";
-               if (addGetVars) additionalGetVariables = addGetVars;
+               if (addGetVars) {
+                       additionalGetVariables = addGetVars;
+               }
 
-               var cMR = 0;
-               if (cMR_flag)   cMR = 1;
-
-               currentModuleLoaded = modName;
+               var cMR = (cMR_flag ? 1 : 0);
+               var modScriptURL = "";
 
                switch(modName) {'
                        ."\n".implode("\n", $moduleJavascriptCommands)."\n".'
                }
+
+               var navFrames = {};';
+               foreach ($navFrameScripts as $mainMod => $frameScript) {
+                       $javascriptCode .= '
+               navFrames["'.$mainMod.'"] = "'.$frameScript.'";';
+               }
+               $javascriptCode .= '
+
+               if (!useCondensedMode && navFrames[mainModName]) {
+                       if (top.content.list_frame && top.fsMod.currentMainLoaded == mainModName) {
+                               top.content.list_frame.location = top.getModuleUrl(top.TS.PATH_typo3 + modScriptURL + additionalGetVariables); 
+                               if (top.currentSubNavScript != navFrames[mainModName]) {
+                                       top.currentSubNavScript = navFrames[mainModName];
+                                       top.content.nav_frame.location = top.getModuleUrl(top.TS.PATH_typo3 + navFrames[mainModName]);
+                               }
+                       } else {
+                               $("content").src = top.TS.PATH_typo3 + modScriptURL;
+                       }
+               } else if (modScriptURL) {
+                       $("content").src = top.getModuleUrl(top.TS.PATH_typo3 + modScriptURL + additionalGetVariables);
+               }
+               currentModuleLoaded = modName;
+               top.fsMod.currentMainLoaded = mainModName;
+               TYPO3ModuleMenu.highlightModule("modmenu_" + modName, (modName == mainModName ? 1 : 0));
        }';
 
                return $javascriptCode;
index c2b902e..23eac61 100644 (file)
@@ -76,6 +76,7 @@ var ModuleMenu = Class.create({
 
                var mainMenuId       = mainModuleHeader.up().identify();
                var subModulesMenu   = mainModuleHeader.next('ul');
+               if (!subModulesMenu) return;
                var state            = subModulesMenu.visible();
 
                        // save state
@@ -124,6 +125,12 @@ var ModuleMenu = Class.create({
                        this.currentlyHighLightedMainModule = mainModule;
                }
                this.currentlyHighlightedModuleId = moduleId;
+
+               // kept for backwards compatibility
+               // @TODO: remove in TYPO3 4.5
+               // @deprecated since TYPO3 4.3, remove in 4.5
+               top.currentlyHighLightedId   = moduleId;
+               top.currentlyHighLightedMain = mainModule;
        }
 
 });
@@ -145,9 +152,6 @@ var currentlyHighLighted_restoreValue = '';
 var currentlyHighLightedMain = '';
 function highlightModuleMenuItem(trId, mainModule) {
        TYPO3ModuleMenu.highlightModule(trId, mainModule);
-
-       currentlyHighLightedId   = trId;
-       currentlyHighLightedMain = mainModule;
 }