Tuesday 24 November 2009

Handy MooTools script for phpBB3 inside a wrapper

For reasons that are too long to go into, a change between phpBB2 and phpBB3 was to make all links not include a target attribute to make the output meet relevant requirements.

On one site I manage (http://www.connectage.com) we have a forum inside a Joomla! wrapper. I'm sure you can see where this is going.

So to stop this happening, I wrote a MooTools script. This script ensures that links to our site open in the parent window (i.e. not the iframe) and other links open in a new window / tab.


<script src="../media/system/js/mootools.js" type="text/javascript"></script>
<script type="text/javascript">
window.addEvent('load', function() {
// send links to a new window, unless it is on our site
var postLinks = $$("div#pagecontent div.postbody a.postlink");

postLinks.each(function(link) {
var sendTo = '_blank';
if(link.getProperty('href').contains(window.location.hostname)) {
sendTo = '_parent';
}
link.setProperties({
target: sendTo,
rel: 'nofollow'
});
});
});
</script>


Simple as that.

There are two scripts there. 1 brings in the default Joomla! MooTools script, which is needed so the rest works.

The second bit, creates an array of links within posts only, checks the domain they're going to and sends them to the parent window (target='_parent') or a new window (target='_blank').

And because it's Javascript, I believe it's still standards compliant. It will also not stop your site working if someone has Javascript turned off in their browser.

This may not work on your template, but it should be easily adaptable if you need it for your own site.

Validated XML for Joomla!

http://docs.joomla.org/Official_DTDs

And better yet, if you're using Eclipse and put the information in (correctly), it will validate it for you. Might solve my current problem with a component not installing correctly.

Tuesday 17 November 2009

Menu Module Clone

I've written a Joomla! component. Here's a demo of it.




Here's the full listing.