Class Banana.Control
Extends
Class.
Defined in: Control.js.
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.
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
- Parameters:
- {Function} fn
- function to apply to all children in control collection
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} ;
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
- this.page - Reference to the page control
- this.parent - Reference to the parent control
- this.id - internal id
- 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.
Recursively finds control
- Parameters:
- {String} id
- of the control
- Returns:
- Banana.Control
fetches the first parent control which is an instance of Banana.UiControl
- Returns:
- {Banana.Control}
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}
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
Check wether a bind to a specific function in a control exists
- Parameters:
- {String} name
- of event
- {Function} func
- Returns:
- {boolean}
invalidates display. triggers the page to re-render node tree beginning from this control.
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
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
Sets reference to parent control. This method is automatically invoked during page construction
- Parameters:
- {Banana.Control} parent
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
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