将 jQuery 导入 Joomla [英] Importing jQuery into Joomla

查看:11
本文介绍了将 jQuery 导入 Joomla的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成为 Joomla 开发人员将近一年了.我每天都在努力将 jQuery 导入 joomla.Joomla 带有 mootools.当我导入 jQuery 时它崩溃了.此外,当我创建模块时,我必须将 jQuery 导入每个模块,这会使站点变慢.有时它会使整个网站崩溃.我希望 mootools 和 jquery 携手合作,这样我就可以使用它们而不会发生任何崩溃.

I have been a Joomla developer for almost an year now. I have been struggling to import jQuery into joomla everyday. Joomla comes with mootools. When I import jQuery it crashes. Also when I create modules I have to import jQuery into each module which makes to site slow. Sometimes it makes the whole site crashes. I want both mootools and jquery to work hand in hand so I can use both without any crashes.

将 jQuery 导入 Joomla 的最佳方法是什么? 是否有一个特定的地方应该进行导入以在整个站点范围内使用一个 jquery 库(后端和前端>) ?

What's the best way to import jQuery into Joomla ? Is there a specific place where the import should be done to use one jquery library site-wide(both backend and frontend) ?

谢谢

推荐答案

这是我们用来确保仅导入 1 个 jQuery 副本的代码.它只是检查 jQuery 是否已经被导入,如果没有,然后我们导入它 :)

This is the code we use to ensure only 1 copy of jQuery is imported. It simply checks to see if jQuery is already being imported and if not, then we import it :)

Joomla 2.5

<?php
  $app = JFactory::getApplication();
  if (!$app->get('jquery'))
  {
     $app->set('jquery', true);
     JFactory::getDocument()->addScript(JUri::root() . 'templates/template_name/js/jquery.js');
  }
?>

Joomla 3.x(无冲突模式):

JHtml::_('jquery.framework');

Joomla 3.x(普通模式):

JHtml::_('jquery.framework', false);

您需要将此代码插入到模板的 index.php 中,最好靠近顶部,以便您记住它的位置.如果您不想覆盖模板的 index.php 文件,那么您还可以开发一个小的 插件

You need to insert this code into the index.php of your template, preferably near the top so you remember where it is. If you do not wish to override your template's index.php file, then you can also develop a small Plugin

更新:

正如鲍比所说.许多扩展包括他们自己的 jQuery 副本,其中很多不使用这种方法,因此会导致冲突.我所知道的是,任何优秀的开发人员都应该知道多个 jQuery 库会导致冲突,并且应该使用此代码.

As Bobby stated. A lot of extensions include their own copy of jQuery and a lot of them don't use this method and thus causes conflicts. All I know is that any good developer should know that multiple jQuery libraries causes conflicts and should use this code.

这篇关于将 jQuery 导入 Joomla的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