jQuery dropdown menu in TYPOlight | qzminski Blog

jQuery dropdown menu in TYPOlight

Inspired by a post on the TYPOlight-community.org, I decided to write a tutorial that shows how to implement easy-to-use dropdown menu called Superfish. Similar navigation can be found on the polish TYPOlight support website.

Before we start, you need to know that the default javascript framework in TYPOlight is MooTools. The menu will not work unless you marry TYPOlight and jQuery.

Required file

First of all, you need to download the Superfish menu plugin from http://users.tpg.com.au/j_birch/plugins/superfish/#download.

File location

Extract the downloaded archive into /typolight_root/plugins/jquery/ and rename it to superfish so that it is /typolight_root/plugins/jquery/superfish. This folder should now have three sub folders: css, images and js.

Template change

Now let’s include css and js files. You can either modify fe_page.tpl file in /templates directory (just like in jQuery+TYPOlight tutorial) or use the field “Additional <head> tags” in page layouts in backend.

Add the following lines to your template:


<link rel="stylesheet" href="plugins/jquery/superfish/css/superfish.css" type="text/css" media="screen">
<!-- you don't need this line: -->
   <script type="text/javascript" src="http://code.jquery.com/jquery-latest.pack.js"></script>
<!-- if you followed previous tutorial -->
<script type="text/javascript" src="plugins/jquery/superfish/js/superfish.js"></script>
<script type="text/javascript">
   // initialise plugins
   jQuery(function(){
      jQuery('ul.level_1').addClass('sf-menu'); // apply demo's CSS
      jQuery('ul.level_1').superfish();
   });
</script>

Notice that the superfish is initialised on tag <ul class="level_1">, which is the top level of the menu.

Put the menu into the layout

All we have to do now is put the menu module into our website and see if it works.

Well, the submenu doesn’t actually show up. And that is because of the TYPOlight’s default css file that is included to every page.

CSS fix

The problem lies in /system/typolight.css file:

.block {
   overflow: hidden;
}

So it is necessary to put an additional CSS definition:

.mod_navigation {
   overflow: visible;
}

Now it should work.

The “Home” link is smaller than the others because of differences between template menu and superfish demo’s css.

We’re done!

That’s all. All you need to do now is to style this up. You might do it by editing the /system/plugins/jquery/superfish/css/superfish.css file or unlinking this file from the <head> tag and putting styles into your very own CSS files. Don’t forget to style the .active and .trail classes!

Good luck! ;)

Update @ 28th July 2010

I received several e-mails describing the problem with smaller “Home” link in the navigation. To fix it, you can either modify the nav_default.tpl template, or simply correct two lines in the superfish CSS file /system/plugins/jquery/superfish/css/superfish.css:

.sf-menu a, .sf-menu span {
  display: block;
  position: relative;
}

and

.sf-menu a, .sf-menu span {
  border-left: 1px solid #fff;
  /* etc. */
}

Contao’s default navigation template displays active item as a <span> tag, whereas normal item is displayed as a link <a>.


About Author

Kamil Kuzminski

Hi! I'm a webdeveloper from Olsztyn, Poland. I'm the manager of Contao (fka TYPOlight) polish support website and community. I work mainly as a freelancer for private clients or various agencies.





Comments

  1. Ben March 18th

    Comment Arrow

    Excellent post, Kamil! I’ve used FSMenu from http://www.twinhelix.com in TYPOlight a few times, but I’ve wanted to try the jQuery SuperFish menu. Thanks for putting together this tutorial!


  2. Martin March 30th

    Comment Arrow

    My superfish navi doesn’t work.
    When I include the overflow:auto into the typolight.css file the menu can’t be clicked anymore!
    Please help!
    Greets
    Martin


  3. Kamil Kuzminski March 30th

    Comment Arrow

    Could you provide a link to your website? What TYPOlight version are you using?


  4. Gary May 15th

    Comment Arrow

    Be, I also use FSMenu at the moment, is it worth changing to SuperFish?

    What are the benefits?

    Ta,

    Gary.


  5. Kamil Kuzminski May 15th

    Comment Arrow

    The main and biggest advantage is that Superfish is based on jQuery :)


  6. ilithya July 7th

    Comment Arrow

    Thanks for the great tutorial on installing Superfish.

    It has worked as a charmed in a website I’m developing, actually with the new CONTAO name, no longer Typolight.

    Just one question, I’m having some trouble when I apply the:
    overflow: visible

    I get circle bullets appearing on the left side of each of my menu main buttons. I tried applying “list-style-type:none;” but that seems not to work. Any ideas why I do get the bullets on the left side???

    If I don’t apply the overflow:visible, there are no bullets, but of course, as you display in here, I cannot see my submenu.


  7. ilithya July 7th

    Comment Arrow

    Hello, me again.

    Well, forget about my previous problem heheh.

    I realized it didn’t work, because I only applied the list-style-type before to my class.

    I had to do it to my class and ul list as this:
    #myclass ul li {
    list-style-type: none;
    }

    Thanks again, and happy coding!! =)


  8. Peter January 6th


  9. Cheers, Daniel June 29th

    Comment Arrow

    Hello. I have the same problem like Martin. After when I apply to .mod_navigation overflow:visible, menu is not clickable anymore.
    What can I do to fix this problem?
    Please, help me.
    I apply non-span a links in nav_default.tpl and it’s work fine.


  10. Cheers, Daniel June 29th

    Comment Arrow

    Described earlier problem came on free hosting’s services, where are advertising scripts from hosting. Tested on non-free hosting with positive results. Added scripts are the problem.


Add Yours

  • Author Avatar

    YOU


Comment Arrow