Show:

Namespace: utils

uijet. utils

Set a namespace on uijet for utility functions.

Methods

staticuijet.utils.async(f)

uijet.js, line 58

Utility for deferring a function by adding it to the process queue.

Name Type Description
f function

the function to defer.

staticuijet.utils.contains(a, b){boolean}

uijet.js, line 988

Checks if the first element contains the second element.

Name Type Description
a HTMLElement

container element.

b HTMLElement

contained element.

Returns:
- whether container contains contained.

staticuijet.utils.copy(source){Object}

uijet.js, line 357

Shallow (or deep) copy Objects (Arrays are shallow copied). If first argument is true then does a deep copy. First (or second if first is a Boolean) argument is the source object to copy from.

Name Type Description
source Object | boolean

the source object to copy or true for deep copying.

Returns:
copy object of source.

staticuijet.utils.Create(proto, _extends){function}

uijet.js, line 897

Creates a new class from a given prototype object or a constructor function, optionally inheriting the prototype/constructor _extends. Returns the created class constructor.

Name Type Description
proto function | Object

a constructor or an object to use as the top level prototype.

_extends function | Object optional

a constructor of a class to inherit from or simply an object to add to the prototype chain.

Returns:
new created class constructor.

staticuijet.utils.extend(target, source){Object}

uijet.js, line 320

Shallow (or deep) copy Objects (Arrays are shallow copied). If first argument is true then does a deep copy. First (or second if first is a Boolean) argument is the target object to copy to, all subsequent arguments are source objects to copy from. Objects are copied to target from left to right.

Name Type Description
target Object | boolean

the target object or true for deep copying.

source Object optional repeatable

the target object if deep copying or a source object(s).

Returns:
target object.

staticuijet.utils.extendProto(target, source){Object}

uijet.js, line 402

Deep copy (prototype) objects (Arrays are shallow copied), {@see extend}. If a property of same name exists in both source and target then if that property is:

  • Object: deep copy.
  • function: target method is wrapped to support a super call to the source method.
  • otherwise: shallow copy

First argument is the target object to copy to. All subsequent arguments are source objects to copy from. Objects are copied to target from left to right.

Name Type Description
target Object

the target object.

source Object optional repeatable

the source object(s).

Returns:
target object.

staticuijet.utils.extendProxy(target, source, context){Object}

uijet.js, line 439

Shallow copy properties while making sure functions are bound to context, {@see extend}. Usually used in {@see uijet.use}.

Name Type Description
target Object

target object to extend.

source Object

source object to copy from.

context Object optional

optional context object to bind Function properties to.

Returns:
target object.

staticuijet.utils.format(template, data){string}

uijet.js, line 209

Returns an interpolated string based on a given template, a string format pattern and a data context.

data can be either an Object, in which case replacement is done based on keywords matching, or an Array, in which replacement is done based on order.

The template format is {param} with no whitespace allowed inside.

Name Type Description
template string

template string to interpolate on.

data Object | Array.<string> optional

data context object to use as lookup for interpolation.

staticuijet.utils.getOffsetOf(child, parent){Object}

uijet.js, line 1004

Gets the offset of child relative to parent.

note: if child is not child of parent then the returned result will show only 0s.

Name Type Description
child HTMLElement

child element to get its offset.

parent HTMLElement

parent element to use as relative offset parent.

Returns:
- an object with x and y keys and Numbers as values representing offset in pixels.

staticuijet.utils.getPrefixed(name, obj){string|null}

uijet.js, line 73

Searches for a prefixed name of name inside obj.

Name Type Description
name string

Name to search for.

obj object

The source object search in.

Returns:
prefixed property or null if not found.

staticuijet.utils.getStyle(el, prop, pseudo, win){string|Array.<string>|CSSStyleDeclaration}

uijet.js, line 232

Gets the computed style object (CSSStyleDeclaration) of an HTMLElement el. If prop is supplied they return it's value. If a list of properties prop is supplied then return a corresponding list of values. An optional pseudo-element argument can be used to fetch its style. If the element is a decendent of a window object that isn't this global namespace you can supply that window object as fourth argument.

Name Type Description
el HTMLElement

the element to use.

prop string | Array.<string> optional

the property to fetch or list of properties.

pseudo string optional

a name of a pseudo-element of that element to get its style.

win HTMLWindowElement optional

The window element that element el belongs to.

Returns:
read-only style object of that element or the value[s] of that property[ies].

staticuijet.utils.getStyleProperty(prop, as_css_text){string|null}

uijet.js, line 931

Returns the specific name of a style property in the current user-agent, meaning, with the proper vendor prefix if needed and found. If there's no match, prefixed or not, returns null. Can also be used to check for the support of that CSS feature in current user-agent.

Name Type Description
prop string

an un-prefixed name of a style property.

as_css_text boolean

if true will return the property prefixed properly to be used as CSS text directly in a style declaration.

Returns:
- the matching name of this property for the current user-agent.

staticuijet.utils.isArr(obj){boolean}

uijet.js, line 115

Checks if given argument is an Array. Uses {@see Array.isArray} by default if it exists.

Name Type Description
obj *

target object to check.

Returns:
obj is an Array.

staticuijet.utils.isFunc(obj){boolean}

uijet.js, line 154

Checks if argument obj is an Function.

Name Type Description
obj *

target object to check.

Returns:
obj is an Function.

staticuijet.utils.isObj(obj){boolean}

uijet.js, line 143

Checks if given argument is an Object.

Name Type Description
obj *

target object to check.

Returns:
obj is an Object.

staticuijet.utils.parseRestUrl(url, context){Object}

uijet.js, line 271

Parses and formats a URL into an object containing method and path for making a proper RESTful request.

Name Type Description
url string | Object

The URL to use for the request or an Object in the form of { method: <method>, path: <path>}.

context Object optional

context object to use for formatting the URL.

staticuijet.utils.putMixin(array, name, position){Array.<string>}

uijet.js, line 1982

Makes sure a mixin's name is in the requested position of the returned array of mixin names.

Sometimes array could be an optional mixins option of some widget, in which case the author of the widget's prototype expects to get name wrapped in an Array. There's also a chance array could be another mixin's name, in which case it will be wrapped in an array and the operation is repeated.

Name Type Description
array Array.<string> | string | undefined

The list of mixin names.

name string

The name of the mixin to add.

position number optional

The index in which to place name in array or simply at its end.

Returns:
of mixin names.

staticuijet.utils.returnOf(arg, ctx){*}

uijet.js, line 258

Checks if given argument is Function, and either calls it with optional second argument as its context or simply returns it if it's not callable.

Any additional parameters after ctx are sent as arguments to call of arg.

Name Type Description
arg *

argument to check if callable and return its call or itself if not.

ctx Object optional

context object to use for the call.

Returns:
argument or its .call()'s product.

staticuijet.utils.toArray(obj){Array|undefined}

uijet.js, line 177

Utility for either wrapping an argument with an Array or return a copy of that array. If an array-like object is given then converts it into a plain Array. If the argument supplied is undefined or no arguments are supplied then returns undefined.

Name Type Description
obj *

target object to check.

Returns:
Array copy of obj or undefined.

staticuijet.utils.toElement(obj){*}

uijet.js, line 301

Normalizes obj into a wrapped DOM element object via the used DOM module, if it's either a string or an HTMLElement.

Name Type Description
obj string | HTMLElement

either a query string or an HTMLElement to wrap.

Returns:
wrapped object or simply obj.