DropDown Menu

You can easily add a beault (and CSS formatable) drop-down menu to a web with accessibility navegation based on a simple TWiki list.

Your menu HTML code will stay being a list of links (the best semantics for that). Good for google and other search bots, and good for text browsers. Some people need to navigate with the tab, because they are blind or has degenerative disease... this code enable to open sub-menus with tab focus.

Example


You only need a list. Better if it is a TWiki list. All list itens must be links, except the parents of the sub-menus like this:
<div id="some-id">
   * [[Link 1]]
   * Link 2
      * [[Link 2.1]]
      * [[Link 2.2]]
      * [[Link 2.3]]
   * Link 3
      * [[Link 3.1]]
      * Link 3.2
         * [[Link 3.2.1]]
         * [[Link 3.2.2]]
      * [[Link 3.3]]
</div>

This TWiki code makes the menu above as a big example (not realy useful):
<div id="menuTeste">
   * [[Web Home]]
   * TWiki Services
      * WebNotify
      * WebIndex
      * WebSearch
      * TWiki Groups
%SEARCH{ "TWiki"
         web="Main"
         topic="*Group"
         nonoise="on"
         limit="6"
         format="         * $web.$topic" }%
      * [[TWiki.TWikiRegistration][Registration]]
   * Admin Docs
%SEARCH{ "AdminDocumentationCategory"
         excludetopic="AdminDocumentationCategory"
         web="TWiki"
         nonoise="on"
         limit="6"
         format="      * $web.$topic"}%
   * [[Main.TWikiUsers][Users]]
</div>

You can see the real world using this hire: This websites are TWiki based and the site menu uses this DropDown Menu.

How to add the drop-down codebase?

To have a DropDown menu on your web add this two lines:

  • On your CSS:
    <style>
    (...)
    %INCLUDE{"Main.DropDownMenu" section="css" MENU_ID="your-menu-id"}%
    (and you can add more css for the menu hire, to make it personal)
    (...)
    </style>

  • Below your menu list:
    %INCLUDE{"Main.DropDownMenu" section="js" MENU_ID="your-menu-id"}%

If you already use prototype.js on your TWikiWeb template, you can set DO_NOT_LOAD_PROTOTYPE="on" in the %INCLUDE% to it do not load the script again.
%INCLUDE{"Main.DropDownMenu" section="js" DO_NOT_LOAD_PROTOTYPE="on" MENU_ID="your-menu-id"}%

How can i change the menu appearance?

Think in CSS ever.

All new repeated sets, resets the old set. So... Replace everything that you want by CSS after the %INCLUDE% section css.

Example:
<style> /* <pre> disable TWiki parser */

  body {
    color: #777;
    font-family: sans-serif;
  }

  %INCLUDE{"this topic" section="css" MENU_ID="menu"}%

  #menu ul ul a{
    padding: 3px 2px 3px 15px;
    background-color: #DCDCDC;
  }

  #menu ul ul a.linkSubMenu {
    color: red;
  }
  #menu ul ul a.linkSubMenu:hover {
    color: green;
  }

</style>

linkSubMenu is the class added to the link created to open the sub-menus.

Work around IE CSS bugs: If your personalization is getting some problem with IE, don't cry. The script add a msie class on the div parent of the menu list.

So, you cam make that:
  #menu {
    /* a code for all */
  }
  #menu.msie {
    /* a code replace for IE */
  }
And your CSS will not break the standards as the common CSS hacks.


Copying

This AddOn is a licenced in the GPL version 2 or (at your option) a later version.

When copy this to your TWiki, don't forget to copy the prototype.js attached in this topic or a newer version from http://www.prototypejs.org

-- Contributors: AurelioAHeckert - 29 Aug 2007


Source URL: TWiki:Plugins.DropDownMenuAddOn
Topic revision: r3 - 31 Aug 2007, AurelioAHeckert
 

This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Wiki-Colivre? Send feedback