Caplin Trader 5.1.0

Class: module:ct-menu/Control

module:ct-menu/Control(any, containerElement)

new module:ct-menu/Control(any, containerElement)

The Control will be in charge of rendering into the screen any module:ct-menu/Model. In order to do so, after constructing this class with the appropriate parameters, call module:ct-menu/Control#render. This class will be initially used to render module:ct-menu/model/Menu but any implementation of module:ct-menu/Model can be provided. See module:ct-menu/Control#addGenerator for details on how to extend the control's functionality.

Parameters:
Name Type Description
any module:ct-menu/Model

instance of Model.

containerElement HTMLElement

Container element.

Methods

addGenerator(generator, type)

This method is used as an extension point to the Control. It will allow you to define your own generators to render custom items. They will be linked by the item's type returned by module:ct-menu/Model#getType. This generators will need to implement module:ct-menu/Generator.

Parameters:
Name Type Description
generator module:ct-menu/Generator

Generator class which will render elements of the given type.

type String

String representation of the item type the generator registered will be in charge of rendering.

Throws:

If generator is not an instance of module:ct-menu/Generator.

Type
module:ct-core/Error

append(any, containerElement)

Extracts the DOM representation of the provided model and appends it to a container element. This is done by calling each of the model type generator's create method.

Parameters:
Name Type Description
any module:ct-menu/Model

instance of Model.

containerElement HTMLElement

Container element in which the menu will be rendered to.

Throws:

destroy()

Removes all the children nodes appended to the container and calls destroy in each of the registered controls.

getModel() → {Model}

Returns the current model for the menu.

Returns:
Type
Model

render()

Renders any module:ct-menu/Model onto the screen.

setAutoHide(autoHide)

Disable or enable the auto-hide functionality.

Parameters:
Name Type Description
autoHide Boolean

if true, enable auto-hiding this menu

setContainerElement(containerElement)

Allows you to set the container element in which the menu will be rendered.

Parameters:
Name Type Description
containerElement HTMLElement

The element in which the menu will be rendered.

Throws:

If containerElement is not a HTMLElement.

Type
module:ct-core/Error

setModel(model)

Allows you to set the model which will be rendered.

Parameters:
Name Type Description
model module:ct-menu/Model

Model to be rendered.

Throws:

If model is not an instance of module:ct-menu/Model.

Type
module:ct-core/Error