So ... in a nutshel. Many users faced problem - they dont want to make their site heavy ... for any reasons ... And they need to remove mootools scripts. But removing these scripts we cant see pop ups when we are logged in ... (login in frontend and try to see edit buttons).
So , here we must use at least this checking code (it was decribed earlier by several users in different ways). And with me it looks like:
Code:
<?php
$user =& JFactory::getUser();
if($user->get('guest') == 1) {
$search = array('mootools', 'caption.js');
// remove the js files
foreach($this->_scripts as $key => $script) {
foreach($search as $findme) {
if(stristr($key, $findme) !== false) {
unset($this->_scripts[$key]);
}
}
}
}
Sure ... It doesnt solve our problem.
But, removing mootools from head we make impossible to use properly working extensions with moo. Lets see.
When Joomla starts load template - head data is already generated. IE - each script is added like ... caption
Code:
<?php
function caption() {
JHTML::script('caption.js');
}
If we look at this function (script) we see
Code:
<?php
function script($filename, $path = 'media/system/js/', $mootools = true)
{
// Include mootools framework
if($mootools) {
JHTML::_('behavior.mootools');
}
...........
$document = &JFactory::getDocument();
$document->addScript( $path.$filename );
return;
}
/*-------------- from JHTMLBehavior class ------------*/
function mootools($debug = null)
{
static $loaded;
// Only load once
if ($loaded) {
return;
}
// if is not loaded - loads and assign loaded = true
$loaded = true;
return;
}
/*-------------- from DOCUMENT class ------------*/
function addScript($url, $type="text/javascript") {
$this->_scripts[$url] = $type;
}
That mootools will be added anyway! before each script we want to include. It means that - when we remove mootools from head - we already have mootools "included" and any further attemt to include moo this way
Code:
<?php JHTML::_('behavior.mootools'); ?>
Wont be successful - as $loaded = true;
So we will need to recode each component that needs mootools.
IN the end ... I think, If JTem decided to include motoold in frontent - they should also think over how to give us the choice and provide with ability to unset mootools. Say like this way
Code:
<?php
function mootools($debug = null, $unset = false)
{
static $loaded;
// with help of this var - we set $loaded to false and make possible to include mootools then ...
if ($unset) {$loaded = false;return;}
then ... in template, after removing js scripts we past
Code:
<?php JHTMLBehavior::mootools(null,true); ?>
It's not professional - i;m not good coder - but the idea is like I descibed. And then ... in component - weh we call
JHTML::_('behavior.mootools');
we will get result =) even if we have removed some scripts at the very top of our template.
_________________
rudialex.com - custom joomla templates developer