Class
caplin.menu

Control

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

Constructor Summary

Attributes Name and Description
caplin.menu.Control(caplin.menu.Model any, HTMLElement containerElement)

Method Summary

Attributes Name and Description
void addGenerator(caplin.menu.Generator generator, String type)

This method is used as an extension point to the caplin.menu.Control.

void append(caplin.menu.Model any, HTMLElement containerElement)

Extracts the DOM representation of the provided model and appends it to a container element.

void destroy()

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

void render()

Renders any caplin.menu.Model onto the screen.

void setContainerElement(HTMLElement containerElement)

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

void setModel(caplin.menu.Model model)

Allows you to set the model which will be rendered.

Constructor Detail

caplin.menu.Control(caplin.menu.Model any, HTMLElement containerElement)

Parameters
caplin.menu.Model any instance of caplin.menu.Model.
HTMLElement containerElement Container element.

Method Detail

void addGenerator(caplin.menu.Generator generator, String 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 by caplin.menu.Model#getType. This generators will need to implement caplin.menu.Generator.

Parameters
caplin.menu.Generator generator Generator class which will render elements of the given type.
String type String representation of the item type the generator registered will be in charge of rendering.
Throws
caplin.core.Error
If generator is not an instance of caplin.menu.Generator.

void append(caplin.menu.Model any, HTMLElement containerElement)

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

Parameters
caplin.menu.Model any instance of caplin.menu.Model.
HTMLElement containerElement Container element in which the menu will be rendered to.
Throws
caplin.core.Error
If generator is not an instance of caplin.menu.Model.
caplin.core.Error
If containerElement is not a HTMLElement.
caplin.core.Error
If no generator exists for the provided model.

void destroy()

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

void render()

Renders any caplin.menu.Model onto the screen.

void setContainerElement(HTMLElement containerElement)

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

Parameters
HTMLElement containerElement The element in which the menu will be rendered.
Throws
caplin.core.Error
If containerElement is not a HTMLElement.

void setModel(caplin.menu.Model model)

Allows you to set the model which will be rendered.

Parameters
caplin.menu.Model model Model to be rendered.
Throws
caplin.core.Error
If model is not an instance of caplin.menu.Model.