Namespace: Helpers

.ALS. Helpers

Contains helper methods and properties

Members


<static> deviceType :"desktop"|"phone"|"tablet"

Contains user's device type. This detection has been performed using only user agent. If you want to implement something that relies on actual device type, consider performing feature detection by yourself. Otherwise, use this property to maintain consistent look and feel.

Type:
  • "desktop" | "phone" | "tablet"

<static> isChrome :boolean

Indicates whether user's browser is Chrome.

Type:
  • boolean

<static> isElectron

Indicates whether this library is running inside Electron.

This is based on user agent: navigator.userAgent.indexOf('Electron') !== -1

If you've modified user agent, feel free to change this field too.


<static> isIE :boolean

Indicates whether user's browser is IE (any version).

Type:
  • boolean

<static> isIE11 :boolean

Indicates whether user's browser is IE11.

Type:
  • boolean

<static> isIElte9 :boolean

Indicates whether user's browser is IE9 or older.

Type:
  • boolean

<static> isMobile :boolean

Equals to deviceType === "phone"

Type:
  • boolean

<static> localStorage :WindowLocalStorage

By default, points to window.localStorage. If user's browser doesn't support LocalStorage, will use temporary "polyfill" which acts like LocalStorage but doesn't actually save anything.

Type:
  • WindowLocalStorage

<static> mergeOptions

Merges two options into one object without modifying them. It checks if property is present in the defaultOptions, defaultOptions should contain ALL the needed properties.


<static> supportsBlob :boolean

Indicates whether user's browser supports Blob or not

Type:
  • boolean

<static> supportsDataURL :boolean

If user's browser doesn't support Data URLs (URLs in form: data:[<mediatype>][;base64],<data>), this will true. Otherwise will be false.

Type:
  • boolean

<static> supportsFlexbox :boolean

Indicates whether user's browser supports flexbox.

Type:
  • boolean

Methods


<static> createDataURL(filename, mediatype, encoding, data, notifyIfCantKeepExtension)

Makes browser download data by creating data URL.

Parameters:
Name Type Description
filename string

Name of the file to save

mediatype string

Data URL media type

encoding string

Data or text encoding

data string

Data itself

notifyIfCantKeepExtension boolean

If user's browser can't keep extension, notify them about it


<static> dispatchEvent(object, type)

Dispatches event of given type to given object.

Parameters:
Name Type Description
object Object

Object to dispatch event to

type string

Type of event


<static> formatNumber(number)

Formats number to more readable format by inserting spaces

Parameters:
Name Type Description
number number | string

Number to format

Returns:

Formatted number

Type
string

<static> generateID()

Generates random and unique ID

Returns:

Generated ID

Type
string

<static> getFileExtension(filename)

Finds extension of the given filename, i.e. part after last dot.

Parameters:
Name Type Description
filename string

Filaname

Returns:

Extension

Type
string

<static> HTMLToElement(html, appendTo)

Parses given HTML and appends it to given element as a child

Parameters:
Name Type Description
html string

HTML to parse

appendTo Element

Element to append parsed HTML to


<static> isObjectEmpty(object)

Checks if given object is empty

Parameters:
Name Type Description
object Object

Object to check

Returns:

True, if object is empty. False otherwise.

Type
boolean

<static> makeCollapsible(button, element, clickAfter)

Makes an element collapsible with an animation.

Parameters:
Name Type Description
button HTMLElement

Button that will show or collapse an element

element HTMLElement

Element to make collapsible

clickAfter boolean

If true, button will be clicked when everything's applied.


<static> makeHideable(button, element, onHideCallback, onShowCallback, clickAfter)

Makes button hide or show element on click. Both button and element will have attribute "data-hidden" equal to 0 or 1.

Parameters:
Name Type Description
button Element

Button that will control visibility of the element.

element Element

Element that will be controlled

onHideCallback function

Function to call on hiding

onShowCallback function

Function to call on showing

clickAfter boolean

If true, button will be clicked after all the things will be applied. You may want to set it to false if your callbacks affects unfinished stuff.


<static> notifyIfDataURLIsNotSupported(extension)

Displays notification if Data URL is not supported

Parameters:
Name Type Description
extension string

file extension to display in notification


<static> readTextFile(fileInput, notSupportedNotification, callback)

Reads file opened on fileInput as text, calls given callback and passes text to it

Parameters:
Name Type Description
fileInput HTMLInputElement

File input to read file from

notSupportedNotification string

If user's browser doesn't support reading text files, this notification will be presented.

callback function

Callback to pass text to


<static> saveAsText(string, filename)

Saves string as text

Parameters:
Name Type Description
string string

String to save

filename string

Name of the file to save