jeffchannell.com

Change Component Heading on SOBI2

Posted in Joomla!
2009-09-09 17:20:35 +0000 UTC

I was in need of a fix for the Joomla! component SOBI2, as a client wanted the title to reflect the current category and listing, instead of always having the name of the directory. After searching the web, I found an older post on the Sigsiu forums dealing with this. After rewriting a portion to reflect changes in SOBI2 since this was posted and applying this fix, however, I found that my copy of IE6 was throwing a very strange error: 80004004.

As it turns out, the error was related to the code posted at the Sigsiu forums:

...
static $cheadChanged = false;
if( !$cheadChanged ) {
	$cid = sobi2Config::request( $_REQUEST, 'catid', 0 );
        $cheadChanged = true;
	if( $cid ) {
		sobi2Config::import( 'category.class' );
		$cat = new sobi2Category( $cid );
		?>
		<script>
			var elements = document.getElementsByTagName( "div" );
		    for (var i = 0; i < elements.length; i++) {
		        if ( elements[i].className == "componentheading" ) {
		            elements[i].innerHTML = "<?php echo htmlentities($cat->name); ?>";
		            break;
		        }
		    }
		</script>
		<?php
	}
}
...

Since this code was executing before IE6 had even finished loading the page, IE6 had no idea how many divs there were going to be, and threw that error.

What I ended up doing is rewriting the JavaScript portion using MooTools markup, as the site I was doing this for always loaded MooTools for its operation. I also added this as a window load event, instead of firing immediately. Now IE6 renders the page as expected, without error.

...
static $cheadChanged = false;
if( !$cheadChanged ) {
	$cid = sobi2Config::request( $_REQUEST, 'catid', 0 );
        $cheadChanged = true;
	if( $cid ) {
		sobi2Config::import( 'category.class' );
		$cat = new sobi2Category( $cid );
		// original posted code causes weird ie6 error 80004004
		// added to domready using mootools & using mootools selectors
		$this->listing .= '
		<script type="text/javascript">
		window.addEvent( "load", function()
		{
			$$(".componentheading").each( function( el )
			{
				el.setHTML( "'.htmlentities($cat->name).'" );
			});
		});
		</script>';
	}
}
...

Unfortunately, this doesn't really help as far as SEO is concerned, but it looks better to the end user. Hopefully at some point in the future SOBI2 will support this as a configurable option.