jComponent / 02. Library
Updated: 15. March 2018
Author: Peter Širka

02. Library

Professional Support Chat with contributors

Quick navigation:

Properties


Property: MAIN.components

readonly Gets all instances of components.

MAIN.components;
// returns {Array Object}

Property: MAIN.defaults

Gets default settings. With this property you can change behaviour of jComponent library.

MAIN.defaults;
// returns {Object}

DEF;
// returns {Object}
// Is an alias for MAIN.defaults

DEF.ajaxerrors = false;
// {Boolean} AJAX() method won't create an exception if HTTP status code will be >= 400

DEF.baseurl = '';
// This property affects a relative URL address in AJAX requests
// {String} If it contains "string" then the string is combined with URL: "url = baseurl + url"
// {Function(url)} If it contains "function" then the function needs to return a new url
// +v13.0.5

DEF.makerurl = function(url) {
   return url;
};
// This delegate can affect URL before is request created.
// It must return updated URL!!!
// +v14.3.1

DEF.decimalseparator = '.';
// Default decimal separator

DEF.delay = 300;
// {Number} A delay for real-time keypress binding

DEF.delaybinder = 200;
// {Number} A default delay for binding of value for non-released component
// +v13.0.0

DEF.delaywatcher = 555;
// {Number} A delay for component watcher (component.width(), component.heigth(), etc.)
// +v13.0.0

DEF.devices = { xs: { max: 768 }, sm: { min: 768, max: 992 }, md: { min: 992, max: 1200 }, lg: { min: 1200 }};
// {Object} Custom display sizes for Responsive UI

DEF.fallback = 'https://cdn.componentator.com/j-{0}.html';
// {String} A fallback URL for non-exist components
// Import "fallback" will be disabled if the "fallback" will be empty
// +v14.0.0

DEF.fallbackcache = '5 minutes';
// {String} Fallback cache, empty value disables caching
// Default: empty
// +v14.0.0

DEF.headers = { 'X-Requested-With': 'XMLHttpRequest' };
// {Object} Custom AJAX() headers
// IMPORATNT: +v13.0.0 X-Requested-With is removed for CORS request

DEF.jsoncompress = false;
// {Boolean} Compresses JSON values (removes empty strings and null values from JSON)

DEF.jsondate = true;
// {Boolean} Converts date values in JSON automatically to Date object

DEF.keypress = true;
// {Boolean} Can disable real-time keypress binding

DEF.localstorage = true;
// {Boolean} Can disable localstorage

DEF.pingdata = {};
// {Object} Can contain GET params for PING method

DEF.thousandsseparator = ' ';
// {String} Default thousands separator

DEF.version = '1';
// {String} A default version for all jComponents
// Default: empty
// +v14.0.0

Property: MAIN.validators

Contains RegExp validators.

MAIN.validators;
// returns {Object}

MAIN.validators.url;
// RegExp for URL addresses

MAIN.validators.email;
// RegExp for email addresses

MAIN.validators.phone;
// RegExp for phone numbers

Property: MAIN.version

readonly Returns the current version of jComponent.

MAIN.version;
// returns {String}

Property: MAIN.$components

readonly Gets all registered components, only types - not instances.

MAIN.$components;
// returns {Object}

Property: MAIN.$language

Affects all AJAX() requests, it appends GET argument ?language=$language automatically to the URL address.

MAIN.$language = '';
// returns {String}

Property: MAIN.$localstorage

Returns a localStorage key for jComponent. You can change this key by your needs.

MAIN.$localstorage = 'jc';
// returns {String}

Property: MAIN.$version

Affects all AJAX() requests, it appends GET argument ?version=$version automatically to the URL address.

MAIN.$version = '';
// returns {String}

Methods

Method: MAIN.createURL()

This method can appends custom params to url.

MAIN.createURL([url], values);
// @url {String} Optional, default: "location.href"
// @valus {Object}
// returns {String}

console.log(MAIN.createURL({ sort: 1, pricefrom: 300 }));
// Output: /?sort=1&price=300

console.log(MAIN.createURL('/search/?q=Peter', { sort: 1, pricefrom: 300 }));
// Output: /search/?q=Peter&sort=1&pricefrom=300

Method: MAIN.formatter()

This method registers a new global formatter. Each component uses global formatters for formatting of values.

MAIN.formatter(fn);
// @fn {Function(path, value, type)}
// returns {MAIN}

MAIN.formatter(function(path, value, type) {
    return typeof(value) === 'string' ? value.toUpperCase() : value;
});

Method: MAIN.parseCookies()

This method parses the current document cookies.

MAIN.parseCookies();
// returns {Object}

console.log(MAIN.parseCookies());
// Output: { _ga: "GA1......" }

Method: MAIN.parseQuery()

This method parses URL arguments from the current URL address.

MAIN.parseQuery([query]);
// @query {String} Optional, custom URL (default: "location.href")
// returns {Object}

console.log(MAIN.parseQuery('/search/?q=Peter'));
// Output: { q: "Peter" }

Method: MAIN.parser()

This method registers a new global parser. Each component uses global parsers for parsing of values.

MAIN.parser(fn);
// @fn {Function(path, value, type)}
// returns {MAIN}

MAIN.parser(function(path, value, type) {
    return typeof(value) === 'string' && type === 'date' ? value.parseDate() : value;
});

Method: MAIN.ready()

This method registers a handler to execute when jComponent is fully loaded.

MAIN.ready(handler);
// @handler {Function}
// returns {MAIN}

MAIN.ready(function() {
    console.log('jComponent is ready');
});

Method: MAIN.usage()

This method returns last usage components.

MAIN.usage(type, expire, [path], [callback]);
// @type {String} Can be "init", "manually", "input" or "custom"
// returns {Array Component} or {jComponent}

console.log(MAIN.usage('init', '5 minutes'));
// Returns {Array Component}

MAIN.usage('init', '5 minutes', function(component) {
    console.log(component);
});