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

查看:144
本文介绍了将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天全站免登陆