wijmo Module

File
wijmo.js
Module
wijmo

Contains utilities used by all controls and modules, as well as the Control and Event classes.

Classes

Interfaces

Enums

Properties

Methods

Properties

culture

Gets or sets an object that contains all localizable strings in the Wijmo library.

The culture selector is a two-letter string that represents an ISO 639 culture.

Type
any

Methods

addClass

addClass(e: HTMLElement, className: string): void

Adds a class to an element.

Parameters
Returns
void

animate

animate(apply: Function, duration?: number, step?: number): number

Calls a function on a timer with a parameter varying between zero and one.

Use this function to create animations by modifying document properties or styles on a timer.

For example, the code below changes the opacity of an element from zero to one in one second:

var element = document.getElementById('someElement');
animate(function(pct) {
  element.style.opacity = pct;
}, 1000);

The function returns an interval ID that you can use to stop the animation. This is typically done when you are starting a new animation and wish to suspend other on-going animations on the same element. For example, the code below keeps track of the interval ID and clears if before starting a new animation:

var element = document.getElementById('someElement');
if (this._animInterval) {
  clearInterval(this._animInterval);
}
var self = this;
self._animInterval = animate(function(pct) {
  element.style.opacity = pct;
  if (pct == 1) {
    self._animInterval = null;
  }
}, 1000);
Parameters
Returns
number

asArray

asArray(value: any, nullOK?: boolean): any[]

Asserts that a value is an array.

Parameters
Returns
any[]

asBoolean

asBoolean(value: boolean, nullOK?: boolean): boolean

Asserts that a value is a Boolean.

Parameters
Returns
boolean

asCollectionView

asCollectionView(value: any, nullOK?: boolean): ICollectionView

Asserts that a value is an ICollectionView or an Array.

Parameters
Returns
ICollectionView

asDate

asDate(value: Date, nullOK?: boolean): Date

Asserts that a value is a Date.

Parameters
Returns
Date

asEnum

asEnum(value: number, enumType: any, nullOK?: boolean): number

Asserts that a value is a valid setting for an enumeration.

Parameters
Returns
number

asFunction

asFunction(value: any, nullOK?: boolean): Function

Asserts that a value is a function.

Parameters
Returns
Function

asInt

asInt(value: number, nullOK?: boolean, positive?: boolean): number

Asserts that a value is an integer.

Parameters
Returns
number

asNumber

asNumber(value: number, nullOK?: boolean, positive?: boolean): number

Asserts that a value is a number.

Parameters
Returns
number

assert

assert(condition: boolean, msg: string): void

Throws an exception if a condition is false.

Parameters
Returns
void

asString

asString(value: string, nullOK?: boolean): string

Asserts that a value is a string.

Parameters
Returns
string

asType

asType(value: any, type: any, nullOK?: boolean): any

Asserts that a value is an instance of a given type.

Parameters
Returns
any

changeType

changeType(value: any, type: DataType, format: string): any

Changes the type of a value.

If the conversion fails, the original value is returned. To check if a conversion succeeded, you should check the type of the returned value.

Parameters
Returns
any

clamp

clamp(value: number, min: number, max: number): number

Clamps a value between a minimum and a maximum.

Parameters
Returns
number

closest

closest(e: any, selector: string): Node

Finds the closest ancestor that satisfies a selector.

Parameters
Returns
Node

contains

contains(parent: any, child: any): boolean

Checks whether an HTML element contains another.

Parameters
Returns
boolean

copy

copy(dst: any, src: any): void

Copies properties from an object to another.

This method is typically used to initialize controls and other Wijmo objects by setting their properties and assigning event handlers.

The destination object must define all the properties defined in the source, or an error will be thrown.

Parameters
Returns
void

createElement

createElement(html: string, appendTo?: HTMLElement): HTMLElement

Creates an element from an HTML string.

Parameters
Returns
HTMLElement

enable

enable(e: HTMLElement, value: boolean): void

Enables or disables an element.

Parameters
Returns
void

escapeHtml

escapeHtml(text: string): void

Escapes a string by replacing HTML characters as text entities.

Strings entered by uses should always be escaped before they are displayed in HTML pages. This ensures page integrity and prevents HTML/javascript injection attacks.

Parameters
Returns
void

format

format(format: string, data: any, formatFunction?: Function): string

Replaces each format item in a specified string with the text equivalent of an object's value.

The function works by replacing parts of the formatString with the pattern '{name:format}' with properties of the data parameter. For example:

var data = { name: 'Joe', amount: 123456 };
var msg = wijmo.format('Hello {name}, you won {amount:n2}!', data);

The format function supports pluralization. If the format string is a JSON-encoded object with 'count' and 'when' properties, the method uses the 'count' parameter of the data object to select the appropriate format from the 'when' property. For example:

var fmt = {
    count: 'count',
    when: {
        0: 'No items selected.',
        1: 'One item is selected.',
        2: 'A pair is selected.',
        'other': '{count:n0} items are selected.'
    }
}
fmt = JSON.stringify(fmt);
console.log(wijmo.format(fmt, { count: 0 })); // No items selected.
console.log(wijmo.format(fmt, { count: 1 })); // One item is selected.
console.log(wijmo.format(fmt, { count: 2 })); // A pair is selected.
console.log(wijmo.format(fmt, { count: 12 })); 12 items are selected.

The optional formatFunction allows you to customize the content by providing context-sensitive formatting. If provided, the format function gets called for each format element and gets passed the data object, the parameter name, the format, and the value; it should return an output string. For example:

var data = { name: 'Joe', amount: 123456 };
var msg = wijmo.format('Hello {name}, you won {amount:n2}!', data,
    function (data, name, fmt, val) {
        if (wijmo.isString(data[name])) {
            val = wijmo.escapeHtml(data[name]);
        }
        return val;
    }
);
Parameters
Returns
string

getActiveElement

getActiveElement(): void

Gets a reference to the element that contains the focus, accounting for shadow document fragments.

Returns
void

getAggregate

getAggregate(aggType: Aggregate, items: any[], binding?: string): void

Calculates an aggregate value from the values in an array.

Parameters
Returns
void

getElement

getElement(selector: any): HTMLElement

Gets an element from a jQuery-style selector.

Parameters
Returns
HTMLElement

getElementRect

getElementRect(e: Element): Rect

Gets the bounding rectangle of an element in page coordinates.

This is similar to the getBoundingClientRect function, except that uses window coordinates, which change when the document scrolls.

Parameters
Returns
Rect

getType

getType(value: any): DataType

Gets the type of a value.

Parameters
Returns
DataType

getUniqueId

getUniqueId(baseId: string): string

Creates a new unique id for an element by adding sequential numbers to a given base id.

Parameters
Returns
string

getVersion

getVersion(): string

Gets the version of the Wijmo library that is currently loaded.

Returns
string

hasClass

hasClass(e: HTMLElement, className: string): boolean

Checks whether an element has a class.

Parameters
Returns
boolean

hasItems

hasItems(value: ICollectionView): void

Checks whether an ICollectionView is defined and not empty.

Parameters
Returns
void

hidePopup

hidePopup(popup: HTMLElement, remove?: boolean, fadeOut?: boolean): void

Hides a popup element previously displayed with the showPopup method.

Parameters
Returns
void

httpRequest

httpRequest(url: string, settings?: any): XMLHttpRequest

Performs HTTP requests.

Parameters
Returns
XMLHttpRequest

isArray

isArray(value: any): boolean

Determines whether an object is an Array.

Parameters
Returns
boolean

isBoolean

isBoolean(value: any): boolean

Determines whether an object is a Boolean.

Parameters
Returns
boolean

isDate

isDate(value: any): boolean

Determines whether an object is a Date.

Parameters
Returns
boolean

isFunction

isFunction(value: any): boolean

Determines whether an object is a function.

Parameters
Returns
boolean

isInt

isInt(value: any): boolean

Determines whether an object is an integer.

Parameters
Returns
boolean

isNullOrWhiteSpace

isNullOrWhiteSpace(value: string): boolean

Determines whether a string is null, empty, or whitespace only.

Parameters
Returns
boolean

isNumber

isNumber(value: any): boolean

Determines whether an object is a number.

Parameters
Returns
boolean

isObject

isObject(value: any): boolean

Determines whether a value is an object (as opposed to a value type, an array, or a Date).

Parameters
Returns
boolean

isPrimitive

isPrimitive(value: any): boolean

Determines whether an object is a primitive type (string, number, boolean, or date).

Parameters
Returns
boolean

isString

isString(value: any): boolean

Determines whether an object is a string.

Parameters
Returns
boolean

isUndefined

isUndefined(value: any): boolean

Determines whether an object is undefined.

Parameters
Returns
boolean

mouseToPage

mouseToPage(e: any): Point

Converts mouse or touch event arguments into a Point in page coordinates.

Parameters
Returns
Point

moveFocus

moveFocus(parent: HTMLElement, offset: number): void

Moves the focus to the next/previous/first focusable child within a given parent element.

Parameters
Returns
void

removeClass

removeClass(e: HTMLElement, className: string): void

Removes a class from an element.

Parameters
Returns
void

setAttribute

setAttribute(e: Element, name: string, value?: any): void

Sets or clears an attribute on an element.

Parameters
Returns
void

setCss

setCss(e: any, css: any): void

Modifies the style of an element by applying the properties specified in an object.

Parameters
Returns
void

setSelectionRange

setSelectionRange(e: HTMLInputElement, start: number, end?: number): void

Sets the start and end positions of a selection in a text field.

This method is similar to the native setSelectionRange method in HTMLInputElement objects, except it checks for conditions that may cause exceptions (element not in the DOM, disabled, or hidden).

Parameters
Returns
void

setText

setText(e: HTMLElement, text: string): void

Sets the text content of an element.

Parameters
Returns
void

showPopup

showPopup(popup: HTMLElement, ref?: any, above?: boolean, fadeIn?: boolean, copyStyles?: boolean): void

Shows an element as a popup.

The popup element becomes a child of the body element, and is positioned above or below a reference rectangle, depending on how much room is available.

The reference rectangle may be specified as one of the following:

HTMLElement
The bounding rectangle of the element.
MouseEvent
The bounding rectangle of the event's target element.
Rect
The given rectangle.
null
No reference rectangle; the popup is centered on the window.

Call the hidePopup method to hide the popup.

Parameters
Returns
void

toFixed

toFixed(value: number, prec: number, truncate: boolean): number

Rounds or truncates a number to a specified precision.

Parameters
Returns
number

toggleClass

toggleClass(e: HTMLElement, className: string, addOrRemove?: boolean): void

Adds or removes a class to or from an element.

Parameters
Returns
void

toHeaderCase

toHeaderCase(text: string): string

Converts a camel-cased string into a header-type string by capitalizing the first letter and adding spaces before uppercase characters preceded by lower-case characters.

For example, 'somePropertyName' becomes 'Some Property Name'.

Parameters
Returns
string

tryCast

tryCast(value: any, type: any): any

Casts a value to a type if possible.

Parameters
Returns
any