Class: Utils

Utils

new Utils()

This contains various utility like loading, image preload, resizeEnd or scrollEnd watcher
Source:
Example
var Utils = require('./path/to/utils.js');
var utils = new Utils();

Methods

loading(action)

This add/remove hidden class to $('.js-loading') DOM element
Parameters:
Name Type Description
action string hide/show to add/remove hidden class to $('.js-loading') DOM element
Source:
Example
utils.loading('show');
utils.loading('hide');

preloadImages(images, allCallback, singleCallback)

Preload array of images
Parameters:
Name Type Description
images array array of images to preload
allCallback function function called when all images has been loaded
singleCallback function function called when single image has been loaded
Source:
Example
var imagesArray = ['a.jpg','b.png','c.gif'];
function allCallback() {
 console.log('all images has been loaded');
}
function singleCallback(res) {
 console.log('index of image just loaded ' + res.index);
 console.log('url of image just loaded ' + res.src);
}
utils.preloadImages(imagesArray, allCallback, singleCallback);

resizeEnd(endCallback, time)

This detects the end of the resize of window
Parameters:
Name Type Description
endCallback function function called when resize finish
time number delay in millisecond
Source:
Example
var time = 500;
function endCallback(res) {
 console.log('window width and height when resize action start ' + res.old.width + ' - ' + res.old.height);
 console.log('window width and height when resize action finish ' + res.new.width + ' - ' + res.new.height);
}
utils.resizeEnd(endCallback, time);

scrollEnd(endCallback, element, time)

This detects the end of the resize of window by default or user defined element
Parameters:
Name Type Description
endCallback function function called when resize finish
element string jQuery element selector
time number delay in millisecond
Source:
Example
var time = 500;
var element = '.my-element';
function endCallback(res) {
 console.log('scroll position when event start ' + res.old);
 console.log('scroll position when event finish ' + res.new);
}
utils.scrollEnd(endCallback, element, time);