Disable Mootools Javascript from Joomla 1.5 frontend
// June 25th, 2009 // Joomla
Whilst I have nothing against the MooTools javascript library for websites (it’s an awesome resource), I have built a lot of Joomla 1.0.x sites using the Jquery Javascript library. Now, this can cause a few conflicts, and it seems that with the introduction of Joomla 1.5.x, you’re pretty much forced into using it. or so I thought….
A quick google search on the subject revealed some nice ways to disable it from the frontend of your website (not appropriate for the backend, as it uses the MT library extensively.
I am by far no Javascript or php guru, but can get done what I need. Anyhow, the nicest bit of code i found to do the job was:
1 2 3 4 5 6 7 | <?php $user =& JFactory::getUser(); if ($user->get('guest') == 1 || $user->get('usertype') == 'Registered') { $headerstuff = $this->getHeadData(); $headerstuff['scripts'] = array(); $this->setHeadData($headerstuff); } ?> |
Perfect, just add it to your template > index.php file, right above:
1 | <jdoc:include type="head" /> |
I wanted to take it a step further (since I am building a few templates), and make it easy for anyone to change. Since Joomla 1.5 has a parameters file (which stores settings selected from templateDetails.xml), I simply added my on/off select button to the .xml file, defined the parameters in my template index file, and it works.
This is the code, and steps to make this happen.
In your Joomla 1.5 template folder:
templates > your_template_folder
open up: templateDetails.xml and add the following:
1 2 3 4 5 6 | <param name="@spacer" type="spacer" default="" label="" description=""/> <param name="Use_Mootools" type="radio" default="1" label="Disable Mootools Javascript library frontend?" description="Do you want to Disable the MooTools javscript library frontend?"> <option value="0">No</option> <option value="1">Yes</option> </param> |
The Parameters are usually at the end of the .xml file. You can declare many tyopes of parameters this way (as long as you also declare them in the index.php heade). If your .xml file doesn’t have any parameters yet, simply add the code between:
1 2 3 | <params> add it here </params> |
Now open up your templates index.php file. in between the < head > … < /head > area, AFTER:
1 | defined( '_JEXEC' ) or die( 'Restricted access' ); |
we need to declare our new parameter, so add the following:
1 2 3 | /* Definition whether to enable or disable Mootools and captions.js files This parameter should be turned off if you don't use any modules or Core Joomla compoinents that require it */ $Use_Mootools = ($this->params->get("Use_Mootools", 1) == 1)?"yes":"no"; // yes | no |
Now that we have declared our variable, we need to envoke the code (or not).
So, add the following code:
1 2 3 4 5 6 7 | <?php if($Use_Mootools == "yes") { $user =& JFactory::getUser(); if ($user->get('guest') == 1 || $user->get('usertype') == 'Registered') { $headerstuff = $this->getHeadData(); $headerstuff['scripts'] = array(); $this->setHeadData($headerstuff); } } ?> |
right before:
1 | <jdoc:include type="head" /> |
Now, Open up your admin, edit the template, on the right you’ve got the parameters, select no/yes, and test. hopefully it all went smoothly!
Edit:
There is plugin available, that will do just this for you, in case you don’t want to edit your templates. :
http://extensions.joomla.org/extensions/core-enhancements/scripts/8403/details , my code gives template developers the opportunity to turn it off…
As pointed out by 2estrellas, this code may strip all code. I stumbled across a great blog over at
highub, so def check it out, but try changing:
1 2 3 4 5 6 7 | <?php if($Use_Mootools == "yes") { $user =& JFactory::getUser(); if ($user->get('guest') == 1 || $user->get('usertype') == 'Registered') { $headerstuff = $this->getHeadData(); $headerstuff['scripts'] = array(); $this->setHeadData($headerstuff); } } ?> |
to
1 2 3 4 5 6 7 | <?php if($Use_Mootools == "yes") { $headerstuff = $this->getHeadData(); reset($headerstuff['scripts']); $moo = key($headerstuff['scripts']); unset($headerstuff['scripts'][$moo]); $this->setHeadData($headerstuff); } ?> |





it works great! im hoping for another tips on yours, thanks!
WARNING:
It works perfect , so perfect that it disables ALL JAVASCRIPTS from the front-end (not only mootols but jQuery or ANY other javascript that has been installed as modules/plugin in joomla)
If you want to selectively delete only some ( eg. mootols) js files take a look at
http://forum.joomla.org/viewtopic.php?f=304&t=194274&start=30
Worked for me
Thanks 2estrellas for the heads up. I tested it, and haven’t had any issues, but agreed, it may disable scripts from plugins. Most plugins I use load their JS into the body (which isn’t the best method anyhow).
I have edited the code to include a fix, and a link to a plugin that does the same, but this is more for template developers.
Cheers again….
Hi,
Thank you.
Craig.
Another faster way to remove the moo is to edit
Libraries/Joomla/Document/html/renderer/head.php
comment all it:
// Generate script file links
foreach ($document->_scripts as $strSrc => $strType) {
$strHtml .= $tab.”.$lnEnd;
}*/
but you are going to get javascript errors, use other plugin to hide or mask it.
Heya mate,
I did what you did, but mootools refuses to go away, I allready tried the other article too. Doesnt this work for article pages or something?
It should work across the board hans, I have done this method on 3 sites where i use Jquery and not Mootools (I don’t like the core tools used).