The Component class is intended to be used as the base class for views you might create. It is also used as the base class for the BoundComponent class, which is nothing more than a small (one-element), one- or two-way bound view. The bulk of the class is in the constructor, which is described in a different api document. The rest is described here.
All components must implement IContent, which means they have a content property, representing the HTML content of the component.
If you are building a view, it is recommended that you implement IView, which means only that there is also a viewModel property.
Link to the demo scriptAPI
Code | Type | Detail |
---|---|---|
inject(selector = '[ichigo]', options?, constructor?) |
static method |
The inject method can be used to construct a single component (where it is not very useful) or multiple components from currently existing HTML elements.
|
content |
public field |
Every component has a content property, which references the physical footprint, in the HTML page, of
the component. The |
id {get; set;} |
public property |
This mirrors the id of the content element. |
innerHTML {get; set;} |
public property |
This mirrors the innerHTML of the content element. |
value {get; set;} |
public property |
If the content element is a form field, this gets and sets the field value, using whatever means is used by the element type (it varies). |
className {get; set;} |
public property |
This mirrors the className of the content element. |
classList {get;} |
public property |
This mirrors the classList of the content element. |
style {get;} |
public property |
This mirrors the style of the content element. |
addEventListener(eventType, event, options?): this |
public method |
This mirrors the addEventListener() method of the content element. |
addInlineEventListeners(componentFilter): this |
public method |
If called, this searches the content element for all elements having properties named i5_event, :event, or data-i5_event.
On these elements, it takes the attribute in parentheses (or underscores) as the event type and the value of that attribute as the method
to use. Then it calls addEventListener() using those details. For example,
Even though parentheses are legal fields for attributes, the setAttribute()/getAttribute() functions will choke on them. You may prefer |
append(child): this |
public method |
This mirrors the appendChild() method of the content element, except that child can also be a component. Fluent. |
appendChild(child) |
public method |
This mirrors the appendChild() method of the content element, except that child can also be a component. NOT fluent. |
appendToParent(parent): this |
public method |
This calls appendChild() on the parent, using the component content as the argument. The parent can also be a component. |
mapComponent(): this |
public method |
This adds the component to ComponentMap.components, a WeakMap that can get an added component class by looking up its content element. |
unmapComponent(): this |
public method |
This removes the component from ComponentMap.components. |
getAllChildComponents() |
public method |
This returns all components found within the content element, if they have been mapped. |
setStyle(style): this |
public method |
Sets style of the content element, except that this can also take an object of the format { "text-decoration": "wavy" }. |
addClass(class): this |
public method |
Adds to the classList of the content element. Takes either an array of class names or a space-delimited list. |
Type definitions