Helpers

Helpers

Source:
Global helper functions

Methods

(static) ajax(method, url, body, errCallback, successCallback)

Source:
Send XMLHttpRequest and call either error or success callback
Parameters:
Name Type Description
method String
url String
body Object | Null
errCallback function
successCallback function

(static) callFnWithElementsIfExist(fn, required, optionalopt)

Source:
Check whether required DOM elements exist, if so, call fn with provided els
Parameters:
Name Type Attributes Description
fn function Function to be called if elements exist
required Array.<(HTMLElement|NodeList)> All elements in this array are required to exist, otherwise fn won't be called
optional Array.<(HTMLElement|NodeList)> <optional>
These are optional elements that will be passed to fn if it's called

(static) debounce(fnopt, delayopt) → {function}

Create a debounced version of the passed function

Source:
Function to execute and timeout can be passed either at init or at call time and can be redefined
Example
const debouncedFn = debounce(testingFunction, 500);

// This function can be called any time
debouncedFn();

// It can also be redefined
debouncedFn(anotherTestingFn); // will execute anotherTestingFn instead of testingFunction if this call is the last
debouncedFn(anotherTestingFn, 800); // either fn or both fn and delay can be overriden at call time

// Unless it's called again w/o params, in this case, the params provided at init will be used
debouncedFn(); // Will exec testingFunction after 500ms

// Can also be canceled
clearTiemout(debouncedFn);
Parameters:
Name Type Attributes Description
fn function <optional>
Function to debounce
delay Integer <optional>
Delay after which it'll be executed after the last call to de debounced function
Returns:
Debounced function
Type
function

(static) getCookie(name) → {String}

Source:
Get a cookie by name
Parameters:
Name Type Description
name String Cookie name
Returns:
Type
String

(static) getUrl(pathNameopt) → {String}

Source:
Get current url
Parameters:
Name Type Attributes Description
pathName Bool <optional>
Whether to return only relative url without anchors and query parameters
Returns:
Type
String

(static) getUrlParamValue(paramName) → {String}

Source:
Get a query parameter's value
Parameters:
Name Type Description
paramName String Name of the parameter to get the value from
Returns:
Type
String

(static) getUrlQueryString() → {String}

Source:
Get url query string (unparsed)
Returns:
Type
String

(static) getWindowHeight() → {Number}

Source:
Get the viewport height
Returns:
Size in pixels
Type
Number

(static) getWindowWidth() → {Number}

Source:
Get the viewport width
Returns:
Size in pixels
Type
Number

(static) navigateTo(url, redirectopt)

Source:
Navigate to a new page
Parameters:
Name Type Attributes Description
url String
redirect Bool <optional>
Whether this is a redirect and as such, won't be saved in browser history

(static) scrollIn(el, left, top, smooth)

Source:
Trigger scroll to coordinates relative to the element
Parameters:
Name Type Description
el Element Scroll to a particular set of coordinates inside a given element
left Integer Number of pixels along the horizontal axis of the element that will be displayed in the upper left
top Integer Number of pixels along the vertical axis of the element that will be displayed in the upper left
smooth Bool Whether the scrolling should animate smoothly

(static) scrollTo(el, smooth)

Source:
Trigger scroll to the element
Parameters:
Name Type Description
el Element Scroll untill the element is at the top of the viewport (like clicking an anchor tag)
smooth Bool Whether the scrolling should animate smoothly

(static) setCookie(name, val) → {String}

Source:
Set or update a cookie
Parameters:
Name Type Description
name String Cookie name in ASCII
val String Cookie value as a key=value string with ";" separator
Returns:
Type
String

(static) throttle(fn, delay) → {function}

Source:
Create a thottled version of the passed function
Parameters:
Name Type Description
fn function Function to throttle
delay Integer Minimum allowed interval of time between two calls of the function
Returns:
Throttled function
Type
function