Using a hybrid of Mike Hall‘s hierarchical menus, I’ve come up with a rather nifty method to accessify them.
The problem was that each submenu was held in a layer of it’s own, with no visual clue to what the relationship was between each layer and it’s companions. This was a problem especially for non-coding web designers – it should not be necessary that a web designer have to learn JavaScript in order to create a funky menu. Also, any menu created should have it’s meaning, use, and relationships clear to even a non-JavaScript browser.
So, the method I’ve come up with is to create the menu using a tree of unordered lists, such as this:
I then add the below line at the head of the document, and add class="magicmenutop" or class="magicmenuleft" to the root <ul>:
<script type="text/javascript" src="magicmenu.js"></script>
That script searches for the <ul> containing the magicmenu (left|right) class, and does some cool stuff to it.
The menu traverses the tree, replacing each level of the tree with a layer, in the manner that Mike Hall’s script understands.
A difficulty arose when I wrote the traversal algorithm. I decided to use a depth-first recursive method, as it was simplest, but quickly realised something I had only been peripherally aware of – JavaScript’s variable scopes suck! Essentially, a variable created in a JavaScript is global, so a recursive instance of the same function will destroy any copies of itself.
That was, of course, very vexing.
The solution was to create an external array holding the variables. The index of the array was pretty handy – the index of the layer that the algorithm was writing to at the time.
Another difficulty arose when it was pointed out to me that the script fscked up in Opera and IE. I can’t test IE yet (don’t have it at home), but downloaded Opera and worked on that.
It turns out that Opera does not understand the document.styleSheets collection, and all efforts to dynamically create document-wide styles failed. (the styles I’m talking about are the all-important positioning directives – I don’t mess with colours – leave that to the designers)
I ended up having to write the styles directly into each layer and link as I wrote it.
Long story short – I’m happy with it, and think it will make a formidibale tool. Must contact Mike and mention it to him.