Module: Helpers

Helpers

This module is a motley collection of simple "shortcut" methods

Method Summary

addEvent
Adds a handler for a browser event.
getNumber
Gets a string and interpret it as a Number.
getTimeStamp
Shortcut for new Date().
isArray
Shortcut for val.
randomG
Shortcut for Math.
removeEvent
Removes a handler for a browser event.
trim
Trims a string

Method Detail

<static> addEvent(obj, evnt, handler) → {Boolean}

Adds a handler for a browser event. The capture flag is set to false.
Parameters:
Name Type Description
obj Object the element to be listened to.
evnt String the event to be listened to.
handler function the function to be called
Returns:
true if the event was registered, false otherwise.
Type
Boolean
Example
 
Helpers.addEvent(window, "load", function(){});

<static> getNumber(val, commaAsDecimalSeparator) → {Number}

Gets a string and interpret it as a Number. The given string may contain dots or commas to separate decimals
Parameters:
Name Type Argument Default Description
val String the string to be converted
commaAsDecimalSeparator Boolean <optional>
false true to interpret the commas as decimal separators, false to interpret dots as decimal separators
Returns:
the interpreted number
Type
Number
Example
Helpers.getNumber("3.432.771,201",true) == 3432771.201

<static> getTimeStamp()

Shortcut for new Date().getTime();
Returns:
the current timestamp

<static> isArray(val) → {Boolean}

Shortcut for val.join && typeof(val.join) == "function"
Parameters:
Name Type Description
val Object the object to be verified
Returns:
true if val is an array, false otherwise
Type
Boolean

<static> randomG(max)

Shortcut for Math.round( Math.random() * max );
Parameters:
Name Type Argument Default Description
max Number <optional>
1000 The max value to be returned
Returns:
the current timestamp

<static> removeEvent(obj, evnt, handler) → {Boolean}

Removes a handler for a browser event.
Parameters:
Name Type Description
obj Object the element that is listened to.
evnt String the event that is listened to.
handler function the function that is called
Returns:
true if the event was removed, false otherwise.
Type
Boolean

<static> trim(str) → {String}

Trims a string
Parameters:
Name Type Description
str String the string to be trimmed
Returns:
the trimmed string
Type
String