Project

General

Profile

Actions

Feature #15889

closed

Clean up inline javascript in menu_layers.php

Added by Clemens Riccabona about 18 years ago. Updated about 11 years ago.

Status:
Rejected
Priority:
Should have
Assignee:
-
Category:
-
Target version:
-
Start date:
2006-03-23
Due date:
% Done:

0%

Estimated time:
PHP Version:
4.3
Tags:
Complexity:
Sprint Focus:

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
  1. 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();
  1. schnapp #####

(issue imported from #M2970)


Files

gmenu_layers.php (20.8 KB) gmenu_layers.php Administrator Admin, 2006-03-23 16:56
tmenu_layers.php (20.6 KB) tmenu_layers.php Administrator Admin, 2010-10-27 18:28
gmenu_layers_v2.php (20.6 KB) gmenu_layers_v2.php Administrator Admin, 2010-10-27 18:29
2970.patch (4.86 KB) 2970.patch Administrator Admin, 2010-10-27 20:37

Related issues 3 (0 open3 closed)

Related to TYPO3 Core - Feature #17035: Approach and patch for removing all inline JavaScriptRejected2007-02-24

Actions
Related to TYPO3 Core - Feature #17003: Add the js openPic-function to core-jsClosed2007-02-17

Actions
Related to TYPO3 Core - Task #46358: Separate ext:statictemplates code from coreClosed2013-03-16

Actions
Actions #1

Updated by Clemens Riccabona about 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:

  1. 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###

Actions #2

Updated by Ralf Hettinger about 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 ;)

Actions #3

Updated by Clemens Riccabona about 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.

Actions #4

Updated by Benni Mack almost 16 years ago

Hey Clemens.

Can you provide an updated patch and send it to the core list?

Actions #5

Updated by Clemens Riccabona almost 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 ;)

Actions #6

Updated by Martin Kutschker almost 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.

Actions #7

Updated by Clemens Riccabona almost 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

Actions #8

Updated by Clemens Riccabona over 15 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

Actions #9

Updated by Benni Mack about 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.

Actions #10

Updated by Clemens Riccabona about 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.

Actions #11

Updated by Ernesto Baschny over 13 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

Actions #12

Updated by Clemens Riccabona over 13 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.

Actions #13

Updated by Clemens Riccabona over 13 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.

Actions #14

Updated by Chris topher over 13 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.

Actions #15

Updated by Clemens Riccabona over 13 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. :-)

Actions #16

Updated by Chris topher over 13 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.

Actions #17

Updated by Ernesto Baschny over 13 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

Actions #18

Updated by Chris topher over 13 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.

Actions #19

Updated by Clemens Riccabona over 13 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. :-)

Actions #20

Updated by Clemens Riccabona over 13 years ago

for me, patchfile looks ok.

+1 by reading ;)

Actions #21

Updated by Chris topher over 13 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!

Actions #22

Updated by Xavier Perseguers over 12 years ago

  • Category deleted (Communication)
  • Target version deleted (4.6.0-beta1)
Actions #23

Updated by Christian Kuhn about 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.

Actions #24

Updated by Christian Kuhn about 11 years ago

  • Status changed from Needs Feedback to Rejected
Actions

Also available in: Atom PDF