Somethimes in projects where Joomla 1.5 is used you may need to remove inclusion of MooTools JavaScript library. It may need when your Joomla uses another JavaScript library, for example jQuery or you don't need to use functionality which provides MooTools. While looking for solution for this, I often found the following code which may be used in template code:
<?php
$headerstuff = $this->getHeadData();?>
$headerstuff['scripts'] = array();
$this->setHeadData($headerstuff);
This code can break some plugins or module functionality because it removes all javascript inclusions which were done through Joomla API. If module or plugin includes required javascript file(s) through Joomla API and you are using code above, this code removes this inclusion and correct behaviour of plugin or module will be broken. I can offer more correct code for this purpose:
<?php
$headerstuff = $this->getHeadData();?>
$scripts = $headerstuff['scripts'];
$jsForRemove = array('mootools.js', 'caption.js');
foreach ($scripts as $key => $value)
foreach ($jsForRemove as $js)
if (strpos($key, $js) !== false) unset($scripts[$key]);
$headerstuff['scripts'] = $scripts;
$this->setHeadData($headerstuff);
Include this code before
Or you can use 'Inclusions Remover' Joomla plugin which helps to remove unnecessary inclusions of scripts and CSS files which were included through Joomla API. You can download it here.
PS: If you use 'Inclusions Remover' plugin, please post a rating and a review at the Joomla! Extensions Directory.
5 comments: