DHTML Menu Builder [DynAPI 1.1]
<developers_edition>
Tuesday May 20, 2008

 

 

WARNING: The information on this documentation will change as the development on this version of DHTML Menu Builder progresses.
It is VERY important that you always refer to the information provided in this document prior to testing new versions of the DynAPI code.


Helper Functions

objtid dmbAPI_parseArray(MenuID, ParentID, Caption, [URL], [TargetFrame], [ToolbarIndex])


Description

One of the most complex tasks when using the DynAPI is populating the menus, that is, creating the menus' structure.
Up until now, you required to use long sequences of calls to functions such as dmbAPI_addGroup, dmbAPI_addCommand, dmbAPI_addTBItem and many others -- these functions had to be called in a very specific order and you were required to save values returned by some of the functions and then be passed to the consequent functions... in the end, the process was quite cumbersome.

DynAPI 10.j introduces a new function called "dmbAPI_parseArray". This function will take as its main argument the information about a menu items and the function will automatically create the required menu structure for you.
Having this function will also simplify the creation of menu items from data stored on a database.

Let's consider this menu structure:

Sample menu structure
  • Home
  • Products
    • DHTML Menu Builder
    • KeyLaunch
    • SoftLeds
  • Contact Us

Without using the new dmbAPI_parseArray function you would have to use a code like this to produce such structure:

Code sample
var id;
dmbAPI_addTBItem(1, "Home");
id = dmbAPI_addTBItem(1, "Products");
dmbAPI_addGroup("grpProducts");
dmbAPI_addCommand("grpProducts", "DHTML Menu Builder");
dmbAPI_addCommand("grpProducts", "KeyLaunch");
dmbAPI_addCommand("grpProducts", "SoftLeds");
dmbAPI_setOnMouseOver(id, "grpProducts", null, true, 0);
dmbAPI_addTBItem(1, "Contact Us");

And here's the code that produces the same results by using the dmbAPI_parseArray function:

Code sample
dmbAPI_parseArray(1, 0, "Home");
dmbAPI_parseArray(2, 0, "Products");
dmbAPI_parseArray(21, 2, "DHTML Menu Builder");
dmbAPI_parseArray(22, 2, "SoftLeds");
dmbAPI_parseArray(23, 2, "KeyLaunch");
dmbAPI_parseArray(3, 0, "Contact Us");

As you can see, the code is considerably simpler and with just a single function (instead of having to call three different functions as in the previous sample) you can construct any type of menu structure.
Also, this function is extremely versatile and it will let you combine standard DynAPI functions with it allowing you, at any time, change the style of a particular menu item, or perform any of the more advance tasks supported by other DynAPI functions.

The returned id can be used with all functions that expect a parameter type of 'objid'.
Click here to see a sample using the "traditional method" and then click here to see how the same menus can be generated using the dmbAPI_parseAttay function. Then, compare both samples and you will notice the huge reduction in code when using the dmbAPI_parseArray function.

For more information, please see the Introduction to the DynAPI tutorial available here.

Parameters

MenuID (string/integer) This is a unique identifier for this menu item. It can either be a number or a string.
ParentID (string/integer) This is the unique identifier that refers to the parent menu item from which this item depends. If this is a top-level item (that is, a toolbar item) set this parameter to 0 or to an empty string.
Caption (string) This parameter specifies the caption (or text) for the menu item.
URL (string) This parameter is optional but when used specifies the link to which this menu item will redirect the browser when clicked.
TargetFrame (string) This parameter is optional but when used, specifies the target frame where the link should be opened. By default, this parameter is set to "_self".
ToolbarIndex This parameter is options and defaults to the first toolbar in the project. If required, it can be passed to specify a different toolbar in case the project contains multiple toolbars.