While migrating a very old Joomla website to version 2.5, we ran into a compatibility issue between the default MooTools library that comes with Joomla 2.5 and a module (the module was mod_jxtc_k2contentwall, for those who really want to know). The module was expecting an older version of MooTools – but what it got was the new version that comes with Joomla 2.5 which was incompatible with that module.
Trying to fix the JavaScript files of that module to to resolve the issue is, to put it delicately, an extremely painful experience. So we decided to do the following:
- Copy the old MooTools JavaScript file to the directory of the migrated module.
-
Unload (remove) the new MooTools files (there are two) in that module using PHP.
-
Load (add) the old MooTools file in that module (also using PHP).
So, after copying the old MooTools JavaScript file to the module’s directory, we added the following code (in the main file of the module, in our case it was the mod_jxtc_k2contentwall.php file located under the /modules/mod_jxtc_k2contentwall/ directory) in order to unload the default MooTools library and load the old one:
//Step 0 - Get the current document $document = &JFactory::getDocument(); //Step 1 - Get the root path of your website (this is needed later on in our code) $rootPath = JURI::root(true); //Step 2 - Get the current loaded scripts from the document $arrHead = $document->getHeadData(); //Step 3 - Remove the loaded scripts unset($arrHead['scripts'][$rootPath.'/media/system/js/mootools-core.js']); unset($arrHead['scripts'][$rootPath.'/media/system/js/mootools-more.js']); //Step 4 - Update the head content for the document $document->setHeadData($arrHead); //Step 5 - Add the old MooTools file $document->addScript('modules'.DS.'[yourmoduledirectory]'.DS.'mootools.js');
If you want to override the MooTools library with another library in one of your modules, then all you need to do is to literally copy and paste the above code to that module (of course, you need to change yourmoduledirectory with the directory containing your module). You can also do it globally (for all your website) by just copying and pasting the above code into your index.php file.
But where is the MooTools library loaded?
The MooTools library is loaded in the file behavior.php which is located in the libraries/joomla/html/html directory under your Joomla 2.5 website. It is possible to change the default MooTools library there (line 60 and 61 of that file), but we advise not to do this (unless you really know what you’re doing) because most likely you will run int compatibility issues with newer Joomla extensions that use features of the default MooTools library. Not to mention that we think it’s always a bad idea to change a core file (and behavior.php is a core file).
If you are having conflicts on one (or several) of your pages on your Joomla website between different JavaScript libraries, then try to fix that by using our method above (it applies to all JS files, not just those related to MooTools), and if you need help, rest assured that you can always rely on us. We’re fast, our services are well priced, and we know Joomla inside out! All you need to do is to contact us!
[…] mentioned earlier, the mootools JavaScript library is included in the file behavior.php which is located under the […]