Manual Reference Source Test

Function

Static Public Summary
public

Q(s: Element | Node | String, e: Element | Node | String | ArrayObject): Collection | HtmlElement

The Q function can be used to create Elements, enhance nodes and query DOM or nodes.

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

hash(text: string): string

This function takes a string as argument and returns its hash.

version 1.0.0 since 1.0.0
public

load(Qname: string)

Load Elementify names exports into the global scope.

version 1.0.0 since 1.0.0
public

ready(callback: *): Promise

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

uniqid(prefix: string, moreEntropy: boolean): string

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.

Params:

NameTypeAttributeDescription
s Element | Node | String
  • optional

Element definition or search query

e Element | Node | String | ArrayObject
  • optional

Element options or search context

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:

NameTypeAttributeDescription
callback Function

Callback to be run when event fired

Return:

undefined | Promise

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

This function takes a string as argument and returns its hash.

Probavility of collision is rather high

Params:

NameTypeAttributeDescription
text string

Text to process

Return:

string

Hash

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:

NameTypeAttributeDescription
Qname string
  • optional
  • default: Q

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:

NameTypeAttributeDescription
callback *

Return:

Promise

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

This function returns a unique identifier

Params:

NameTypeAttributeDescription
prefix string
  • optional

Prefix to prepend

moreEntropy boolean
  • optional

Add more entropy to generator (slower)

Return:

string

Hash

See: