2012-04-28 64 views
0

我只是想添加一个js文件,但我不能得到它的工作...我用Google搜索,但没有发现任何帮助,但..任何帮助是非常appreacheated添加JS中的Joomla 2.5插件

这是我的代码:

所有的
<?php 

defined('_JEXEC') or die('Restricted access'); 
jimport('joomla.plugin.plugin'); 

class plgSystemInfinityScroll extends JPlugin { 
protected $_execute; 

function __construct(&$subject, $config) { 
    $app = JFactory::getApplication(); 

    if($app->isAdmin()) 
    { 
     return; 
    } 

    parent::__construct($subject, $config); 
    $this->loadLanguage('', JPATH_ADMINISTRATOR); 
    $this->_execute = true; 
} 

public function onBeforeCompileHead() { 

    $document =& JFactory::getDocument(); 
    $document->addScript('/plugins/system/sjdinfinitescroll/jquery.infinitescroll.js'); 

} 

public function onAfterRender() { 

} 

} 
+0

是你的插件安装并启用?事件是否被调用?尝试在构造函数和事件中调用'JFactory :: getApplication-> enqueMessage('message')'来查看脚本的行为。 – Alex 2012-04-29 00:42:59

+0

那么,如果我在onBeforeCompileHead函数中添加它会中断网站..但是如果我将它放在__construct中没有更改..:/ – Mackelito 2012-04-30 10:17:09

+0

听起来不正确,'enqueMessage'只是添加要显示的消息。如果您正在运行php4,则必须使用'public function plgSystemInfinityScroll'而不是'__construct',应始终调用构造函数。我在prev中犯了一个错字。评论,它应该是'JFactory :: getApplication() - > enqueMessage('xxx')'。 – Alex 2012-04-30 12:36:04

回答

1

首先,标识使用的插件事件:

function onBeforeRender(){ 

} 

其次你的路径指向错误的。

将其更改为:

//J1.6+ 
$script= JURI::root(true).DS.'plugins'.DS.'system'.DS.'sjdinfinitescroll'.DS.'jquery.infinitescroll.js'; 
$document =& JFactory::getDocument(); 
$document->addScript($script); 

如果您有加载在同一页上MooTools的,你必须使用jQuery.noConflict();避免冲突。

一起:

function onBeforeRender(){ 
     $script= JURI::root(true).DS.'plugins'. 
      DS.'system'.DS.'sjdinfinitescroll'.DS.'jquery.infinitescroll.js'; 
     $document =& JFactory::getDocument(); 
     $document->addScript($script); 
     $document->addScriptDeclaration('jQuery.noConflict();'); 
     $document->addScriptDeclaration('jQuery(function($){ $('#myid'.append('<h2>my header</h2>');});'); 
} 
+0

我在你的类名中看到一个错字: – Stilero 2012-05-15 06:42:19