App.Utils

App.Utils

App.Utils contains a variety of utility functions.

Methods

(static) autoSize(element, container, options)

Adjusts the size of a element based on the size of its container. Css options provided will be modified based on ratio,

Parameters:
Name Type Description
element Object

to apply text auto size to

container HTMLElement

to base the size on

options Object

Css options to be set with a ratio as a value

(static) booleanize(source) → {Promise}

Resolves the input promises into a promise which resolve true or false e.g. App.Utils.booleanize(promise1, promise2)

Parameters:
Name Type Description
source Promise

promise

Returns:

Returns promise which resolve true or false

Type
Promise

(static) convertHtmlToPlainText(htmlString) → {string}

Convert a HTML string to plain text.

Parameters:
Name Type Description
htmlString string
Returns:

str

Type
string

(static) defaultIfUndefined(value, defaultValue) → {*}

Checks the value if it is defined or not. If it is defined returns the value otherwise returns defaultValue

Parameters:
Name Type Description
value *

the value to check

defaultValue *

the default value which is returned if the value is undefined

Returns:

value if it is defined, defaultValue otherwise

Type
*

(static) encodeUri(component) → {string}

Parameters:
Name Type Description
component
Returns:
Type
string

(static) equalsIgnoreCase(the, the) → {boolean}

Compares two strings ignoring case

Parameters:
Name Type Description
the string

first value in the comparison

the string

second value in the comparison

Returns:

true if passed in values are equal, false otherwise

Type
boolean

(static) escapeHTML(value) → {string}

escape html specific characters

Parameters:
Name Type Description
value string

value to be escaped

Returns:

escaped string value

Type
string

(static) execFunction(functionName, win, context, args) → {Any}

Executes a function with arguments. Supports functions in name spaces, e.g. App.custom.sortChart()

Parameters:
Name Type Description
functionName String | function

Name of function or function to execute

win Object

Window object

context Object

Context for function (Optional)

args Object

Arguments sent to function (Optional)

Returns:

Returns whatever

Type
Any

(static) fixHTML(htmlString) → {string}

Automatically close open HTML tags in htmlString - from https://stackoverflow.com/a/31485232

Parameters:
Name Type Description
htmlString string

htmlString to be balanced with opened and closed tags

Returns:

Corrected htmlString with any opened element tags closed

Type
string

(static) getPublisher()

Returns the message publisher.

(static) getPublishFunction()

Returns the publish function to publish the message.

(static) getTargetOrigin()

Returns the target origin in cross domain.

(static) getValidDomIdentifier(str) → {string}

Gives a string replacing all invalid html class/id characters by '-'.

Parameters:
Name Type Description
str string
Returns:

str

Type
string

(static) is3DDashboard()

Checks if helium is loaded in 3DDashboard

  • @return {boolean}

(static) isAnyUndefined(…values) → {boolean}

Returns false if any of the provided value is undefined

Parameters:
Name Type Attributes Description
values string <repeatable>

values to check

Returns:
Type
boolean

(static) isCrossDomain()

Returns true or false if not able access window.top.TVCbroker

(static) isDefined(value) → {boolean}

Checks to see if a value is defined or not

Parameters:
Name Type Description
value *

the value to check

Returns:

boolean, true if passed in value is defined, false otherwise

Type
boolean

(static) isEnoviaId(content) → {boolean}

Checks to see if the input value matches Enovia Id pattern

Parameters:
Name Type Description
content

content to match

Returns:

true if pattern matches EnoviaId, false otherwise

Type
boolean

(static) isFirefox() → {boolean}

Checks whether the browser is Firefox

Returns:

true if browser is Firefox, false otherwise

Type
boolean

(static) isIEorEdge() → {boolean}

Checks whether the browser is IE or Edge

Returns:

true if browser is IE, false otherwise

Type
boolean

(static) isNullOrUndefined(value) → {boolean}

Checks to see if a value is null or undefined

Parameters:
Name Type Description
value

the value to check

Returns:

true if passed in value is undefined or null, false otherwise

Type
boolean

(static) isObject(value) → {boolean}

Checks to see if a value is of type object

Parameters:
Name Type Description
value *

the value to check

Returns:

boolean, true if passed in value is of type object, false otherwise

Type
boolean

(static) isObjectEmpty(obj) → {boolean}

Checks to see if object is empty or not

Parameters:
Name Type Description
obj *

the object to check

Returns:

boolean, true if object is Empty, false otherwise

Type
boolean

(static) isSafari() → {boolean}

Checks whether the browser is Safari

Returns:

true if browser is Safari, false otherwise

Type
boolean

(static) isTouchDevice() → {boolean}

Checks to see if application is running on touch device or not.

Returns:

true if device is touch screen, false otherwise

Type
boolean

(static) isTruncated() → {boolean}

