简体   繁体   English

在Joomla 2.5中禁用JS脚本

[英]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. 我正在使用Joomla 2.5.19并且我已经删除了Mootools,因为它与JQuery产生了冲突。 I've also disabled caption.js. 我也禁用了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 来自components/com_content/controller.php

But no luck. 但没有运气。 I also tried including unset($this->_scripts['/media/system/js/caption.js']); 我也试过包括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. 你不应该删除Mootools,因为冲突,你可以使用jQuery Easy插件。 Visit http://extensions.joomla.org/extensions/core-enhancements/performance/jquery-scripts/18327 访问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或使用第三方扩展来加载jQuery。 Mootools is used heavily in Joomla, especially version 2.5.x; Mootools在Joomla中使用很多,尤其是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: 如果你需要使用jQuery,只需在IIFE周围包装任何jQuery代码,如下所示:

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. 感谢这篇文章。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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