2009-08-25 98 views

回答

0

你有moo工具和jquery衝突。我建議使用jQuery幻燈片模塊 - 這將是最簡單的方法。

編輯:衝突看起來他們正在使用相同的命名空間,但我沒有太多的時間在更深的細節去

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.noConflict()被調用立即加載jQuery後http://www.designvsdevelop.com/jquery-in-joomla-i-was-wrong

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 [email protected] 
* @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 [email protected] 
*/ 
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); 
    } 

} 

?>