DomObserver
DOM Observer. It will observe DOM document for a configured element types and instantiate associated Types for an existing or newly added DOM elements
Example:
class ProgressBar {
constructor(options) {}
draw() {}
}
// It will observe DOM document for elements <div>
// having attribute 'data-type="progress"'
// and instantiate for each new instance of ProgressBar
new DomParser({color: 'red'}, 'div', 'progress', ProgressBar);
// assume we could have HTML like this
// <div data-type="progress" color="blue"></div>
// in this case all matching attributes names for a given options will be
// parsed and bypassed to an instance from HTML attributes
Static Method Summary
| Static Public Methods | ||
| public static |
Cross-browser DOM ready handler |
|
| public static |
parse(value: *): * Parses given attribute value to a proper JavaScript value. |
|
| public static |
toAttributeName(str: string): string Transforms camel case property name to dash separated attribute name |
|
| public static |
Transforms camelCase string to dashed string |
|
Constructor Summary
| Public Constructor | ||
| public |
constructor(options: object, element: string, type: string) |
|
Member Summary
| Public Members | ||
| public |
Actual type constructor to instantiate for each found element |
|
| public |
Name of an element to lookup/observe |
|
| public |
Flag specifies whenever the browser supports observing of DOM tree mutations or not |
|
| public |
Signals if mutations observer for this type or not |
|
| public |
Default instantiation options for the given type |
|
| public |
data-type attribute value to lookup |
|
Method Summary
| Public Methods | ||
| public |
isValidNode(node: Node | HTMLElement): boolean Checks if given node is valid node to process |
|
| public |
observe(records: MutationRecord[]) Observes given mutation records for an elements to process |
|
| public |
process(node: Node | HTMLElement): GaugeInterface | null Processes a given node, instantiating a proper type constructor for it |
|
| public |
traverse() Traverse entire current DOM tree and process matching nodes. |
|
Static Public Methods
public static domReady(handler: Function): * source
Cross-browser DOM ready handler
Params:
| Name | Type | Attribute | Description |
| handler | Function |
Return:
| * |
public static parse(value: *): * source
Parses given attribute value to a proper JavaScript value. For example it will parse some stringified value to a proper type value, e.g. 'true' => true, 'null' => null, '{"prop": 20}' => {prop: 20}
Params:
| Name | Type | Attribute | Description |
| value | * |
Return:
| * |
Public Constructors
Public Members
Public Methods
public isValidNode(node: Node | HTMLElement): boolean source
Checks if given node is valid node to process
Params:
| Name | Type | Attribute | Description |
| node | Node | HTMLElement |
public observe(records: MutationRecord[]) source
Observes given mutation records for an elements to process
Params:
| Name | Type | Attribute | Description |
| records | MutationRecord[] |
public process(node: Node | HTMLElement): GaugeInterface | null source
Processes a given node, instantiating a proper type constructor for it
Params:
| Name | Type | Attribute | Description |
| node | Node | HTMLElement |
public traverse() source
Traverse entire current DOM tree and process matching nodes. Usually it should be called only once on document initialization.