我最近从 Joomla 3.2.1 升级到 Joomla 3.2.2。

在 Joomla 3.2.1 中,我手动取消包含 jQuery:

$doc = JFactory::getDocument();

$dontInclude = array(
'/media/jui/js/jquery.js',
'/media/jui/js/jquery.min.js',
'/media/jui/js/jquery-noconflict.js',
'/media/jui/js/jquery-migrate.js',
'/media/jui/js/jquery-migrate.min.js',
'/media/jui/js/bootstrap.js',
'/media/system/js/core-uncompressed.js',
'/media/system/js/tabs-state.js',
'/media/system/js/core.js',
'/media/system/js/mootools-core.js',
'/media/system/js/mootools-core-uncompressed.js',
);
foreach($doc->_scripts as $key => $script){
    if(in_array($key, $dontInclude)){
        unset($doc->_scripts[$key]);
    }
}

但这在 Joomla 3.2.2 中不起作用。有没有办法在 3.2.2 中不包含 Joomla 的 jQuery?

有帮助吗?

解决方案 3

我已添加:

            $doNotInclude = array(
                'jquery',
                'bootstrap',
                'behavior',
            );
            if(in_array($file, $doNotInclude)){
                return;
            }
.

后立即:

            list($key, $prefix, $file, $func) = static::extract($key); 
.

在图书馆/ cms / html / html.php中,在“_”函数中。

我不喜欢它,因为它是对Joomla核心的修改,但它有效。我还在寻找更好的解决方案。

其他提示

使用Joomla 3.4适用于我的另一个变体是编辑模板> index.php文件,其中包含:

$doc = JFactory::getDocument();

$headData = $doc->getHeadData();
$scripts = $headData['scripts'];

//scripts to remove, customise as required

unset($scripts[JUri::root(true) . '/media/system/js/mootools-core.js']);
unset($scripts[JUri::root(true) . '/media/system/js/mootools-more.js']);
unset($scripts[JUri::root(true) . '/media/system/js/core.js']);
unset($scripts[JUri::root(true) . '/media/system/js/modal.js']);
unset($scripts[JUri::root(true) . '/media/system/js/caption.js']);
unset($scripts[JUri::root(true) . '/media/jui/js/jquery.min.js']);
unset($scripts[JUri::root(true) . '/media/jui/js/jquery-noconflict.js']);
unset($scripts[JUri::root(true) . '/media/jui/js/bootstrap.min.js']);
unset($scripts[JUri::root(true) . '/media/jui/js/jquery-migrate.min.js']);

$headData['scripts'] = $scripts;
$doc->setHeadData($headData);
.

您需要添加前缀 JUri::root(true) 在每个文件名之前 - 相对路径将不起作用

你也可以尝试这样的东西:

$removeScripts = [
    '/media/jui/js/jquery.min.js',
    '/media/jui/js/jquery-noconflict.js',
    '/media/jui/js/jquery-migrate.min.js',
    '/media/system/js/caption.js',
];
foreach ($removeScripts as $removeScript) {
    unset($this->_scripts[JURI::root(true).$removeScript]);
}
.

问题是您的in_array

如果通过更改此操作:

foreach($doc->_scripts as $key => $script){
    if(in_array($key, $dontInclude)){
        unset($doc->_scripts[$key]);
    }
}
.

到这个:

foreach($doc->_scripts as $key => $script){
    unset($doc->_scripts[$key]);
}
.

然后它可以正常工作。如果数组密钥存在,则毫无意义地检查,因为当我收集时,您还没有手动删除任何这些文件。

希望这有助于

joomla 3.3.6以不同的方式加载脚本,所以$ doc - > _脚本将返回任何东西...所以没有什么可以解开。

我建议使用此插件: https://github.com/poznakomlus/joomla_options

它允许您删除Bootstrap,JQuery和Mootools(您可以选择要禁用的内容)。

免责声明:我没有以任何方式用插件开发人员或插件本身附属。

如果您正在编写自定义模板或组件,则需要删除默认情况下默认加载的所有脚本,您可以创建一个简单的插件并将执行绑定到onBeforeCompileHead事件。

我的实施如下。它很简单。您可以通过特定于文件名或仅浏览父文件夹来进一步播放搜索列表。

protected $app;
public function onBeforeCompileHead() {
    // Front end
    if ($this->app instanceof JApplicationSite) {
        $doc = JFactory::getDocument();
        $search = array(
            'jui/js/',
            'system/js/'
        );
        foreach ($doc->_scripts as $key => $script) {
            foreach ($search as $findme) {
                if (stristr($key, $findme) !== false) {
                    unset($doc->_scripts[$key]);
                }
            }
        }
    }
}
.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top