0

I just trying to add a js file but I cant get it to work... I have googled but not found any help yet.. any help is much appreacheated

This is my code:

<?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() {

}

}
Mackelito
  • 4,213
  • 5
  • 39
  • 78
  • is your plugin installed and enabled? does the event get called? Try calling `JFactory::getApplication->enqueMessage('message')` in the constructor and event to see how your script is behaving. – Alex Apr 29 '12 at 00:42
  • Well if I add that in the onBeforeCompileHead function it breaks the site.. but if I put it in __construct there is no change.. :/ – Mackelito Apr 30 '12 at 10:17
  • does not sound right, `enqueMessage` simply adds a message to be displayed. If you are running php4, you have to use `public function plgSystemInfinityScroll` instead of `__construct`, constructor should always be called. I made a typo in prev. comment, it Should be `JFactory::getApplication()->enqueMessage('xxx')`. – Alex Apr 30 '12 at 12:36

1 Answers1

1

First of all, Id use the plugin event:

function onBeforeRender(){

}

Secondly your path is pointing wrong.

Change it to:

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

If you have MooTools loaded on the same page, you have to use jQuery.noConflict(); to avoid conflicts.

All together:

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>');} );');
}
Stilero
  • 467
  • 4
  • 19