Class: Utils

Utils

Utility methods.

new Utils()

Methods

_num(len){string}

Generate GUID with numeric characters.
Name Type Description
len number Length of the generated GUID

_v4(){string}

Generate GUID with alphanumeric characters (v4 format).

addCallbackEvent(func)

Add callback event
Name Type Description
func function function to execute

addEvtListener(obj, event, callback)

Add an event listener to an object.
Name Type Description
obj object DOM Element on which you want to add the event listener
event string Event you need to listen
callback function When event is triggered, it takes one parameter which is the event object

arrayIndexOf(arr, elemToSearch){number}

Search an element in an array. Use Array.indexOf if possible.
Name Type Description
arr Array
elemToSearch *

cloneSimpleObject(inst, delUndefined){object}

Copy an object which doesnt' contain functions/objects.
Name Type Description
inst object Item that you want to clone
delUndefined boolean If true, undefined properties are not cloned
Returns:
clone of the instance

completeFstLevelObj(target, source, overload){object}

Complete the first level of an object with another.
Name Type Description
target object
source object
overload boolean If true, properties of the target will be overloaded by source ones if they exist

dispatchCallbackEvent(name)

Dispatch event for callbacks
Name Type Description
name string Callback's name

getObjectKeys(object){Array}

Get all keys from object.
Name Type Description
object object

hashcode(str){number}

Make a unique number with a given string.
Name Type Description
str

isPrerender(callback){boolean}

Check if we are in Chrome or IE prerendering case.
Name Type Description
callback function

isPreview(){boolean}

Check if we are in Safari previewing case.

jsonParse(str){object}

Parse a string. Use JSON.parse if possible.
Name Type Description
str string JSON string that you want to parse to Javascript object

jsonSerialize(obj){string}

Serialize any element. Use JSON.stringify if possible.
Name Type Description
obj object Javascript object that you want to serialize to JSON
Returns:
Serialized JSON

loadScript(scriptObj, callback)

Load a script.
Name Type Description
scriptObj object Object containing script properties (url)
callback function Function to call on success or on error

removeEvtListener(obj, event, callback)

Remove an event listener from an object.
Name Type Description
obj object DOM Element on which you want to add the event listener
event string Event you need to listen
callback function

setLocation(contextObj)

Force document location.
Name Type Description
contextObj object Redirection's url and target (properties location & target)

uuid(){function}

Generate UUID.