Checks whether element is truncated

Returns:

true if element is truncated false otherwise

Type
boolean

(static) isUndefined(value) → {boolean}

Checks to see if a value is defined or not

Parameters:
Name Type Description
value

the value to check

Returns:

true if passed in value is undefined, false otherwise

Type
boolean

(static) isUndefinedOrNull(value) → {boolean}

Checks to see if a value is undefined/null or not

Parameters:
Name Type Description
value

the value to check

Returns:

true if passed in value is undefined/null, false otherwise

Type
boolean

(static) objToString(object, operatoropt, delimiteropt) → {string}

Convert JSON object into string

Parameters:
Name Type Attributes Default Description
object Object

JSON object

operator String <optional>
'='

operator used between key and value

delimiter String <optional>
','

delimeter used in between object entries

Returns:

string representaion on input JSON object

Type
string

(static) openExternal(options) → {Window}

Opens a new window based on the supplied arguments.

  • The option object passed in must contain an url and a name property.
  • If the passed in options object contains an params property those properties will be appended to the url.
  • If the passed in options object contains an windowFeatures property those properties will be used
  • when the new window is created. Valid window features can be found here.
Example
App.Utils.openExternal({
"url": "http://google.com",
"name": "Google",
"params": {"q": "test"},
"windowFeatures":  "menubar=no,location=no,resizable=no,scrollbars=yes,status=yes"});
Parameters:
Name Type Description
options Object

Options to be used when opening the new window.

Returns:

window Reference to the opened window object

Type
Window

(static) openObject(objectId, href, targetLocation)

Opens the object based on the view it is being opened from. In case of embeded mode it will route emxTree.jsp, for standalone mode it will page mapped in Helium.xml, for 3DDashboard it publishes the subscribed widget

Parameters:
Name Type Description
objectId String

objectId of the object

href String

href for embeded mode

targetLocation String

when routing to emxTree, if the object needs to be opened in content or popup

(static) preferredLanguage() → {string}

Returns preferred browser language

Returns:

browser preferred language

Type
string

(static) preserveNewLine(value, escapeHTML) → {string}

preserve new line/escape HTML characters

Parameters:
Name Type Description
value string

value to be escaped

escapeHTML boolean

to escape html specific characters

Returns:

preserved string value

Type
string

(static) publishMessage(params, target)

Publish message to parent using postMessage or tvcBroker

Parameters:
Name Type Description
params Object

parameters

target Object

target

(static) publishObject(objectId)

In 3DDashboard we can publish the subscribed widgets

Parameters:
Name Type Description
objectId String

objectId of the object

(static) reloadWindowHref()

Reloads the document

(static) startsWith(haystack, needle, position) → {boolean}

Checks if a string starts with another

Parameters:
Name Type Description
haystack String

String to search in

needle String

The string to look for

position Integer

The position in haystack to start searching, defaults to 0

Returns:

boolean true if needle is found, false otherwise

Type
boolean

(static) stopEvent(event)

Cancels a cancelable event

Parameters:
Name Type Description
event

the cancelable event itself

(static) stopKeyEvent(event, blackListedKeysopt)

Conditionally cancels a key event (keyup, keypress, keydown etc)

Parameters:
Name Type Attributes Description
event

the cancelable event itself

blackListedKeys <optional>

Array of keynames that should lead to event canceled. See App.Constants.EventKeys

(static) stringToColor(text) → {string}

unique hex color code by looking up color getVCal or by generating new one

Parameters:
Name Type Description
text string

string value

Returns:

hsl color code

Type
string

(static) stringToFloat(value, defaultValueopt) → {number}

Parses string into Float number with base 10

Parameters:
Name Type Attributes Description
value

value to be parsed

defaultValue <optional>

default value if passed in value is invalid

Returns:
Type
number

(static) stringToFunction(functionName,, win) → {function}

Returns a function based on the passed in string, supports namespaces, e.g App.custom.sortChart();

Parameters:
Name Type Description
functionName, String

Name of the function

win Object

Window object

Returns:

the found function

Type
function

(static) stringToNumber(value, defaultValueopt) → {number}

Parses string into number with base 10

Parameters:
Name Type Attributes Description
value

value to be parsed

defaultValue <optional>

default value if passed in value is invalid

Returns:
Type
number

(static) triggerWindowResize()

Trigger resize event on window

(static) validateStringBadChars(string, badChars) → {boolean}

Checks if a string contains any bad characters

Parameters:
Name Type Description
string String

String to validate

badChars String

String of bad characters (Optional) defaults to bad characters set in tvc

Returns:

true if string is valid

Type
boolean

(static) vibrate(milliSecopt)

Performs vibration of the device if supported

Parameters:
Name Type Attributes Default Description
milliSec number | Array.<number> <optional>
200

time for which the device should vibrate