简体   繁体   中英

Disable JS script in Joomla 2.5

I'm using Joomla 2.5.19 and I have removed Mootools since it is generating a conflict with JQuery. I've also disabled caption.js.

Now, on every page, the following script is being added in the head section:

<script type="text/javascript">
window.addEvent('domready', function() {
            $$('.hasTip').each(function(el) {
                var title = el.get('title');
                if (title) {
                    var parts = title.split('::', 2);
                    el.store('tip:title', parts[0]);
                    el.store('tip:text', parts[1]);
                }
            });
            var JTooltips = new Tips($$('.hasTip'), { maxTitleChars: 50, fixed: false});
        });
  </script>

This is throwing the error:

Uncaught TypeError: Object [object global] has no method 'addEvent' 

How do I get rid of this?

I followed the instructions here and deleted:

JHtml::_('behavior.caption');

From components/com_content/controller.php

But no luck. I also tried including unset($this->_scripts['/media/system/js/caption.js']);

How do I get rid of this?

You should not remove Mootools, for conflictions, you can use jQuery Easy plugin. Visit http://extensions.joomla.org/extensions/core-enhancements/performance/jquery-scripts/18327

If you are developing your own extension there is really no need to remove Mootools or use a third party extension to load jQuery. Mootools is used heavily in Joomla, especially version 2.5.x; so removing it could have adverse affects on expected behavior when using core functions. If you need to use jQuery simply wrap any jQuery code around an IIFE like so:

function($) {

    // jQuery code goes here

})(jQuery);

I've managed to remove the script with:

<?php


// Custom script
    $document =& JFactory::getDocument();

    // Remove call to JTooltips
    $document->_script = preg_replace('window\.addEvent\(\'domready\',\s*function\(\)\s*{\s*\$\$\(\'.hasTip\'\).each\(function\(el\)\s*{\s*var\s*title\s*=\s*el.get\(\'title\'\);\s*if\s*\(title\)\s*{\s*var\s*parts\s*=\s*title.split\(\'::\',\s*2\);\s*el.store\(\'tip:title\',\s*parts\[0\]\);\s*el.store\(\'tip:text\',\s*parts\[1\]\);\s*}\s*}\);\s*var\s*JTooltips\s*=\s*new\s*Tips\(\$\$\(\'.hasTip\'\),\s*{\s*maxTitleChars:\s*50,\s*fixed:\s*false}\);\s*}\);', '', $document->_script);


?>

Thanks to this post.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM