Spanish Total.js
English
Documentation For AI agents
Contents

DEF

The configuration options of the library.

.md GitHub
On this page

DEF holds the configuration of the library. Set the options in a script right after the library is loaded, before the first components start. To see how the options fit together, read Getting started.

API

config

DEF.ajaxcredentials = false

Sends cookies with every request.
Example
DEF.ajaxcredentials = true;
console.log(DEF.ajaxcredentials); // true
config

DEF.ajaxcredentialshtml = false

Also sends cookies with requests for .html files when DEF.ajaxcredentials is on.
Example
console.log(DEF.ajaxcredentialshtml); // false
config

DEF.ajaxerrors = false

Handles error responses as regular responses.

With true, the event error is not emitted and the Promise of a request is not rejected.

Example
DEF.ajaxerrors = true;
ON('request', opt => opt.throw('Failed', 500));
AJAX('GET /api/', function(response, err) {
	console.log(response, err); // Failed 500
});
config

DEF.api = undefined

The default endpoint of DAPI() and TAPI().

A URL, or a function that receives the name and the data and returns the value for API().

Example
DEF.api = '/api/';
console.log(DEF.api); // /api/
config

DEF.baseurl = ''

A prefix of relative request URLs.

A string, or a function that receives the URL and returns a new one.

Example
DEF.baseurl = '/app';
console.log('/users/'.ROOT()); // /app/users/
config

DEF.cdn = ''

The value of the marker ~CDN~ in imported content.
Example
DEF.cdn = '//cdn.example.com';
console.log(ADAPT(null, null, '~CDN~/a.js')); // //cdn.example.com/a.js
config

DEF.cl = {}

The loaded code lists by name.
Example
CL_INIT('roles', next => next(['admin']), true);
console.log(DEF.cl.roles); // ["admin"]
config

DEF.color = '#4285F4'

The main color of the application.
Example
console.log(DEF.color); // #4285F4
config

DEF.csrf = undefined

A token sent in the header x-csrf-token.

Requests for .html files do not send it.

Example
DEF.csrf = 'abc';
ON('request', function(opt) {
	console.log(opt.headers['x-csrf-token']); // abc
	opt.respond({});
});
AJAX('POST /api/', {}, NOOP);
config

DEF.currencies = {}

Functions that format numbers as currencies.
Example
DEF.currencies.eur = value => value.format(2) + ' EUR';
console.log((5).currency('eur')); // 5.00 EUR
config

DEF.currency = undefined

The default currency of Number.currency().
Example
DEF.currencies.eur = value => value.format(2) + ' EUR';
DEF.currency = 'eur';
console.log((5).currency()); // 5.00 EUR
config

DEF.customelements = false

Registers every component as its own element, <ui-name>.

Set it before declaring components.

Example
DEF.customelements = true;
COMPONENT('hello', function(self) {
	self.make = () => self.element.text('Hi');
});
console.log(customElements.get('ui-hello') != null); // true
config

DEF.dateformat = 'yyyy-MM-dd'

The default format of Date.format().
Example
console.log(new Date(2024, 0, 15).format()); // 2024-01-15
config

DEF.dateformatutc = false

Formats dates in UTC.
Example
console.log(DEF.dateformatutc); // false
config

DEF.decimalseparator = '.'

The decimal separator of formatted numbers.
Example
DEF.decimalseparator = ',';
console.log((1.5).format(2)); // 1,50
config

DEF.delay = 555

The delay in milliseconds before a request with the flag sync is tried again.
Example
console.log(DEF.delay); // 555
config

DEF.delaybinder = 200

The delay in milliseconds of delayed data bindings.
Example
console.log(DEF.delaybinder); // 200
config

DEF.delaykeypress = 200

The delay in milliseconds after a key press in an input.
Example
console.log(DEF.delaykeypress); // 200
config

DEF.delaypref = 1000

The delay in milliseconds before PREF is saved.
Example
console.log(DEF.delaypref); // 1000
config

DEF.delayrepeat = 2000

The delay in milliseconds before a request with the flag repeat is sent again.
Example
console.log(DEF.delayrepeat); // 2000
config

DEF.delaywatcher = 555

The interval in milliseconds of the checks that wait for a value.
Example
console.log(DEF.delaywatcher); // 555
config

DEF.devices = { xs: { max: 768 }, sm: { min: 768, max: 992 }, md: { min: 992, max: 1200 }, lg: { min: 1200 } }

The limits of the display sizes in pixels.
Example
console.log(DEF.devices.sm); // {"min":768,"max":992}
config

DEF.dictionary = {}

The translations used by TRANSLATE().
Example
LOCALIZE('hello : Ahoj');
console.log(DEF.dictionary.hello); // Ahoj
config

DEF.empty = '---'

The text used for an empty value in data bindings.
Example
console.log(DEF.empty); // ---
config

DEF.environment = { ts, date, time }

The variables of ENV().
Example
console.log(DEF.environment.date); // yyyy-MM-dd
config

DEF.fallback = 'https://cdn.componentator.com/j-{0}.html'

The URL of components that are not declared on the page.

{0} is the name of the component. An empty value turns the download off.

Example
DEF.fallback = '';
console.log(DEF.fallback === ''); // true
config

DEF.fallbackcache = ''

How long downloaded components are cached.
Example
DEF.fallbackcache = '1 day';
console.log(DEF.fallbackcache); // 1 day
config

DEF.headers = { 'X-Requested-With': 'XMLHttpRequest' }

The headers of every request.
Example
DEF.headers['X-App'] = 'shop';
ON('request', function(opt) {
	console.log(opt.headers['X-App']); // shop
	opt.respond({});
});
AJAX('GET /api/', NOOP);
config

DEF.iconprefix = 'ti ti-'

The prefix of icon names in component.icon().
Example
console.log(DEF.iconprefix); // ti ti-
config

DEF.importcache = 'session'

How long content from <ui-import> is cached.
Example
console.log(DEF.importcache); // session
config

DEF.jsoncompress = false

The default value of the compress argument of STRINGIFY().
Example
DEF.jsoncompress = true;
console.log(STRINGIFY({ a: 1, b: '' })); // {"a":1}
config

DEF.jsonconverter = { 'text json': fn }

The converters of request responses.
Example
console.log(typeof(DEF.jsonconverter['text json'])); // function
config

DEF.jsondate = true

Converts ISO dates to Date objects when JSON is parsed.
Example
DEF.jsondate = false;
console.log(typeof(PARSE('{"d":"2024-01-01T10:00:00.000Z"}').d)); // string
config

DEF.keypress = true

Makes inputs react while the user types.
Example
console.log(DEF.keypress); // true
config

DEF.language = undefined

The language added to the URL of every request.
Example
DEF.language = 'sk';
console.log(DEF.language); // sk
config

DEF.languagehtml = undefined

The language added to the URL of .html requests only.
Example
DEF.languagehtml = 'sk';
console.log(DEF.languagehtml); // sk
config

DEF.languagekey = 'language'

The name of the query argument with the language.
Example
console.log(DEF.languagekey); // language
config

DEF.localstorage = 'jc'

The prefix of the keys in the browser storage.
Example
console.log(DEF.localstorage); // jc
config

DEF.makeurl = null

A function that changes the URL of every request.
Example
DEF.makeurl = url => url + '?v=2';
console.log(typeof(DEF.makeurl)); // function
config

DEF.monitor = false

Collects usage counters in M.performance.
Example
DEF.monitor = true;
SET('a', 1);
console.log(M.performance.set.count > 0); // true
config

DEF.pathcl = 'DEF.cl.'

The path behind the prefix #.
Example
console.log(DEF.pathcl); // DEF.cl.
config

DEF.pathcommon = 'common.'

The path behind the prefix *.
Example
SET('*title', 'Hello');
console.log(GET('common.title')); // Hello
config

DEF.prefixcsscomponents = 'ui-'

The CSS prefix passed to component declarations.
Example
console.log(DEF.prefixcsscomponents); // ui-
config

DEF.prefixcsslibrary = 'ui-'

The CSS prefix of the classes of the library.
Example
console.log(DEF.prefixcsslibrary); // ui-
config

DEF.prefixcssmacros = 'm-'

The CSS prefix passed to macro declarations.
Example
console.log(DEF.prefixcssmacros); // m-
config

DEF.regexp = { int, float, date, pluralize, format }

The regular expressions of the string and date helpers.
Example
console.log(DEF.regexp.int instanceof RegExp); // true
config

DEF.repeatfocus = true

Pauses REPEAT() while the page is in the background.
Example
console.log(DEF.repeatfocus); // true
config

DEF.root = ''

A prefix of relative URLs that has priority over DEF.baseurl.

A string, or a function that receives the URL and returns a new one.

Example
DEF.root = '/shop';
console.log('/users/'.ROOT()); // /shop/users/
config

DEF.scope = window

The object in which paths are stored.
Example
console.log(DEF.scope === window); // true
config

DEF.scrollbaranimate = true

Animates custom scrollbars at the end of the content.
Example
console.log(DEF.scrollbaranimate); // true
config

DEF.secret = function

Sets the key that encrypts the data of requests.

Call it as DEF.secret(key, [validator], [html]). validator is a function that receives the request options and decides whether to encrypt them. With true as html, responses for .html files are also decrypted. The function removes itself after the first call.

Example
DEF.secret('my-key');
console.log(DEF.secret === undefined); // true
config

DEF.thousandsseparator = ' '

The thousands separator of formatted numbers.
Example
console.log((1500).format(0)); // 1 500
config

DEF.timeformat = 'HH:mm'

The default time format in DEF.environment.
Example
console.log(DEF.timeformat); // HH:mm
config

DEF.validators = { url, phone, email }

The regular expressions of String.isURL(), String.isPhone() and String.isEmail().
Example
console.log(DEF.validators.email.test('a@b.com')); // true
config

DEF.version = ''

The version added to the URL of every request.
Example
DEF.version = '1.2';
console.log(DEF.version); // 1.2
config

DEF.versioncomponents = ''

The version of components used without a version.
Example
console.log(DEF.versioncomponents === ''); // true
config

DEF.versionhtml = undefined

The version added to the URL of .html requests only.
Example
DEF.versionhtml = '1.2';
console.log(DEF.versionhtml); // 1.2
config

DEF.versionkey = 'version'

The name of the query argument with the version.
Example
console.log(DEF.versionkey); // version
config

DEF.webcomponentsonly = undefined

With true, the page is searched only for the <ui-*> elements.
Example
DEF.webcomponentsonly = true;
console.log(DEF.webcomponentsonly); // true
Made in Europe