MyBB Hacks

Full Version: Coding a lightbox in a plug in
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am trying to make a template in a plug in that will cause a lightbox to open when the resulting inserted image is clicked on:

PHP Code:
{
   $text = $this->html($text);
	if($link != '')
          {
	return "<div class=\"wikiimage\"><a href=\"{$link}\" rel=\"lightbox\"><img src=\"{$url}\" alt=\"{$text}\" /></a><br />{$text}</div>\n";
           }
	else
	{
	return "<div class=\"wikiimage\"><img src=\"{$url}\" alt=\"{$text}\" /><br />{$text}</div>\n";
	}
}


however, this is not working for me. When I inspect element using firebug then I get this:

Code:
<a rel="lightbox" href="http://www.leefish.nl/mybb/wiki.php?file/how-to-make-ambtattoos/ambtattoo-tut-1.jpg"><img alt="" src="http://www.leefish.nl/mybb/wiki.php?file/how-to-make-ambtattoos/ambtattoo-tut-1.jpg"></a>


It should be

Code:
<a href="http://www.leefish.nl/mybb/wiki.php?file/how-to-make-ambtattoos/ambtattoo-tut-1.jpg" rel="lightbox" ><img alt="" src="http://www.leefish.nl/mybb/wiki.php?file/how-to-make-ambtattoos/ambtattoo-tut-1.jpg"></a>


How should I order the input in the php to make the lightbox code show correctly? At the moment when I click on the image it just opens in a new window, rather than in a lightbox.

The order of attributes in tags does not matter, so it's possible Firebug is rearranging them.  If you want to check HTML output, you should use the View -> Source option (not sure if View Selection Source is reliable or not).

As for why Lightbox isn't working, it could be a script error on the page?  Enable the Firebug console and see if it comes up with errors.
Thanks for the quick reply Zinga. I checked using view source and selection source and in both cases the HTML looked correct.

Code:
<div class="wikiimage"><a href="http://www.leefish.nl/mybb/wiki.php?file/how-to-make-ambtattoos/ambtattoo-tut-2.jpg" rel="lightbox"><img src="http://www.leefish.nl/mybb/wiki.php?file/how-to-make-ambtattoos/ambtattoo-tut-2.jpg" alt="" /></a><br /></div>


I have a hell of a lot of warnings on my page (yellow triangles) - mainly related to MYBB javascript, but no errors. I also have another lightbox running fine on the board - using that code, so it has to be something in the wiki tag set up.(I think).

I shall continue to nibble at it.

Reference URL's