Code listing for xc.html
Create your menu as an unordered list in HTML.
This provides an accessible menu for everyone, without requiring support for
javascript or CSS. You can place this menu wherever you like in your webpage,
and use any CSS that you like to style it. Customers with support for CSS, but
not javascript, will see your styles.
You must give the menu and each ul
tag within the
menu an id (no other tag can have the same id in the webpage).
You must put titles on the menus (in the ul
tags).
Titles are used on the expanding controls to provide accessibility hints.
- <ul id="x">
- <li><a href="../" title="Javascript library">Javascript library</a>
- <ul id="js" title="Javascript">
- <li class="open"><a href="./">Expanding menu</a>
- <ul id="xc" title="Documentation for expanding menu">
- <li><a href="code/">HTML code</a></li>
- <li><a href="code/js.html">Javascript code</a></li>
- <li><a href="code/css.html">CSS code</a></li>
- </ul></li>
- <li><a href="../m/">Popup menu</a>
- <ul id="m" title="Documentation for popup menu">
- <li><a href="../m/code/js.html">Javascript code</a></li>
- </ul></li>
- <li><a href="../w/">Popup windows</a></li>
- <li><a href="../tp/">Tabbed panels</a>
- <ul id="tp" title="Documentation for tabbed panels">
- <li><a href="../tp/code/">HTML code</a></li>
- <li><a href="../tp/code/js.html">Javascript code</a></li>
- <li><a href="../tp/code/css.html">CSS code</a></li>
- </ul></li>
- </ul></li>
- <li><a href="/ben/resume/" title="Ben Boyle, Multimedia Developer | Resume">Author’s resume</a>
- <ul id="bboyle" title="Ben Boyle">
- <li><a href="/ben/resume/experience/programming/javascript.html">Javascript experience</a></li>
- <li><a href="/ben/resume/experience/internet/css.html">CSS experience</a></li>
- <li><a href="/ben/resume/experience/internet/xhtml.html">XHTML experience</a></li>
- <li><a href="/ben/resume/contact/">Contact email form</a></li>
- <li><a href="/ben/" title="Ben Boyle lives here!">Personal home page</a></li>
- </ul></li>
- </ul>
You must link to the xc.js file. This
contains all the javascript functions for controlling the menu. The stylesheet
controls the look and feel of the menu. You can use the
supplied css file, combine it with your own stylesheet,
or make up your own.
Place this code in the <head>
section of your webpage.
Only include the javascript file once, even if you have multiple menus
on the page. You can use multiple stylesheets if you wish, but there is no need
to repeat styles already defined.
- <link rel="stylesheet" type="text/css" href="/js/xc/xc.css" />
- <script type="text/javascript" src="/js/xc/xc.js"></script>
Setup the menu on a page by calling the xcSet
function.
This runs through the menu collapsing everything by default and adding the expanding
controls (see Output HTML below). If you need part of the menu to
remain expanded by default, you can use either of these options:
- list the
id
of that menu in the xcSet
function;
- place a class (any class) on the
<li>
tag for that menu
(note: the class will be changed to the class specified in xcSet
).
- <body onload="xcSet('x', 'xc', 'js');">
If you have more than one menu on the page, call xcSet
for each one.
- <body onload="xcSet('x', 'xc', 'js');xcSet('x2', 'xc');">
Output HTML
The expanding menu script alters the document to add expanding functionality.
Here is an example showing how the above menu would be transformed.
This is provided as a guide to the menu structure which is useful determining
how to apply styles to the menu.
- <ul id="x">
- <li class="xc"><div class="xcc"><a href="javascript:xcHide('js');" title="Javascript library (collapse menu)">[-]</a></div><a href="../" title="Javascript library">Javascript library</a>
- <ul id="js" title="Javascript">
- <li class="xc"><div class="xcc"><a href="javascript:xcHide('xc');" title="Documentation for expanding menu (collapse menu)">[-]</a></div><a href="./">Expanding menu</a>
- <ul id="xc" title="Documentation for expanding menu">
- <li><a href="code/">HTML code</a></li>
- <li><a href="code/js.html">Javascript code</a></li>
- <li><a href="code/css.html">CSS code</a></li>
- </ul></li>
- <li class="xc"><div class="xcx"><a href="javascript:xcShow('m');" title="Documentation for popup menu (collapse menu)">[+]</a></div><a href="../m/">Popup menu</a>
- <ul id="m" title="Documentation for popup menu">
- <li><a href="../m/code/js.html">Javascript code</a></li>
- </ul></li>
- <li><a href="w/">Popup windows</a></li>
- <li class="xc"><div class="xcx"><a href="javascript:xcShow('tp');" title="Documentation for tabbed panels (collapse menu)">[+]</a></div><a href="../tp/">Tabbed panels</a>
- <ul id="tp" title="Documentation for tabbed panels">
- <li><a href="../tp/code/">HTML code</a></li>
- <li><a href="../tp/code/js.html">Javascript code</a></li>
- <li><a href="../tp/code/css.html">CSS code</a></li>
- </ul></li>
- </ul></li>
- <li class="xc"><div class="xcx"><a href="javascript:xcShow('bboyle');" title="Ben Boyle (collapse menu)">[+]</a></div><a href="/ben/resume/" title="Ben Boyle, Multimedia Developer | Resume">Author’s resume</a>
- <ul id="bboyle" title="Ben Boyle">
- <li><a href="/ben/resume/experience/programming/javascript.html">Javascript experience</a></li>
- <li><a href="/ben/resume/experience/internet/css.html">CSS experience</a></li>
- <li><a href="/ben/resume/experience/internet/xhtml.html">XHTML experience</a></li>
- <li><a href="/ben/resume/contact/">Contact email form</a></li>
- <li><a href="/ben/" title="Ben Boyle lives here!">Personal home page</a></li>
- </ul></li>
- </ul>