Class Banana.Control
Defined in: Control.js.
Constructor Summary
Method Summary
unload()
called just before destroying object Use this method to manualy destroy other objects i.e to prevent memory leaks
applyToChildren(fn)
getId()
getPage()
getProxy(fn)
This method is most useful for attaching event handlers to an element where the context is pointing back to a different object.
bind(name, func, data)
Binds an eventname to a method There are 2 types of events: Dom events: Events mostly fired from user actions like mouse click, keyup etc.
unbind(name, func)
Unbinds an eventname If funcion is given we unbind only when the bind matches the given function.
getHtml(markAsRendered)
returns html string of all child controls Note that Banana.Control type classes on it self won't get rendered.
Constructor Detail
new Banana.Control()
Base control class for component controls in Banana. Provides needed methods to function well in the Banana Hierarchy.
This control is suitable to use in your render hierarchy. Note that this control won't be
rendered. Possible child controls can have visually different parent controls
than the internal control collection would suggest.
Method Detail
createComponents()
This method is called by the page during creation of the control.
This is the place to define your control hierarchy.
Unlike the constructor (init) you have also access to properties
1. this.page - Reference to the page control
2. this.parent - Reference to the parent control
3. this.id - internal id
4. this.clientId - client id of the dom node
Except for these properties there is no difference. It doesn't really matters
if you create child controls in the init or in the createComponents methods.
Only if you need access to the parent or page control.
Or when you need to know what the id or client is.
You will find out that in most cases createComponents is the right place to do things.
Note: that createComponents is called only once. Rerendering doesn't result into a call
to createComponents
Another important note is that both init and createComponents methods are executed before
even one thing is rendered on your screen.The clientId is already known,
but you cannot access the dom node. To get access to the dom you need the updateDisplay() method.
updateDisplay()
The method is called by the page after the dom element is rendered.
If you want to add controls to the collection don't forget to invalidate by calling
invalidateDisplay()
unload()
called just before destroying object
Use this method to manualy destroy other objects i.e to prevent memory leaks
applyToChildren(fn)
Parameters:
{Function} | fn | function to apply to all children in control collection |
render(control)
forces control to be rendered. Only this function to bypass the page logic
i.e you want to render a control which is not part of a control hierarchy
Parameters:
{Banana.Control} | control |
getProxy(fn)
: Function
This method is most useful for attaching event handlers to an element
where the context is pointing back to a different object.
Parameters:
fn |
Returns:
{Function} | fn |
setParent(parent)
Sets reference to parent control. This method is automatically invoked during page construction
Parameters:
{Banana.Control} | parent |
addControl(String)
Adds a plaintext or a control to the control hierargy.
Adding control after render requires call to invalidateDisplay in order to get
the new control rendered visible
Parameters:
{mixed} | String | or Banana.Control |
findControl(id)
Recursively finds control
Parameters:
{String} | id | of the control |
Returns:
Banana.Control |
remove()
If control is part of a collection belonging to a page it has a page defined.
we let the page handle the removement of the control.
If it is a standalone control, we just unregister the events
TODO: should maybe also remove dom in the situation where control is not part of a collection
invalidateDisplay()
invalidates display. triggers the page to re-render node tree beginning from this control.
triggerEvent(name, params)
Triggers an event so all listeners are getting notified.
To start listening use the bind method. example:
someControl.bind('test',function(){});
To Trigger an event. example
someControl.triggerEvent('test',{data:'foo'});
Parameters:
{String} | name | of the event |
params |
bind(name, func, data)
: this
Binds an eventname to a method
There are 2 types of events:
Dom events: Events mostly fired from user actions like mouse click, keyup etc.
Custom events: These events are manually triggered by Banana components.
Important is that dom events are available after the control is rendered.
Custom events are registered instantly and available at all time.
Parameters:
{String} | name | of the event |
{Function} | func | callback function |
{mixed} | data | userdata |
Returns:
{this} | ; |
hasBind(name, func)
: boolean
Check wether a bind to a specific function in a control exists
Parameters:
{String} | name | of event |
{Function} | func |
Returns:
{boolean} |
unbind(name, func)
Unbinds an eventname
If funcion is given we unbind only when the bind matches the given function.
Otherwise we unbind all binds with the specified name regardless how many.
Parameters:
{String} | name | of event |
{Function} | func | optionaly |
getHtml(markAsRendered)
: String
returns html string of all child controls
Note that Banana.Control type classes on it self won't get rendered.
note Banana.control itself wont be rendered, but it chould contain child controls
which are from Banana.UiControl type
Parameters:
{boolean} | markAsRendered |
Returns:
{String} |
getFirstUiControl()
: Banana.Control
fetches the first parent control which is an instance of Banana.UiControl
Returns:
{Banana.Control} |