.utils

Returns a collection of utility functions and objects.

The table below lists the objects returned from the collection, the value type, and a description of their possible use.

Object Value Type Parameters Description
now int none Returns the current time, in UNIX milisecond format.
isString function (obj) Returns a boolean value, true if the object passed as a parameter is a string, and false if not.
str2json function (str, notevil) Converts a JSON string to a plain JavaScript object. If the second parameter noteviile is true, the string is passed through a custom JSON conversion function. Otherwise, it uses the browser's native JSON.parse method.
debounce function (func, wait, immediate) Executes the function passed as the first parameter as set intervals, determined by the second interval. The third parameter immediate defaults to true, allowing the function to execute immediately, rather than wait on cycle. This is particularly useful to reduce memory usage when executing onscroll or onresize callback functions.
isInView function (element, options) Determines if the element passsed as the first parameter is visible within the current viewport. The second parameter, options is an object that includes `topoffset` and `leftoffset` as possible values.
checkDisplay function (context, initanimation) Forces the child elements of the element passed as the first parameter to check their visibility and layout status. This is primarily used internally for animation-based components.
uid function (prefix) Returns a unique string, prefixed if the optional parameter is passed through.
events.click string none Returns either 'tap' or 'click', based on whether or not the browser is a touch-enabled device.

Example

;(function(clique) {
    // Check if an element is inside the current viewport, with
    // a 50px offset from the top of the viewport.
    var isVisible = Clique.utils.isInView('#my-element', {
        topoffset : 50
    });
    if(isVisible) {
        // Do something if the element is visible...
    }

    clique.$('#my-element').on(clique.utils.events.click, function() {
        // Do something on tap/click...
    });
})(Clique);