我的网站上有一个自定义jQuery手风琴菜单,当模块启用时,它会破坏我的RokSlideshow模块。
我无法让他们同时工作。
该网站为http://www.fbcsheffield.org/2.0
非常感谢任何帮助!
答案 0 :(得分:4)
你必须先强制加载MooTools,然后加载jQuery并告诉它在执行任何jQuery代码或插件之前进入无冲突模式。查看第183页:http://www.packtpub.com/files/learning-joomla-1-5-extension-development-sample-chapter-8-using-javascript-effects.pdf或Joomla论坛上的此主题:http://forum.joomla.org/viewtopic.php?f=231&t=283215
编辑:你实际上不必须首先加载MooTools,你必须确保在加载jQuery之后立即调用立即 jQuery.noConflict(): http://www.designvsdevelop.com/jquery-in-joomla-i-was-wrong
答案 1 :(得分:1)
答案 2 :(得分:1)
Joomla使用ob_start()缓冲所有内容。您可以使用以下命令获取当前缓冲区:
$body = JResponse::getBody();
然后,您可以找到JQuery和MooTools脚本声明,并使用“onAfterRender”事件在系统插件中重构它们。
您可以使用preg_replace()获取JQuery并在MooTools之后输入。然后,您可以在JQuery中启用无冲突模式。
jQuery.noConflict();
这是一个将MooTools从1.1更改为1.2的示例插件。你可以为JQuery的无冲突模式做一些相似的事情。
<?php
/**
* MooTools1.2 w/ 1.1 compat for AjaxChat
* @copyright www.fijiwebdesign.com
* @author gabe@fijiwebdesign.com
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
*/
// included only
defined( '_JEXEC' ) or die( 'Direct Access to this location is not allowed!' );
jimport( 'joomla.plugin.plugin' );
/**
* Joomla PHP Speedy Integration
*
* @author gabe@fijiwebdesign.com
*/
class plgSystemAjaxchat extends JPlugin
{
/**
* Constructor
*
* For php4 compatability we must not use the __constructor as a constructor for plugins
* because func_get_args ( void ) returns a copy of all passed arguments NOT references.
* This causes problems with cross-referencing necessary for the observer design pattern.
*
* @access protected
* @param object $subject The object to observe
* @param array $config An array that holds the plugin configuration
* @since 1.0
*/
function plgSystemAjaxchat(& $subject, $config)
{
parent::__construct($subject, $config);
$mainframe =& JFactory::getApplication();
$document =& JFactory::getDocument();
$doctype = $document->getType();
// deactivate for backend
if ($mainframe->isAdmin()) {
return false;
}
// add mootools 1.2
if ( $doctype == 'html' ) {
$document->addScript('components/com_ajaxchat/js/mootools-1.2-core.js');
$document->addScript('components/com_ajaxchat/js/mootools-1.2-more.js');
$document->addScript('components/com_ajaxchat/js/mootools-1.2-core-compat.js');
$document->addScript('components/com_ajaxchat/js/mootools-1.2-more-compat.js');
}
}
/**
* After Templte output is in buffer
*/
function onAfterRender() {
$mainframe =& JFactory::getApplication();
$document =& JFactory::getDocument();
$doctype = $document->getType();
// deactivate for backend
if ($mainframe->isAdmin()) {
return false;
}
// Only render for HTML output
if ( $doctype !== 'html' ) {
return;
}
// get the output buffer
$body = JResponse::getBody();
// remove mootools if not needed
if (stristr($body, 'mootools.js') || stristr($body, 'mootools-uncompressed.js')) {
$body = preg_replace("/<script.*?mootools(-uncompressed)?\.js.*?<\/script>/i", '', $body);
} else {
$body = preg_replace("/<script.*?mootools-1\.2\-.*?\.js.*?<\/script>[\s\t\r\n]*/i", "\n", $body);
}
JResponse::setBody($body);
}
}
?>
答案 3 :(得分:0)
你有moo-tools和jquery冲突。我建议使用jquery幻灯片模块 - 这将是最简单的方法。
编辑:冲突看起来像是在使用相同的命名空间,但我没有太多时间深入细节
答案 4 :(得分:0)