Recall that makeElement() received a single argument when called for menu creation and two arguments for item creation. Our positioned elements are created on-the-fly using the Navigator new Layer() constructor. See column 10, Navigator Jigsaw Puzzle, for a detailed discussion. Suffice to say that it accepts up to two arguments. A mandatory first, integer, argument specifies the wrapping width of the new element. The second, optional argument, specifies the parent element of the new element. That is, the element that contains the new element.

Menus have no containing element. They are contained in the window object. Items are contained in menus. For the first time, in these columns, we use the arguments property of functions. arguments has only one property of its own, length, storing the number of arguments passed to the function. Using this property we can direct our functions to execute different statements depending on the number of arguments received. In our case, we check for a second argument. If none is found, we in effect create a second argument by assigning window to the whichContainer variable. Using the global menuWidth variable and the new whichContainer variable, we create a new positioned element. By using eval(), we create element references out of the element name strings passed as first arguments(whichEl). For example, if whichEl is the "elMenu1" string, makeExample() creates an element with a variable reference of elMenu1. This reference is then returned to the calling function (eg. makeTop()) to be used as an identifier.

Menu Setup

The menuSetup() function, a method of all menu elements, can have up to four arguments, the first two being mandatory. Top level menus pass only the first two, that is, hasParent and lastItem. (see previous page) Child menus pass two additional arguments, openCont and openItem, which designate the parent menu and parent item of the child. Since menuSetup() is a method of menu elements, the this keyword is used to refer to the calling element:

During the setup process, the menu element will be assigned properties, and more methods that use functions. We will go through the setup line-by-line, then look at the functions assigned to the new methods.

The menuOver() and menuOut() functions are assigned to the menuOver and menuOut methods of the menu. These methods are then assigned to the mouseover and mouseout event handlers of the menu. This technique assures that when the events occur the handler methods/functions immediately identify which elements called them.

Finally, the first passed argument is used. If the menu is a child menu, the first argument (hasParent) is true. In this case, a new property, hasParent is created to reflect this, and two other properties, parentMenu and parentItem store the menu and item elements that open the child menu. Finally, the child menu itself is assigned to the child property of its own parent item.

If the menu is top level, the hasParent property is set to false and the hideSelf() function is assigned to the menu's hideSelf method.

Are We Confused Yet?

Don't be. Once all our methods have been defined, and all the functions discussed, you will see how the actual execution and menu navigation become elementary to establish and follow. It is not necessary at this stage to know what each method does or what statements the functions contain. We've looked under the Christmas tree, found presents marked for distribution and we are distributing them. Once that is done, we will open them and find that all the parts of a train set are there and that they fit together nicely.