2011-02-04, 04:41 PM
jQuery is cool. Fading is cool. Clutter most certainly is not. Add all these together and you come up with an elegant solution for displaying category descriptions. In this tutorial, I'll show you how to add fading category descriptions using jQuery.
First of all, why not take a look at what we'll be creating. You can do this by visiting my jsFiddle for it. Feel free to fork it, edit it, share it whatever you wish to it - it mainly existed for me to prototype my styling and html: http://jsfiddle.net/euantor/RLzMr/
Okay, so let's make a start. We first of all need to add jQuery if you don't already have it loaded. The best way to do this is to load it from google. It trims down your bandwidth usage and, chances are, google's servers are at least 9000 times better than yours. Head over to the Templates & Style section of the ACP and load up the headerinclude template for you theme. You can add the code wherever you like in here truth be told. I like to place it below the rest of the JS being initialised, so here we go:
Find:
After, add:
Right, step one done. Consider yourself maybe a third through the tutorial. Next step is to edit the forumbit_depth1_cat template. Load it up. In here, we're going to apply a few ID selectors and a few classes etc. This whole step could be entirely different for your theme. I'm writing from the perspective of editing the default theme.
Find:
Replace with:
That's our jQuery magic. No conflicts or errors. Just delicious jQuery goodness. You can, of course, style the description using the catdesc class. For example:
That's all there is to it. Simple, eh? This technique can, of course, be replicated for individual forum descriptions. I'll leave you to play with it on that front though
First of all, why not take a look at what we'll be creating. You can do this by visiting my jsFiddle for it. Feel free to fork it, edit it, share it whatever you wish to it - it mainly existed for me to prototype my styling and html: http://jsfiddle.net/euantor/RLzMr/
Okay, so let's make a start. We first of all need to add jQuery if you don't already have it loaded. The best way to do this is to load it from google. It trims down your bandwidth usage and, chances are, google's servers are at least 9000 times better than yours. Head over to the Templates & Style section of the ACP and load up the headerinclude template for you theme. You can add the code wherever you like in here truth be told. I like to place it below the rest of the JS being initialised, so here we go:
Find:
<script type="text/javascript" src="{$mybb->settings['bburl']}/jscripts/popup_menu.js?ver=1600"></script>
After, add:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
jQuery.noConflict();
jQuery(document).ready(function() {
jQuery(".catdesc").hide();
jQuery(".cattitle").live('mouseover mouseout', function(event) {
var catdesc = jQuery(this).parent().children('.catdesc');
var content = catdesc.text();
if (content !== "") {
if (event.type == 'mouseover') {
catdesc.fadeIn('slow');
} else {
catdesc.stop(true, true).fadeOut('slow');
}
}
});
});
</script>
Right, step one done. Consider yourself maybe a third through the tutorial. Next step is to edit the forumbit_depth1_cat template. Load it up. In here, we're going to apply a few ID selectors and a few classes etc. This whole step could be entirely different for your theme. I'm writing from the perspective of editing the default theme.
Find:
<div><strong><a href="{$forum_url}">{$forum['name']}</a></strong><br /><div class="smalltext">{$forum['description']}</div></div>
Replace with:
<span class="cattitle"><a href="{$forum_url}">{$forum['name']}</a></span>
<span class="catdesc smalltext">{$forum['description']}</span>
That's our jQuery magic. No conflicts or errors. Just delicious jQuery goodness. You can, of course, style the description using the catdesc class. For example:
.catdesc {
background: rgba(0, 0, 0, 0.5);
padding: 4px;
}
That's all there is to it. Simple, eh? This technique can, of course, be replicated for individual forum descriptions. I'll leave you to play with it on that front though