Chapter 4. One Last Look at Joomla! jQuery Modules

"Last but not least!"

This is the last chapter in which we are going to look at third party modules. After this we will start working on our own template modification, modules, and so on. Though I know that these are very interesting topics, I want to show you some things before I proceed. But don't worry, these will be interesting as well. In this chapter, we will see:

  • The limitations of Joomla! menus
  • How to create a drop-down menu with CSS alone
  • jQuery powered Joomla! menu modules
  • Creative ways of placing logging modules in our site

Interesting, isn't it? Let's start.

Limitations of Joomla! menu modules

By default, we have some interesting options when creating menus for our site—be it vertical menus or horizontal ones. This, mixed with the always useful CSS, will help us create very interesting menus for our site.

However, we face some limitations when working with menus, for example, drop-down menus. Though this can be achieved for sure, it's not as straightforward as we think it is. Take for example our template menu shown in the following screenshot:

Limitations of Joomla! menu modules

It has worked for now. However, imagine that you want to convert the News menu into a drop-down menu, so that when a visitor moved his or her mouse pointer over it a structure like the following will be seen:

  • News
    • News 1
    • News 2
    • News 3
    • News 4

First, we need to go to our administrator screen. For this example you can use any menu you want, but I am going to use the Main Menu.

Go to Menus | Main Menu; here you will see something similar to the following screenshot:

Limitations of Joomla! menu modules

We only need to add some extra menu entries under the News menu. Click on New | Articles | Article Layout; in the screen that opens, near the top right-hand corner, you will see the Parameters (Basic) zone. Click on the Select button, and then select the News 1 article, or any other article of your liking (as shown in the next screenshot):

Limitations of Joomla! menu modules

Once you have this selected, you need to give the rest of the details (placed to the left-hand side), such as:

  • Title—I'm going to enter News 1, but you can name it the way you want.
  • Alias—again, I'm entering News 1 here.
  • Link—should be filled if you have selected the article.
  • Display in—is where we can select in which menu this new menu entry will appear. The default Main Menu will work for us.
  • Parent Item—is the important part; here you will choose under which option this new entry will appear. This time, it will be placed under the News menu.

After making these changes, you will see something similar to the following screenshot:

Limitations of Joomla! menu modules

Repeat the process a few more times so that we have an interesting structure to work with. After all, we need some elements to put in our drop-down menu. When you have finished, and before going to the frontend to see the result of your work, you need to perform one little change in the Main Menu module.

In order to do this, we will go to the Extensions | Module Manager menu. Here, you will click on the Main Menu link. Check the Parameters zone; you need to modify the parameter as shown in the following screenshot:

Limitations of Joomla! menu modules

That's it, we need to change the Always show sub-menu items parameter to Yes. If you do so, in the frontend, you will see the sub-menu items. If we leave this parameter set to No, the sub-menu items will only appear if its menu item is selected. In your case that would be the News menu.

Let's take a look at the frontend:

Limitations of Joomla! menu modules

Here we can see the result of our work. I've tried to highlight all of the menus so that you can see the effect. And because of the change we made in the module configuration, the submenus are shown even if we don't visit the News menu.

We are also seeing the limitations of our work. By default, Joomla! is not going to do anything else for us. So our work starts now.

Creating a drop-down menu with CSS alone

As we have seen in our previous image, for now, our menu is quite limited. The submenus are appearing just under their menus, but they don't really look quite good.

If we want to convert this unfinished menu into a working drop-down menu, we can use a lot of possibilities. We will be able to do it with CSS, a bit of JavaScript, or by using Joomla! extensions—and maybe I'm missing out some other way as well.

To start with, we are going to try it with CSS alone. Let's check the source code generated for our menu. It will look similar to the following:

