Methods
(static) build(el, menuopt) → {Element}
Builds a new menu pre-populated with items and groups.
This function creates a new pop-up menu (a.k.a. "drop-down"). This is a <select>...</select> element, pre-populated with items (<option>...</option> elements) and groups (<optgroup>...</optgroup> elements).
Bonus: This function also builds
input type=textelements. NOTE: This function generates OPTGROUP elements for subtrees. However, note that HTML5 specifies that OPTGROUP elemnents made not nest! This function generates the markup for them but they are not rendered by most browsers, or not completely. Therefore, for now, do not specify more than one level subtrees. Future versions of HTML may support it. I also plan to add here options to avoid OPTGROUPS entirely either by indenting option text, or by creating alternate DOM nodes using<li>instead of<select>, or both.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
el |
Element | string | Must be one of (case-sensitive):
|
||
menu |
Array.<menuItem> |
<optional> |
Hierarchical list of strings to add as |
|
options.prompt |
null | string |
<optional> |
'' | Adds an initial |
options.sort |
boolean |
<optional> |
Whether to alpha sort or not. If truthy, sorts each optgroup on its |
|
options.blacklist |
Array.<string> |
<optional> |
Optional list of menu item names to be ignored. |
|
options.breadcrumbs |
Array.<number> |
<optional> |
List of option group section numbers (root is section 0). (For internal use.) |
|
options.append |
boolean |
<optional> |
false | When |
Returns:
Either a <select> or <optgroup> element.
- Type
- Element
(static) formatItem(item) → {string}
Format item name with it's alias when available.
Parameters:
| Name | Type | Description |
|---|---|---|
item |
string | valueItem |
Returns:
The formatted name and alias.
- Type
- string
(static) lookup(optionsopt, value) → {undefined|menuItem}
Recursively searches the context array of menuItems for a named item.
This:
- Array
Parameters:
| Name | Type | Attributes | Description | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
<optional> |
Properties
|
|||||||||||||||
value |
string | Value to search for. |
Returns:
The found item or undefined if not found.
- Type
- undefined | menuItem
(static) walk(iteratee) → {number}
Recursively walks the context array of menuItems and calls iteratee on each item therein.
iteratee is called with each item (terminal node) in the menu tree and a flat 0-based index. Recurses on member with name of popMenu.subtree.
The node will always be a valueItem object; when a string, it is boxed for you.
This:
- Array
Parameters:
| Name | Type | Description |
|---|---|---|
iteratee |
function | For each item in the menu,
The
|
Returns:
Number of items (terminal nodes) in the menu tree.
- Type
- number