繁体   English   中英

Joomla模块jQuery冲突

[英]Joomla Modules jQuery conflict

我在两个Joomla模块中存在jQuery冲突。 我在每个模块中找到以下代码。 有人可以帮我解决冲突吗?

第一个模块中的代码:

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.pack.js"></script>

//...

<script type="text/javascript">
  jQuery(document).ready(function () {
    jQuery('#jeYW<?php echo $module->id ?>').weatherfeed([<?php echo "'".$cityCode[0]."'"; for ($i=1; $i<count($cityCode); $i++){echo ",'".$cityCode[$i]."'";}?>],{
      unit: '<?php echo $unit ?>',
      image: <?php echo $image ?>,
      country: <?php echo $country ?>,
      highlow: <?php echo $highlow ?>,
      wind: <?php echo $wind ?>,
      humidity: <?php echo $humidity ?>,
      visibility: <?php echo $visibility ?>,
      sunrise: <?php echo $sunrise ?>,
      sunset: <?php echo $sunset ?>,
      forecast: <?php echo $forecast ?>,
      link: <?php echo $forecastlink ?>,
      showerror: true,
      linktarget: '_blank',
      woeid: <?php echo $woeid ?>
    });
  });
</script>

第二个模块中的代码:

$document->addScript(JURI::base(true).'/modules/mod_muscol_featured_albums/tmpl/jcarousel/lib/jquery-1.2.3.pack.js');

$document->addScript(JURI::base(true).'/modules/mod_muscol_featured_albums/tmpl/jcarousel/lib/jquery.jcarousel.pack.js');

$document->addStyleSheet(JURI::base(true).'/modules/mod_muscol_featured_albums/tmpl/jcarousel/lib/jquery.jcarousel.css');

//...

$document->addScriptDeclaration("
  console.dir(jQuery.fn.init.prototype);
  jQuery(document).ready(function() {
    jQuery('#random_album_".$random_id."').jcarousel({
      // Configuration goes here
      scroll: ".$scroll."
      ".$auto."
      ".$animation."
      ".$circular."
      ".$vertical."
    });
});
");

您可以尝试jQuery Easy 阅读评论,您将了解该组件的功能。 我已经使用了很长时间了。

特征:

  • jQuery和jQuery UI库可以在Joomla中托管! 或从HTTP或HTTPS中的Google API库中调用(设置显式版本以进行适当的缓存),
  • 不需要在前端或后端进行编码(无需将代码添加到模板中或与Joomla!core混淆),
  • 在MooTools调用之后放置jQuery调用以实现完美的兼容性,
  • 添加noConflict代码,
  • 在应用程序级别将“ jQuery”变量设置为“ true”,
  • 去除所有其他jQuery,jQuery UI库调用,包括其他模块或插件添加的noConflict调用,
  • 选择jQuery UI基本样式或自定义主题。
  • 新:可能的专家调整
  • 新增:可以在您网站的特定部分启用或禁用该插件
  • v1.2.0以后的新功能:可以在前端暂时禁用MooTools库
  • 自v1.3.0起新增:报告和更多选项可帮助解决更多高级案例
  • 新:Joomla! 3.0特定版本发布

确保仅导入1个jQuery副本。 为此,请改用以下方法:

if(!JFactory::getApplication()->get('jquery')){
     JFactory::getApplication()->set('jquery',true);
     $document = JFactory::getDocument();
     $document->addScript("http://code.jquery.com/jquery-latest.pack.js");
}

更新:

尝试在noConflict的if语句上方添加此内容

$document->addCustomTag( '<script type="text/javascript">jQuery.noConflict();</script>' );

希望这可以帮助

jQuery easy应该可以解决该问题,也可以将其添加到模板index.php的开头:

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

将会加载jquery 1.8.1(或任何joomla稳定的1.8版本)

在我同时使用两者的情况下,其中jquery easy只是禁用mootools并为我添加了jquery ui,发生了一些冲突,此设置似乎可以解决此问题...

暂无
暂无

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

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