Class: MenuBar

hcje/domTools.MenuBar(config)

Encapsulation of a DOM menu bar.

Constructor

Construct a menu bar. The opener and closer elements are added first followed by the children.

The structure generated by the code is effectively

  • div: className hcje-menu-bar-container
    • config.opener element
    • div className hcje-menu-bar
      • config.closer
      • config.children

Listeners are automatically added to the opener and closer to set the class of the menu bar container to 'open' when open. It is expected that the the display of these elements will be controlled by CSS.

There is no need to add the menu bar as this is done automatically in the constructor. It is either added to the config.parentElement or the document.body.

Parameters:
Name Type Description
config Object
Properties
Name Type Attributes Default Description
parentElement Element <optional>
document.body

The menu element is added to the parent

opener module:hcje/domTools.ElementWrapper | Element

Element used to open and close the menu bar.

closer module:hcje/domTools.ElementWrapper | Element

Element used to close the menu bar

children module:hcje/domTools.ElementWrapper | Element

Buttons to add to menu

onOpen function <optional>

Function called when menu opened via the opener.

onClose function <optional>

Function called when menu closed via the closer.

Source:

Members

onClose :function

Function called when menu closed.

Type:
  • function
Source:

onOpen :function

Function called when menu opened.

Type:
  • function
Source:

Methods

close()

Close the menu bar.

Source:

disable()

Disable the menu. The container has the disabled class set and all clicks are ignored.

Source:

enable()

Enabled the menu. The container has the disabled class removed and all clicks are activated.

Source:

remove()

Remove the menu.

Source:

setEnabledState(enabled)

Set the enabled state of the menu. If the state is false, all buttons are disabled and the menu is closed.

Parameters:
Name Type Description
enabled boolean

Required state.

Source: