Namespace: Utils

WinJSContrib. Utils

Namespaces

ValueParsers

Methods

<static> alphabeticSort(a, b) → {number}

function to use as a callback for Array.sort when you want the array to be sorted alphabetically

Parameters:
Name Type Description
a string
b string
Source:
Returns:
Type
number

<static> applyValue(element, text, target, targetPath)

call resolve value and apply result to a target object

Parameters:
Name Type Description
element HTMLElement

DOM element to look

text string

expression like 'page:something' or 'ctrl:something' or 'something'

target string

target object

targetPath string

path to dest property

Source:

<static> distinctArray(array, path, ignorecase) → {Array}

generate an array with only distinct elements

Parameters:
Name Type Description
array Array
path string

to array's item property used for checking items

ignorecase boolean

indicate if comparison should ignore case when using string

Source:
Returns:
Type
Array

<static> ellipsisizeString(text, maxSize, useWordBoundary)

truncate a string and add ellipse if text if greater than certain size

Parameters:
Name Type Description
text string

text to truncate

maxSize number

maximum size for text

useWordBoundary boolean

indicate if truncate should happen on the closest word boundary (like space)

Source:

<static> endsWith(str, strToMatch) → {boolean}

indicate if string ends with featured characters

Parameters:
Name Type Description
str string

string to search within

strToMatch string

match string

Source:
Returns:

true if string starts with strToMatch

Type
boolean

<static> extend() → {Object}

extend an object with properties from subsequent objects

Source:
Returns:

composite object

Type
Object

<static> formatXHRError()

format error from an xhr call

Source:

<static> getDistinctPropertyValues(array, property, ignorecase)

get distinct values from an array of items

Parameters:
Name Type Description
array Array

items array

property string

property path for values

ignorecase boolean

ignore case for comparisons

Source:

<static> getParent(property, element) → {Object}

get parent control identifyed by a property attached on DOM element

Parameters:
Name Type Description
property string

property attached to control's DOM element, for ex: msParentSelectorScope

element HTMLElement

DOM element to scan

Source:
Returns:

WinJS control

Type
Object

<static> getParentControlByClass(className, element) → {Object}

get parent control identifyed by a css class

Parameters:
Name Type Description
className string

css class name

element HTMLElement

DOM element to scan

Source:
Returns:

WinJS control

Type
Object

<static> getParentPage(element) → {Object}

get parent page control (work only with WinJSContrib.UI.PageControlNavigator

Parameters:
Name Type Description
element HTMLElement

DOM element to scan

Source:
Returns:

WinJS control

Type
Object

<static> getProperty(source, properties) → {Object}

return a propery descriptor for an object based on expression

Parameters:
Name Type Description
source Object

the object containing data

properties string[]

property descriptor. could be a string in js notation ex: 'myProp.myChildProp, or an array of strings ['myProp', 'myChildProp']. String notation can contain indexers

Source:
Returns:

property descriptor

Type
Object

<static> getScopeControl(element) → {Object}

get parent scope control (based on msParentSelectorScope)

Parameters:
Name Type Description
element HTMLElement

DOM element to scan

Source:
Returns:

WinJS control

Type
Object

<static> getTemplate(template) → {Object}

get WinJS.Binding.Template like control from a path, a control, a function or a DOM element

Parameters:
Name Type Description
template Object

template input

Source:
Returns:

WinJS.Binding.Template or template-like object (object with a render function)

Type
Object

<static> guid() → {string}

generate a new Guid

Source:
Returns:
Type
string

<static> hasValue(item) → {Boolean}

Checks in a safe way if an object has a value, which could be 'false', '0' or '""'

Parameters:
Name Type Description
item Object

The object to check.

Source:
Returns:

Whether the object has a value or not.

Type
Boolean

<static> inherit(element, property)

inherit property from parent WinJS controls

Parameters:
Name Type Description
element HTMLElement
property string

property name

Source:

<static> inject()

inject properties from source object to target object

Source:

<static> moveChilds(source, target)

move DOM childrens form one node to the other

Parameters:
Name Type Description
source HTMLElement

source node containing elements to move

target HTMLElement

target node for moved elements

Source:

<static> pad2(number)

format a number on 2 digits

Parameters:
Name Type Description
number number
Source:

<static> queryStringFrom(obj) → {string}

generate a string formatted as a query string from object properties

Parameters:
Name Type Description
obj Object

object to format

Source:
Returns:
Type
string

<static> randomFromInterval(from, to) → {number}

generate a random value between two numbers

Parameters:
Name Type Description
from number

lower limit

to number

upper limit

Source:
Returns:
Type
number

<static> readProperty(source, properties) → {Object}

Read property value on an object based on expression

Parameters:
Name Type Description
source Object

the object containing data

properties Object

property descriptor. could be a string in js notation ex: 'myProp.myChildProp, or an array of strings ['myProp', 'myChildProp']. String notation can contain indexers

Source:
Returns:

property value

Type
Object

<static> removeAccents(s) → {string}

Remove all accented characters from a string and replace them with their non-accented counterpart for ex: replace "é" with "e"

Parameters:
Name Type Description
s string
Source:
Returns:
Type
string

<static> removePageFromHistory(pageLocation)

remove a page from navigation history

Parameters:
Name Type Description
pageLocation string

page url

Source:

<static> resolveMethod(element, text) → {function}

get a function from an expression, for example 'page:myAction' will return the myAction function from the parent page. The returned function will be bound to it's owner. This function relies on {link WinJSContrib.Utils.resolveValue}, see this for details about how data are crawled

Parameters:
Name Type Description
element HTMLElement

DOM element to look

text string

expression like 'page:something' or 'ctrl:something' or 'something'

Source:
Returns:
Type
function

<static> resolveValue(element, text) → {Object}

resolve value from an expression. This helper will crawl the DOM up, and provide the property or function from parent page or control.

Parameters:
Name Type Description
element HTMLElement

DOM element to look

text string

expression like 'page:something' or 'ctrl:something' or 'something'

Source:
Returns:
Type
Object

<static> startsWith(str, strToMatch) → {boolean}

indicate if string starts with featured characters

Parameters:
Name Type Description
str string

string to search within

strToMatch string

match string

Source:
Returns:

true if string starts with strToMatch

Type
boolean

<static> triggerCustomEvent(element, eventName, bubbles, cancellable)

Parameters:
Name Type Description
element HTMLElement

receiving the event

eventName string

name of the event

bubbles boolean

indicate if event should bubble

cancellable boolean

indicate if event can be cancelled

Source:

<static> triggerEvent(element, eventName, bubbles, cancellable)

trigger an event on a DOM node

Parameters:
Name Type Description
element HTMLElement

receiving the event

eventName string

name of the event

bubbles boolean

indicate if event should bubble

cancellable boolean

indicate if event can be cancelled

Source:

<static> unwrapJoinError(errorCallback) → {function}

Unwraps the real error from a WinJS.Promise.join operation, which by design returns an array with 'undefined' for all cells, excepts the one corresponding to the promise that really faulted.

Parameters:
Name Type Description
errorCallback function

The callback to use to handle the error.

Source:
Returns:

The result of the callback being fired with the real error.

Type
function

<static> writeProperty(source, properties, data)

Write property value on an object based on expression

Parameters:
Name Type Description
source Object

the object containing data

properties string[]

property descriptor. could be a string in js notation ex: 'myProp.myChildProp, or an array of strings ['myProp', 'myChildProp']. String notation can contain indexers

data Object

data to feed to the property

Source: