Module: Misc

Methods

(static) applyUrlSettings(opt_objopt, opt_argumentNameopt) → {Object}

Read settings from URL. Assume settings it a JSON like URL as in http://foo?settings={key:value}, Note that unlike real JSON we don't require quoting keys if they are alpha_numeric.

Parameters:
Name Type Attributes Description
opt_obj Object <optional>

object to apply settings to.

opt_argumentName String <optional>

name of key for settings, default = 'settings'.

Source:
Returns:

object with settings

Type
Object

(static) clamp(v, min, max) → {Number}

Clamp value

Parameters:
Name Type Description
v Number

value to clamp

min Number

min value to clamp to

max Number

max value to clamp to

Source:
Returns:

v clamped to min and max.

Type
Number

(static) clampPlusMinus(v, max) → {Number}

Clamp in both positive and negative directions. Same as clamp(v, -max, +max)

Parameters:
Name Type Description
v Number

value to clamp

max Number

max value to clamp to

Source:
Returns:

v clamped to -max and max.

Type
Number

(static) createTextNode(element) → {HTMLTextNode}

Inserts a text node into an element

Parameters:
Name Type Description
element HTMLElement

element to have text node insert

Source:
Returns:

the created text node

Type
HTMLTextNode

(static) degToRad(d) → {Number}

Convert degrees to radians

Parameters:
Name Type Description
d Number

value in degrees

Source:
Returns:

d in radians

Type
Number

(static) findCSSStyleRule(selector) → (nullable) {Rule}

finds a CSS rule.

Parameters:
Name Type Description
selector string
Source:
Returns:

matching css rule

Type
Rule

(static) getAbsolutePosition(element) → {Object}

Returns the absolute position of an element for certain browsers.

Parameters:
Name Type Description
element HTMLElement

The element to get a position for.

Source:
Returns:

An object containing x and y as the absolute position of the given element.

Type
Object

(static) invertPlusMinusRange(v, max) → {Number}

flips 0->max to max<-0 and 0->min to min->0 In otherwords max: 3, v: 2.7 = 0.3 max: 3, v:-2.7 = -0.3 max: 3, v: 0.2 = 2.8 max: 3, v:-0.2 = -2.8

Parameters:
Name Type Description
v Number

value to flip.

max Number

range to flip inside.

Source:
Returns:

flipped value.

Type
Number

(static) minToZero(v, min) → {Number}

Takes which ever is closer to zero In other words minToZero(-2, -1) = -1 and minToZero(2, 1) = 1

Parameters:
Name Type Description
v Number

value to min

min Number

min value to use if v is less then -min or greater than +min

Source:
Returns:

min or v, which ever is closer to zero

Type
Number

(static) parseUrlQuery(opt_objopt) → {Object}

Reads the query values from the current URL.

Parameters:
Name Type Attributes Description
opt_obj Object <optional>

Object to attach key values to

Source:
Returns:

Object with key values from URL

Type
Object

(static) parseUrlQueryString(url, opt_objopt) → {Object}

Reads the query values from a URL like string.

Parameters:
Name Type Attributes Description
url String

URL like string eg. http://foo?key=value

opt_obj Object <optional>

Object to attach key values to

Source:
Returns:

Object with key values from URL

Type
Object

(static) radToDeg(r) → {Number}

Converts radians to degrees

Parameters:
Name Type Description
r Number

value in radians

Source:
Returns:

r in degrees

Type
Number

(static) rand32BitColor({function(number):) → {string}

get a random 32bit color

Parameters:
Name Type Description
{function(number):

number?) opt_randFunc function to generate random numbers

Source:
Returns:

random 32bit color

Type
string

(static) randCSSColor({function(number):) → {string}

get a random CSS color

Parameters:
Name Type Description
{function(number):

number?) opt_randFunc function to generate random numbers

Source:
Returns:

random css color

Type
string

(static) randInt(value) → {number}

get a random int

Parameters:
Name Type Description
value number

max value exclusive. 5 = random 0 to 4

Source:
Returns:

random int

Type
number

(static) resize(canvas, useDevicePixelRationullable)

Resizes a cavnas to match its CSS displayed size.

Parameters:
Name Type Attributes Description
canvas Canvas

canvas to resize.

useDevicePixelRatio boolean <nullable>

if true canvas will be created to match devicePixelRatio.

Source:

(static) sign(v) → {Number}

Return sign of value

Parameters:
Name Type Description
v Number

value

Source:
Returns:

-1 if v < 0, 1 if v > 0, 0 if v == 0

Type
Number