Function
Static Public Summary | ||
public |
Q(s: Element | Node | String, e: Element | Node | String | ArrayObject): Collection | HtmlElement The |
version 1.0.0 since 1.0.0 |
public |
Returns a promise fullfilled when document is at complete state meaning all assets have been loaded |
version 1.0.0 since 1.0.0 |
public |
This function takes a string as argument and returns its hash. |
version 1.0.0 since 1.0.0 |
public |
Load Elementify names exports into the global scope. |
version 1.0.0 since 1.0.0 |
public |
Returns a promise fullfilled when document is at interactive state meaning DOM is safe to manipulate |
version 1.0.0 since 1.0.0 |
public |
This function returns a unique identifier |
version 1.0.0 since 1.0.0 |
Static Public
public Q(s: Element | Node | String, e: Element | Node | String | ArrayObject): Collection | HtmlElement version 1.0.0 since 1.0.0 source
import Q from 'elementify/lib/query.js'
The Q
function can be used to create Elements,
enhance nodes and query DOM or nodes. It's the swiss army knife
of elementify
query syntax
Q
will returns an empty collection if
no elements are found with the given query. A single HtmLElement (or extended
Form, FormElement) if there is only one result and a collection if
there is more than one result.
In query mode, the first parameter must be a valid CSS query selector :
- #idname for single id search will trigger
getElementById
- .classname for single class search will trigger
getElementsByClassName
- @elementName for a single name attribute search will trigger
getElementsByName
- =tagName for a single tag name search will trigger
getElementsByTagName
Any others queries will be treated through querySelectorAll
. For single queries,
using the above functions will generally be faster than falling down to querySelectorAll
.
Q
tweaks the query so you can perform id or name search in nodes that are not in DOM.
The second parameter let restrict the search to a node.
Creating and enhancing syntax
If the first parameter is empty, Q
will return an HtmlElement with an
underlying DocumentFragment.
You can use Q
as an alias for [Element constructor]elementify.Element
with prepending a +
on the string node description or providing
a valid Element node created with document.createElement()
.
Any element node provided to Q
will be returned enhanced.
Any HtmlElement or Collection will be returned as is.
public complete(callback: Function): undefined | Promise version 1.0.0 since 1.0.0 source
import complete from 'elementify/lib/events/complete.js'
Returns a promise fullfilled when document is at complete state meaning all assets have been loaded
Params:
Name | Type | Attribute | Description |
callback | Function | Callback to be run when event fired |
Example:
// With promise
complete().then(function() { console.log('Assets loaded !') });
// With callback
complete(function() { console.log('Assets loaded !') });
Test:
public hash(text: string): string version 1.0.0 since 1.0.0 source
import hash from 'elementify/lib/utilities/hash.js'
This function takes a string as argument and returns its hash.
Probavility of collision is rather high
Params:
Name | Type | Attribute | Description |
text | string | Text to process |
public load(Qname: string) version 1.0.0 since 1.0.0 source
import load from 'elementify/lib/load.js'
Load Elementify names exports into the global scope. Therefore, these functions and objects will be directly accessible.
You can personnalize the name of the Q function (and may try $ ;)
Params:
Name | Type | Attribute | Description |
Qname | string |
|
See:
public ready(callback: *): Promise version 1.0.0 since 1.0.0 source
import ready from 'elementify/lib/events/ready.js'
Returns a promise fullfilled when document is at interactive state meaning DOM is safe to manipulate
Params:
Name | Type | Attribute | Description |
callback | * |
Example:
ready().then(function() { console.log('Can manipulate DOM!') });
Test:
public uniqid(prefix: string, moreEntropy: boolean): string version 1.0.0 since 1.0.0 source
import uniqid from 'elementify/lib/utilities/uniqid.js'
This function returns a unique identifier