Aleksandar • Vacić

iOS bits and pieces

Revised for versatility

I implemented AD xMenu on a few sites I was working on and realized that Hider feature could be usefull for any layer on the page, not just menu ones.

Therefore, I have moved the Hider feature to separate script.

I also extracted X functions from the original script - menu script uses almost dozen of them, and X lib will probably be used for some other DHTML scripts.

There are other improvements too…

Benefits from these changes are:

  • Hider feature can be used for any layer on the page

  • Menu script itself is much smaller. It can work by itself, without Hider script, thus making smaller download on pages where there’s no windowed controls.

Used functions from X are enlisted in the code, so either copy them or load the whole library. I recommend the second, since the library itself is not big, and I bet you’ll use it for something else.

Multiple menus

On a client (of the company I’m working for) web site, which uses a lot of DHTML, I quickly ran into the need for two menus on the same page: one for the main navigation and another for help navigation. So, on we go…

Changes were not huge. Instead of one global pointer

var ADXM_oMainMenu = null;

there’s an array of pointers, as well as global menu counter. Script below also shows how is array populated on window.onload.

var ADXM_nIndex = 0;

var ADXM_oMainMenu = new Array();


ADXM_oMainMenu[ADXM_nIndex] = xGetElementById(sMenuID);

Counter could also be removed, and the last line could be

ADXM_oMainMenu[ADXM_oMainMenu.length] = xGetElementById(sMenuID);

but I’m not the fun of cluttered code, so I will keep it clean and simple.

Each menu should have its own global HideMenus functions, as well as current menu pointer and timer for hiding. These are also added on window.onload

ADXM_oMainMenu[ADXM_nIndex].id = sMenuID;

ADXM_oMainMenu[ADXM_nIndex].timer = null;

ADXM_oMainMenu[ADXM_nIndex].curmenu = null;

Afterwards, processing function is called. That id parameter above is needed for HideMenus which is called in setTimeout statement, so I can’t pass an object to it. Again, xGetDocumentById comes to rescue, and recreates the main menu object.

Since all these changes came one at a time, menu version got up to 1.3. I just hope I will finish building this site before all this becomes obsolete…