<div id="mainmenu">
                        <ul class="menu">
                        <li id="current" class="active item1"> <a href="http://wayofthewebninja.com/"><span>Home</span></a></li>
                        <li class="parent item2"> <a href="/index.php?option=com_content&amp;view=category&amp; layout=blog&amp;id=1&amp;Itemid=2"><span>News</span></a>
                        <ul>
                        <li class="item4"> <a href="/index.php?option=com_content&amp;view=article&amp; id=2&amp;Itemid=4"><span>News 1</span></a></li>
                        <li class="item5"> <a href="/index.php?option=com_content&amp;view=article&amp; id=3&amp;Itemid=5"><span>News 2</span></a></li>
                        <li class="item6"> <a href="/index.php?option=com_content&amp;view=article&amp; id=4&amp;Itemid=6"><span>News 3</span></a></li>
                        <li class="item7"> <a href="/index.php?option=com_content&amp;view=article&amp; id=7&amp;Itemid=7"><span>News 4</span></a></li>
                        </ul>
                        </li>
                        <li class="item3"> <a href="/index.php?option=com_content&amp;view=article&amp; id=9&amp;Itemid=3"><span>Code highlight</span></a></li>
                        </ul>
                        </div><!-- End of mainmenu -->
                    

Let's summarize this code so that we can see the important parts of it. Look closely:

<ul>
                        <li>Menu 1
                        <ul>
                        <li>Submenu 1</li>
                        <li>Submenu 2</li>
                        <li>Submenu 3</li>
                        <li>Submenu 4</li>
                        </ul>
                        </li>
                        </ul>
                    

Now we can see the structure more easily, and we can also see that it includes an unordered list nested within another one. With this structure we are able to create a CSS drop-down menu with very little code.

Oh, I know I told you that we will start coding in the next chapter, but let's take this as a small introduction. Open the templates/jj15/css/styles.css file, and add the following code at the end:

/**
                        * CSS dropdown styles
                        */
                        ul.menu {
                        padding: 0;
                        margin: 0;
                        list-style: none;
                        }
                        ul.menu li {
                        float: left;
                        position: relative;
                        }
                        ul.menu li ul {
                        display: none;
                        position: absolute;
                        top: 25px;
                        left: 0;
                        z-index: 102;
                        }
                        ul.menu li ul li {
                        background-color: #4C4841;
                        padding: 4px;
                        padding-left: 10px;
                        width: 75px;
                        border: 1px solid #5B5751;
                        }
                        ul.menu li:hover ul {
                        display: block;
                        }
                    

Tip

You can find this code within the css_dropdown_1.txt file in the code bundle for Chapter 4 of the book.

Most of this code is only there to position the submenus under their menus, and also to give some color to the submenu elements. The important parts are as follows:

