Feature #15889
closedClean up inline javascript in menu_layers.php
0%
Description
When using layermenus, you are confronted with crowds of inline javascripts. the solution is a small change within the two files gmenu_layers.php and tmenu_layers.php. would be nice to be integrated in the next releases.
following changes, gmenu_layers.php, from line 414 --> but its the same in tmenu_layers.php- schnipp #####
$GLOBALS['TSFE']->JSeventFuncCalls['onload']['GL_initLayers()']= 'GL_initLayers();';
$GLOBALS['TSFE']->JSeventFuncCalls['onload'][$this->WMid]= 'GL_restoreMenu("'.$this->WMid.'");';
$GLOBALS['TSFE']->JSeventFuncCalls['onmousemove']['GL_getMouse(e)']= 'GL_getMouse(e);'; // Should be called BEFORE any of the 'local' getMouse functions!
$GLOBALS['TSFE']->JSeventFuncCalls['onmousemove'][$this->WMid]= 'GL'.$this->WMid.'_getMouse(e);';
$GLOBALS['TSFE']->JSeventFuncCalls['onmouseup'][$this->WMid]= 'GL_mouseUp(\''.$this->WMid.'\',e);';
$GLOBALS['TSFE']->divSection.=implode($this->divLayers,chr(10)).chr(10);
/** The Changes **/
$GLOBALS['TSFE']->additionalHeaderData['1tmenu_layers'] .= TSpagegen::inline2TempFile($this->_JSCode,'js');
if($GLOBALS['TSFE']->JSImgCode != ''){
$GLOBALS['TSFE']->additionalHeaderData['js_1tmenu_layers'].= TSpagegen::inline2TempFile($GLOBALS['TSFE']->JSImgCode,'js');
$GLOBALS['TSFE']->JSImgCode = '';
}
return parent::extProc_finish();
- schnapp #####
(issue imported from #M2970)
Files
Updated by Clemens Riccabona over 17 years ago
I have to mention following: I use this code within my projects, and it's okay for me. BUT: you have to write following TypoScript in your layermenus:
###schnipp###
1=GMENU_LAYERS
1 {
...
layer_menu_id = topnav1
imgNameNotRandom = 1
imgNamePrefix = nav1
...
}
###schnapp###
Otherwise the cached javascript files won't be deleted with clearing the cache, what results in myriades of javascript files in typo3temp folder, sitting there lost and doing nothing!! And also getting more files with every 'ClearCache' operation!
So if someone has a better suggestion, to solve this problem, it would be nice.
The code provided above, is for tmenu_layers, which may be unclear, here the code for the gmenu_layers, just the same line:
- Schnipp ###
$GLOBALS['TSFE']->additionalHeaderData['1gmenu_layers'] .= TSpagegen::inline2TempFile($this->_JSCode,'js');if($GLOBALS['TSFE']->JSImgCode != ''){
$GLOBALS['TSFE']->additionalHeaderData['js_1gmenu_layers'].= TSpagegen::inline2TempFile($GLOBALS['TSFE']->JSImgCode,'js');
$GLOBALS['TSFE']->JSImgCode = '';
}
return parent::extProc_finish();
###Schnapp###
Updated by Ralf Hettinger over 17 years ago
This has relations to http://bugs.typo3.org/view.php?id=5064
I don't know a better way either and think there probably isn't one since without naming the menus, they will be named randomly triggereing a new file to export.
OT: Clemens, if I look at the date you must've been under heavy workload for 2 weeks plus a year ;)
Updated by Clemens Riccabona over 17 years ago
Sorry, it was definitively me, who reported the problem.
But I didn't recognize because there was so much time gone since I posted.
I will have a look at it again in May 2007, if I hopefully can finish this big project I'm working on.
I think there MUST be a better solution, as it is not really secure for beginners, to use my hack.
Updated by Benni Mack over 16 years ago
Hey Clemens.
Can you provide an updated patch and send it to the core list?
Updated by Clemens Riccabona over 16 years ago
Hey Benjamin, Sorry, been on holiday ;)
I could send an updated version of the two files. BUT: Do you think, this is save? As mentioned above, it is a problem if you do not set some of these important typoscript variables.
On the other hand, probably we can set this variables within the x-layer.php. But for that I need some time, to have a look at the code again, since this topic is very old ;)
Updated by Martin Kutschker over 16 years ago
Clemens, you could check the required TS settings in the PHP code and trigger the externalization only if the prerequesits are met.
Updated by Clemens Riccabona over 16 years ago
Thanks Martin, for the hint. This is most likely the best way.
Which version should this go to the core? 4.2.2?
or 4.3.0?
I will try to add the new files here till beginning of August
Updated by Clemens Riccabona about 16 years ago
Hey Guys!
After a while, I had now time to have a short look at it.
One thing I experienced is, that some JS code could go to jsfunc.layermenu.js in sysext/cms/media/scripts/
Here they are:
1. function changeBGcolor
This simple static js-code. no need to spam the header with it.
btw: it could be a better function, I changed it for some projects of mine, that it also except graphics and not only colors. This has been done, because if you want a seperate bg-graphic for ifsub, you will need it (because the css version of this won't freeze if you move the mouse to sublayer).
Working example here: www.pakfeifer-riccabona.com
This one is the same with tslib_menu line 1826. So probably the jsfunc.layermenu.js is not the correct place. Suggestions?
2. The over and out functions:
I was not able by now, to locate where they are written. but looking at the source it seems to be, that this is also static js-code, which can be sourced out in a static js file easily.
Another thing I recognized: sms_directshortcuts does xclass the gmenu and tmenu, but not the layers.
But this feature could easily be included by having the link function in this two files too. -> also been done on my own web (link above).
Does anyone know, when featurefreeze for version 4.3 is scheduled, that i can contribute my work in time?
thxal, Clemens
Updated by Benni Mack over 14 years ago
Hey Clemens.
Sorry for the late response. The Feature Freeze for 4.4 is in about a month, would you be able to contribute your work on this issue until then?
thx, benni.
Updated by Clemens Riccabona over 14 years ago
Should be possible.
At the moment I am using a different modification because to the changes of TSpagegen::inline2TempFile in TYPO3 4.3 as i wasn't really pleased with the solution writing the script-tags on my own. ;)
With this new version it would also be possible to automatically merge and compress the script-files through one of the js-css merger+compressors in TER.
Updated by Ernesto Baschny about 14 years ago
Clemens, thanks for your patience. This is still interesting, and maybe you find some time to provide a new version that would work in our current "trunk", so that we can ship some enhancements in that area with version 4.5 (in long time support).
Cheers,
Ernesto
Updated by Clemens Riccabona about 14 years ago
Hi Ernesto,
After playing around with the new pagerenderer, and searching for an alternative for the fixed 'layer_menu_id' and some testing is my conclusion as follows:
also with the new pagerenderer a fixed layer_menu_id must be set, because there is no way to use the tsfe-inlineJS with ONE SINGLE FILE for all the layers together.
So i now have two new files, attaching them immediatley after posting.
these files should replace the 'old' xmenu_layer files. they are built on the ones shipped with TYPO3 4.4.4.
The changes:
All changes are marked with '// changes by RICC for externalization'
original code is commented out, not deleted.
the changes are small, but with some effect i guess ;)
1. jsfunc.layermenu.js is included through the new pagerenderer, therefore it is possible to have it compressed and probably concatenated with e.g. js_css_optimizer extension.
2. if a layer_menu_id is set, the rest of the code is written to tempfile (via typo3-api), each layer to one file, and is included through pagerenderer too. (compression & concatenation with hooking ext, see @1.)
3. if no layer_menu_id is set, the stuff is written with the old method 'TSFE->JSCode'.
last but not least:
there is a function addJScolorShiftFunction which adds 'changeBGcolor' js in the tslib_menu class, around line 1915.
this function should be changed to have this code also "externalized" in websites.
it's quite simple, change this:
$GLOBALS['TSFE']->additionalJavaScript['TMENU:changeBGcolor()']='
to
$jsCode = '
and add at the bottom of the function
$pageRender = $GLOBALS['TSFE']->getPageRenderer();
$pageRender->addJsInlineCode('tmenu.changebgcolor', $jsCode, TRUE, TRUE);
so it can be externalized.
Updated by Clemens Riccabona about 14 years ago
BTW: i use this patch since years on lots of installations (without the 'fallback' if layermenuid is not set, and some additional changes of no common interest), and i can't see any problems or unwanted sideeffects.
A live example for a mixed gmenu_layers / tmenu_layers implementation you can have a look at our own website www.eur-ops.com.
Updated by Chris topher about 14 years ago
Hi Clemens,
could you provide your changes as a patch file? That would help to figure out, what was changed.
Afterwards, seeing your discussion here, I think you should send your patch to Core List to get the fix integrated finally.
Updated by Clemens Riccabona about 14 years ago
i will try to make a patch. can you suggest a good piece of software for this task on ubuntu?
// edit:
sry, netbeans can do this task. :-)
Updated by Chris topher about 14 years ago
I use Eclipse (on Windows, but it is plattform independent), but for me it is slow. Others use Netbeans, which basically does the same.
If you are a purist, maybe a command line version of "diff" is enough for you.
Updated by Ernesto Baschny about 14 years ago
Clemens. Best would be:
1) checkout the TYPO3 src with "svn" (available in package "subversion" on ubuntu):
% svn co https://svn.typo3.org/TYPO3v4/Core/trunk typo3-trunk
2) symlink this in your webspace root as typo3_src and create the links to t3lib, typo3 and index.php
3) add your changes to the files you want, don't need extra tagging around your changes.. and just remove lines that are not relevant anymore
4) do a "svn diff" in the root and you will see the changes as a patch file. Just save it to a file "svn diff > 2970.diff" and send it here.
Cheers,
Ernesto
Updated by Chris topher about 14 years ago
I just created a patch file out of the files Clemens posted here.
I also included the changes from #21388, which are part of trunk, but were not part of Clemen's patch. Besides, I did some CGL clean up.
See attached 2970.patch.
Updated by Clemens Riccabona about 14 years ago
thxal christopher, you saved me some time of fiddling around with trunk and my changes.
and thxal to ernesto, i think for the future i will use your diff method via bash. copied already to my ZIM. :-)
Updated by Clemens Riccabona about 14 years ago
for me, patchfile looks ok.
+1 by reading ;)
Updated by Chris topher about 14 years ago
Now send a mail with your patch to Core List. You can find a how to here: http://typo3blogger.de/ab-in-den-core/ (I assume you are speaking German ;)).
If you have any questions, don't hesitate to ask!
Updated by Xavier Perseguers over 13 years ago
- Category deleted (
Communication) - Target version deleted (
4.6.0-beta1)
Updated by Christian Kuhn over 11 years ago
With 6.1 issue #46358, the _layers menus where moved to statictemplates, and statictemplates was removed from core afterwards. This issue won't be solved in the core anymore.
Updated by Christian Kuhn over 11 years ago
- Status changed from Needs Feedback to Rejected