Constructor
new module:caplin/menu/Control(any, containerElement)
The
caplin.menu.Control
will be in charge of rendering into the screen any
module:caplin/menu/Model
. In order to do so, after constructing this class with the appropriate
parameters, call module:caplin/menu/Control#render
.
This class will be initially used to render module:caplin/menu/model/Menu
but any implementation of
module:caplin/menu/Model
can be provided. See module:caplin/menu/Control#addGenerator
for details
on how to extend the control's functionality.
Parameters:
Name | Type | Description |
---|---|---|
any |
module:caplin/menu/Model | instance of caplin.menu.Model. |
containerElement |
HTMLElement | Container element. |
Methods
-
addGenerator(generator, type)
-
This method is used as an extension point to the
caplin.menu.Control
. It will allow you to define your own generators to render custom items. They will be linked by the item's type returned bymodule:caplin/menu/Model#getType
. This generators will need to implementmodule:caplin/menu/Generator
.Parameters:
Name Type Description generator
module:caplin/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:caplin/menu/Generator
.
-
-
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:caplin/menu/Model instance of caplin.menu.Model. containerElement
HTMLElement Container element in which the menu will be rendered to. Throws:
-
-
If generator is not an instance of
module:caplin/menu/Model
.
-
-
-
If containerElement is not a HTMLElement.
-
-
-
If no generator exists for the provided model.
-
-
-
destroy()
-
Removes all the children nodes appended to the container and calls destroy in each of the registered controls.
-
getModel() → {caplin.menu.Model}
-
Returns the current model for the menu.
Returns:
- Type
- caplin.menu.Model
-
render()
-
Renders any
module:caplin/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.
-
-
setModel(model)
-
Allows you to set the model which will be rendered.
Parameters:
Name Type Description model
module:caplin/menu/Model Model to be rendered. Throws:
-
If model is not an instance of
module:caplin/menu/Model
.
-