This reference describes the methods and fields available in jsDOMenu.
Create a new menu.
menuObj = new jsDOMenu(width, mode, id, alwaysVisible, className);
width - Required. Integer that specifies the width of the menu. Default unit is "px".
mode - Optional. String that specifies the mode of the menu. Defaults to "cursor". Allowed values are "cursor", "absolute", "fixed", and "static". If the mode = "static", you must also specify an unique id.
A menu is a cursor menu if any of the following is true:
A menu is an absolute menu if any of the following is true:
A menu is a fixed menu if any of the following is true:
A menu is a static menu if it is a main menu that is fixed at a particular position with respect to the document structure.
Do not confuse absolute menus with fixed menus. An absolute menu will move together with the page when you scroll. If you scroll up/down enough, it will be totally out of view. On the other hand, a fixed menu will not move with the page when you scroll. It will always be visible regardless of how much you scroll (provided it is positioned within the window when the page loads).
In addition, a static menu is fixed at a particular position with respect to the document structure, i.e. the position of the menu will "flow" with the document when the browser is resized. Thus, it is not required to call methods like setX(), moveTo(), etc to position the menu.
id - Optional, except when mode = "static". String that specifies the id of the element that will contain the menu. This argument is required when mode = "static". It is recommended that the element you specify is an empty DIV tag. For example:
<div id="staticMenu"></div>
Note that the id must be unique.
alwaysVisible - Optional. Boolean that specifies whether the menu is always visible. Defaults to false. If set to true, the menu will always be visible, unless you execute its hide() method to hide it.
className - Optional. String that specifies the CSS class selector for the menu. Defaults to "jsdomenudiv". The class selector "jsdomenudiv" is defined in the theme file, e.g. classic.css.
The method signature for this constructor has been changed compared with the previous version (v1.2.1).
You can access the HTML element object of the menu using the menuObj field. For example, menuObj.menuObj.style holds the style object of the HTML element.
Create a new menu item.
menuItemObj = new menuItem(displayText, itemName, actionOnClick,
enabled, className, classNameOver);
displayText - Required. String that specifies the text to be displayed on the menu item. If displayText is "-", a menu separator will be created instead.
itemName - Optional. String that specifies the name of the menu item. Defaults to "" (no name). You should set this argument only if you need to reference this menu item later on.
actionOnClick - Optional. String that specifies the action to be done when the menu item is being clicked. Defaults to "" (no action).
There are two types of actions allowed:
To distinguish between the two types, prefix "link:" or "code:" respectively to the value. For example, "code:alert('Hello World!');" instead "alert('Hello World!');". For links, prefixing "link:" is optional, as any prefix other than "code:" will be intepreted as a link.
enabled - Optional. Boolean that specifies whether the menu item is enabled/disabled. Defaults to true. The default value can also be set using "".
className - Optional. String that specifies the CSS class selector for the menu item. Defaults to "jsdomenuitem". The default value can also be set using "". The class selector "jsdomenuitem" is defined in the theme file, e.g. classic.css.
classNameOver - Optional. String that specifies the CSS class selector for the menu item when the cursor is over it. Defaults to "jsdomenuitemover". The default value can also be set using "". The class selector "jsdomenuitemover" is defined in the theme file, e.g. classic.css.
If you need to define any argument, you must also define the arguments before it. For example, if you need to define the third argument, but not the second, you still need to set the second argument to "" (default value).
The following codes are equivalent to the above:
menuItemObj = new menuItem(displayText);
menuItemObj.itemName = itemName;
menuItemObj.actionOnClick = actionOnClick;
menuItemObj.enabled = enabled;
menuItemObj.className = className;
menuItemObj.classNameOver = classNameOver;
You should only define the fields that need to be changed.
Add a new menu item to the menu.
menuObj.addMenuItem(menuItemObj);
menuItemObj - Required. Menu item that is going to be added to the menu.
You can access the HTML element object of the menu item using the items field. For example, menuObj.items["itemName"].style (or menuObj.items.itemName.style) holds the style object of the HTML element, where "itemName" is the value of itemName field of the menuItemObj added.
Set the class name of the menu.
menuObj.setClassName(className);
className - Required. String that specifies the CSS class selector for the menu.
The following code is equivalent to the above:
menuObj.menuObj.className = className;
Set the mode of the menu.
menuObj.setMode(mode);
mode - Required. String that specifies the mode of the menu. Allowed values are "cursor", "absolute", and "fixed".
If you change the mode of any menu, it is recommended that you change the mode of all its submenus as well.
Set whether the menu is always visible.
menuObj.setAlwaysVisible(alwaysVisible);
alwaysVisible - Required. Boolean that specifies whether the menu is always visible. If set to true, the menu will always be visible, unless you execute its hide() method to hide it.
The following code is equivalent to the above:
menuObj.menuObj.alwaysVisible = alwaysVisible;
Show the menu.
menuObj.show();
None
The following code is equivalent to the above:
menuObj.menuObj.style.visibility = "visible";
Hide the menu.
menuObj.hide();
None
-
Set the x-coordinate of the menu.
menuObj.setX(x);
x - Required. Integer that specifies the x-coordinate of the menu. Default unit is "px".
-
Set the y-coordinate of the menu.
menuObj.setY(y);
y - Required. Integer that specifies the y-coordinate of the menu. Default unit is "px".
-
Move the menu to the x-coordinate specified by the first argument and the y-coordinate specified by the second argument.
menuObj.moveTo(x, y);
x - Required. Integer that specifies the x-coordinate of the menu. Default unit is "px".
y - Required. Integer that specifies the y-coordinate of the menu. Default unit is "px".
-
Move the menu towards left by the amount specified by the first argument, and away from top by the amount specified by the second argument. If you want to move the menu towards right, or away from bottom, specify a negative value respectively.
menuObj.moveBy(x, y);
x - Required. Integer that specifies how much left/right the menu will move. Default unit is "px".
y - Required. Integer that specifies how much top/bottom the menu will move. Default unit is "px".
-
Set the filter such that the menu will show up only if the region that is being clicked/right clicked is not specified in the filter.
menuObj.setAllExceptFilter(filter);
filter - Required. Array that specifies the regions where the menu will not show up when clicked/right click. Each array element is made up of two parts, separated by ".". The first part is any HTML tag, the second part is the id of the tag. The "*" wildcard can be used.
For example:
filter = new Array("A.*", "IMG.*");
means that the menu will show up if the region that is being clicked/right clicked is not anchor tag (<a>) or image tag (<img>).
filter = new Array("*.nomenu");
means that the menu will show up if the region that is being clicked/right clicked is not having id = "nomenu".
filter = new Array("P.nomenu");
means that the menu will show up if the region that is being clicked/right clicked is not paragraph tag (<p>) having id = "nomenu".
The filter is case-insensitive. This method is used mainly for cursor menus. Calling this method will also reset the noneExceptFilter field to an empty array.
Set the filter such that the menu will show up only if the region that is being clicked/right clicked is specified in the filter.
menuObj.setNoneExceptFilter(filter);
filter - Required. Array that specifies the regions where the menu will show up when clicked/right click. Each array element is made up of two parts, separated by ".". The first part is any HTML tag, the second part is the id of the tag. The "*" wildcard can be used.
For example:
filter = new Array("A.*", "IMG.*");
means that the menu will show up only if the region that is being clicked/right clicked is anchor tag (<a>) or image tag (<img>).
filter = new Array("*.menu");
means that the menu will show up only if the region that is being clicked/right clicked is having id = "menu".
filter = new Array("P.menu");
means that the menu will show up if the region that is being clicked/right clicked is paragraph tag (<p>) having id = "menu".
The filter is case-insensitive. This method is used mainly for cursor menus. Calling this method will also reset the allExceptFilter field to an empty array.
Set the border width of the menu.
menuObj.setBorderWidth(width);
width - Required. Integer that specifies the border width of the menu. Default unit is "px".
This method may be deprecated in future versions. Therefore, try not to use it in this version.
It is recommended that you set the border width using stylesheet instead.
The following code is equivalent to the above:
menuObj.menuObj.style.borderWidth = width + "px";
Set the class name of the menu item.
menuObj.items["itemName"].setClassName(className);
className - Required. String that specifies the CSS class selector for the menu item.
The following code is equivalent to the above:
menuObj.items.itemName.setClassName(className);
Set the class name of the menu item when the cursor is over the menu item.
menuObj.items["itemName"].setClassNameOver(classNameOver);
classNameOver - Required. String that specifies the CSS class selector for the menu item when the cursor is over the menu item.
The following code is equivalent to the above:
menuObj.items.itemName.setClassNameOver(classNameOver);
This method is not available if the menu item is a menu separator.
Set the display text of the menu item.
menuObj.items["itemName"].setDisplayText(displayText);
displayText - Required. String that specifies the text to be displayed on the menu item.
The following code is equivalent to the above:
menuObj.items.itemName.setDisplayText(displayText);
This method is not available if the menu item is a menu separator.
Set the menu that will show up when the cursor is over the menu item.
menuObj.items["itemName"].setSubMenu(menuObj);
menuObj - Required. Menu that will show up when the cursor is over the menu item.
The following code is equivalent to the above:
menuObj.items.itemName.setSubMenu(menuObj);
This method is not available if the menu item is a menu separator.
Set the class name of the arrow.
menuObj.items["itemName"].setArrowClassName(className);
className - Required. String that specifies the CSS class selector for the arrow.
The following code is equivalent to the above:
menuObj.items.itemName.setArrowClassName(className);
This method is available only if the setSubMenu() method has been called to set a submenu for the menu item.
Set the class name of the arrow when the cursor is over the menu item.
menuObj.items["itemName"].setArrowClassNameOver(className);
className - Required. String that specifies the CSS class selector for the arrow when the cursor is over the menu item.
The following code is equivalent to the above:
menuObj.items.itemName.setArrowClassNameOver(className);
This method is available only if the setSubMenu() method has been called to set a submenu for the menu item.
Show the icon before the display text.
menuObj.items["itemName"].showIcon(className, classNameOver);
className - Required. String that specifies the CSS class selector for the icon.
classNameOver - Optional. String that specifies the CSS class selector for the icon when the cursor is over the menu item.
The following code is equivalent to the above:
menuObj.items.itemName.showIcon(className, classNameOver);
This method is not available if the menu item is a menu separator.
Set the class name of the icon.
menuObj.items["itemName"].setIconClassName(className);
className - Required. String that specifies the CSS class selector for the icon.
The following code is equivalent to the above:
menuObj.items.itemName.setIconClassName(className);
This method is available only if the showIcon() method has been called to show the icon before the display text.
Set the class name of the icon when the cursor is over the menu item.
menuObj.items["itemName"].setIconClassNameOver(classNameOver);
classNameOver - Required. String that specifies the CSS class selector for the icon when the cursor is over the menu item.
The following code is equivalent to the above:
menuObj.items.itemName.setIconClassNameOver(classNameOver);
This method is available only if the showIcon() method has been called to show the icon before the display text.
Method to call before creating the menus.
initjsDOMenu();
None.
This method is attached to the body tag (<body>) as a onload event handler. Therefore, you should not call this method again.
Method that contains the codes to create and customize the menus.
createjsDOMenu();
None.
This method is found in jsdomenu.inc.js. It will be called by the initjsDOMenu() method. Therefore, you should not call this method again.
Set the menu to be the pop-up menu.
setPopUpMenu(menuObj);
menuObj - Required. Menu that specifies the pop-up menu.
This method should be called only if you are using cursor menus.
Set how the pop-up menu is shown/hidden.
activatePopUpMenuBy(showValue, hideValue);
showValue - Required. Integer that specifies how the pop-up menu is shown.
hideValue - Required. Integer that specifies how the pop-up menu is hidden.
Allowed values for showValue/hideValue are:
Certain browsers (e.g. Opera) do not support the right click feature.
This method should be called only if you are using cursor menus.
Hide all menus, except those with alwaysVisible = true.
hideAllMenus();
None.
This method may be useful if you wish to control how the menus hide.
Hide all menus with mode = "cursor", except those with alwaysVisible = true.
hideCursorMenus();
None.
This method may be useful if you wish to control how the menus hide.
Hide all menus with mode = "absolute" or mode = "fixed", except those with alwaysVisible = true.
hideVisibleMenus();
None.
This method may be useful if you wish to control how the menus hide.
Hide the menu and all its submenus.
hideMenus(menuObj);
menuObj - Required. Menu that specifies the menu and all its submenus to be hidden.
This method may be useful if you wish to control how the menus hide.
You can define the following global public fields in jsdomenu.config.js to override the default values.
Array that specifies the regions where the menu will not show up if clicked/right clicked. Each array element is made up of two parts, separated by ".". The first part is any HTML tag, the second part is the id of the tag. The "*" wildcard can be used.
var allExceptFilter = new Array("A.*",
"BUTTON.*",
"IMG.*",
"INPUT.*",
"OBJECT.*",
"OPTION.*",
"SELECT.*",
"TEXTAREA.*");
If both allExceptFilter and noneExceptFilter are not empty, the value of allExceptFilter will be used.
Array that specifies the regions where the menu will show up if clicked/right clicked. Each array element is made up of two parts, separated by ".". The first part is any HTML tag, the second part is the id of the tag. The "*" wildcard can be used.
var noneExceptFilter = new Array();
If both allExceptFilter and noneExceptFilter are not empty, the value of allExceptFilter will be used.
String that specifies the CSS class selector for the menu.
var menuClassName = "jsdomenudiv";
The class selector "jsdomenudiv" is defined in the theme file, e.g. classic.css.
String that specifies the CSS class selector for the menu item.
var menuItemClassName = "jsdomenuitem";
The class selector "jsdomenuitem" is defined in the theme file, e.g. classic.css.
String that specifies the CSS class selector for the menu item when the cursor is over it.
var menuItemClassNameOver = "jsdomenuitemover";
The class selector "jsdomenuitemover" is defined in the theme file, e.g. classic.css.
String that specifies the CSS class selector for the menu separator.
var sepClassName = "jsdomenusep";
The class selector "jsdomenusep" is defined in the theme file, e.g. classic.css.
String that specifies the CSS class selector for the arrow.
var arrowClassName = "jsdomenuarrow";
The class selector "jsdomenuarrow" is defined in the theme file, e.g. classic.css.
String that specifies the CSS class selector for the arrow when the cursor is over it.
var arrowClassNameOver = "jsdomenuarrowover";
The class selector "jsdomenuarrowover" is defined in the theme file, e.g. classic.css.
String that specifies the default mode of the menus.
var menuMode = "cursor";
Allowed values are "cursor", "absolute", "fixed", and "static".
Integer that specifies the border width of the menu. Default unit is "px".
var menuBorderWidth = 2;
This field may be deprecated in future versions. Therefore, try not to use it in this version.
Safari will use the value of this field to render the menus when the page loads, and disregard the value set in the stylesheet. Other Gecko-based browsers like Mozilla Firefox or Microsoft Internet Explorer will use the value set in the stylesheet to render the menus when the page loads, and disregard the value of this field.
View the Example page to see a simple example of how to create jsDOMenu.
Compiled on 16 January 2005.
The latest version is available at http://www.tohzhiqiang.per.sg/projects/jsdomenu/docs/reference.php.