ul.menu li ul {
                        display: none;
                    

This code hides the submenu, so we can't see it. But then we have the following code:

ul.menu li:hover ul {
                        display: block;
                        }
                    

This code makes the menus visible when the mouse pointer is over the Main Menu. An image is better than a thousand words, so let's take a look at the result (as seen in the following screenshot):

Creating a drop-down menu with CSS alone

Tip

Why don't you try this out on your own? This way you can see it in action.

Our menu now has a nice drop-down effect, and we have been able to accomplish it with only a bit of CSS. We can group our menus into drop-down menus to organize them better. But we have some limitations here:

  • With the current code, we are able to nest only one sublevel. For example, if News 2 has other menus inside, such as News 2.1 and News 2.2, our CSS won't work for it.
  • This code may not work in old browsers, such as IE 6, because it can't have the :hover pseudo class in elements other than links. As we have used it on a li element, it won't work.

All of these problems can be solved with some coding. For example, we can follow the guidelines found at the following links:

There's lot more out there. However, once we have seen an easy and fast way to have drop-down menus on standard compliant browsers, I think our next best step will be to use a Joomla! extension to create our menus.

jQuery-powered Joomla! menu modules

Using a Joomla! module for creating our menus has some benefits that must be taken into account. For example, they have some nice effects, such as fade effects, shadows, and many more.

These effects can make our site look a bit more appealing. They can also solve the problems that we have previously found, such as the menu not working in other browsers or the number of sublevels we are able to have.

With all this in mind we are going to see the Superfish Dropdown Menu. Search for it on the JED by that name, or find it at the following URL:

http://extensions.joomla.org/extensions/structure-a-navigation/menu-systems/drop-a-tab-menus/6731

As the module description itself states on this page, it's based on the Suckerfish-style menu—yes, the one we have been using in our CSS example—but this time with some jQuery added to it and all put into a Joomla! module.

Once we have downloaded it, our next step will be to go to the administrator screen of our site. Then go to Extensions | Install/Uninstall. Here, after selecting the file, click on the Upload file & Install button.

Hopefully, the extension will be installed without problems and you will find it in Extensions | Module Manager.

As this module will substitute our current Main Menu module, we need to disable the Main Menu module, and enable the Superfish Menu module as shown in the following screenshot:

jQuery-powered Joomla! menu modules

After doing so, you can click on the Superfish Menu. Do so now, and look at the parameters found in it, as shown in the next screenshot:

jQuery-powered Joomla! menu modules

There are still more parameter's in the module, but we will start with the following ones:

  • Menu Name—indicates the name of the menu to be used by the module. For now, we only have the mainmenu, so we have very little choice!
  • Menu Style—provides quite a good range of options, such as Horizontal, Vertical, Nav-Bar, and Accordion List. For our example, we are going to need the Horizontal option.
  • Animation—provides another good range of effects from slide to fade, or even both the effects together. This option doesn't really matter in our example, so choose any effect that you want.
  • Animation Speed—is a parameter that will let us select the speed of the animation. This can be done by entering slow, fast, def, or the time in milliseconds in this field. For now, we will leave this parameter at its default value.
  • mouseOut Delay—is an interesting parameter, which helps us define the time that elapses between the mouse leaving the menu, and the menu disappearing.
  • Hover Class—is the CSS class that will be used when the mouse pointer is over the menu options.
  • Path Class—is the CSS class that will be used for active elements in our menu.
  • Path Levels—is the parameter that defines the number of menu levels that will remain active when we select the Nav-Bar style for our menu.
  • Auto Arrows—will automatically add arrows to menus that contain submenus if we select Yes.
  • Drop Shadows—is a nice effect that adds a good looking shadow to our menus; we will select Yes.
  • Add clearing DIV—is used if you have been having problems with the menu—template problems I mean. Maybe it's because of the floating elements used with the menu; therefore, adding a clearing DIV may help. Our template doesn't have such problems, so we can leave this parameter set to No.

We have configured quite a few parameters, but before seeing our menu in action we need to do something more. At the very bottom of the parameters we can see the options for the jQuery library:

jQuery-powered Joomla! menu modules
  • Load jQuery—at this point in time we are already loading the jQuery library, so it's not necessary to load it again; select No here.
  • Use No Conflict Mode—we can leave this option as Yes without problems.

We are almost done now, and only a few parameters need to be changed—the ones in the Details part, to the left-hand side—as we can see in the following screenshot:

jQuery-powered Joomla! menu modules

Here we need to perform some minor changes. The Title is not so important, as we are selecting No in Show Title. Of course, we need to enable the module if we haven't done so before. And last, but not least, is the module Position. For our current template and example, we are going to select the menu position of our template.

And that's all; we can save our changes and take a look at the frontend. If all has gone OK, and hopefully it has, we will be able to see something similar to the following screenshot:

jQuery-powered Joomla! menu modules

I know, I know, this needs some styling, but I just wanted you to see the result of our work. We can also comment on the benefits of this module over our previous CSS-only version. For example, and to name only some of them:

  • It adds an arrow where submenus are present, so visually we know where more menus are expected to appear.
  • The submenus don't disappear when the mouse pointer is not over them. Instead we can define for how much time the submenus will wait. This is especially useful for visitors with some difficulties.
  • The effects, though not necessary, can make visiting our site more interesting.

Adapting the menu to suit our template

Now that we have our menu working, we are going to make the styling more in consonance with our template. Don't worry, this part will be easy, and more fun I think.

First open the templates/jj15/css/styles.css file and remove all of the styles that we placed before. These are all the styles that were placed under this comment:

/**
                            * CSS dropdown styles
                            */
                        

This way we will start working from the ground up with our new styles. Now if we take a look at our source code, we can see a code similar to the following:

<div id="mainmenu">
                            <ul class="menu sf-menu sf-horizontal">
                            <li id="current" class="first-child active item1"><a href="http://wayofthewebninja.com/"><span>Home</span></a></li>
                            <li class="parent item2"><a href="/index.php?option=com_content&amp;view=category&amp; layout=blog&amp;id=1&amp;Itemid=2"><span>News</span></a>
                            <ul>
                            <li class="first-child item4"><a href="/index.php?option=com_content&amp;view=article&amp; id=2&amp;Itemid=4"><span>News 1</span></a></li>
                            <li class="item5"><a href="/index.php?option=com_content&amp;view=article&amp; id=3&amp;Itemid=5"><span>News 2</span></a></li>
                            <li class="item6"><a href="/index.php?option=com_content&amp;view=article&amp; id=4&amp;Itemid=6"><span>News 3</span></a></li>
                            <li class="last-child item7"><a href="/index.php?option=com_content&amp;view=article&amp; id=7&amp;Itemid=7"><span>News 4</span></a></li>
                            </ul>
                            </li>
                            <li class="item3"><a href="/index.php?option=com_content&amp;view=article&amp; id=9&amp;Itemid=3"><span>Code highlight</span></a></li>
                            <li class="last-child item8"><a href="/index.php?option=com_content&amp;view=article&amp; id=10&amp;Itemid=8"><span>Flicker</span></a></li>
                            </ul>
                            </div><!-- End of mainmenu -->
                        

As we can see, it's mostly the same code that we have before installing the menu module. We have the two nested lists. However, some classes have been added, and this is great because this gives us more control when styling.

Note that some of these styles make mention of child elements, such as first-child, last-child, and so on. Child elements are elements that are inside another element. So the first-child would be the first element found inside the other element and the last-child would be the last.

This differentiation makes it easier to style elements; we can take advantage of these new classes.

But first, let's return to our administrator screen. Go to Extensions | Module Manager, and click on the Superfish Menu. We need to add something to the module parameters. Once in the module's admin screen, look for the Custom Styling parameter. It looks similar to the following screenshot:

Adapting the menu to suit our template

This parameter lets us add our custom CSS stylesheet. This way we don't need to modify module files, and we can create our own file. This file will prevail upon the module CSS files. For example, I've put in the following parameter:

{mostemplate}/css/menu.css
                        

First save this change. Then we need to create the menu.css file in templates/jj15/css. Create the file and open it; we are going to add the following styles to it:

.menu{
                            margin-top: -3px;
                            margin-left: -15px;
                            }
                        

This is only to move the menu a bit. Now add the background colors, borders, and so on, of the first-level li elements:

.menu li{
                            background-color: #938F89;
                            border: 1px solid #211F1B;
                            }
                            .menu li a{
                            border-top: 1px solid #DEDEDE;
                            border-left: 1px solid #DEDEDE;
                            }
                        

For the second-level li elements add the following styles:

.menu li ul li{
                            background-color: #938F89;
                            border: 1px solid #211F1B;
                            }
                            .menu ul li li a{
                            border-top: 1px solid #DEDEDE;
                            border-left: 1px solid #DEDEDE;
                            }
                        

For the current active menu add the following styles:

#current a{
                            background-color: #9A0000;
                            color: #ffffff;
                            font-weight: bold;
                            border-top: 1px solid #D70000;
                            border-left: 1px solid #D70000;
                            }
                        

And lastly, for the hovering elements add the following styles:

.sf-menu a:focus, .sf-menu a:hover, .sf-menu a:active {
                            background: #000000;
                            }
                        

With all these changes, our menu will look more or less as follows:

Adapting the menu to suit our template

Much better now, isn't it? With very little effort our menu looks a lot better. Of course, this module has many other options, so why don't you give it a try? This is an extension that we could always use to modify and try out options, or to just play with it!

Tip

You can find the code for this example inside the css_dropdown_2.txt file in the code bundle for Chapter 4 of the book.

Some more extensions to try

Though this menu module can be a great solution for our site, there are also some other great extensions that we can use in other projects. We can find them by searching the JED:

  • FishEye Menu For Joomla 1.5—generates icon menus. When you hover the mouse pointer over the elements, the icons get bigger. I think this can be quite useful in some templates.
  • HxD MooMenu—is similar, in concept, to the module that we have been using. However, it uses MooTools instead of jQuery— it's just a question of personal taste.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.50.156