Spanish Total.js
English
Documentation For AI agents
Contents

DEF

The default settings of the library.

.md GitHub
On this page

DEF holds the default settings of the library. Assign the values directly after the library script, so that they apply from the start. Getting started shows where this code belongs.

API

config

DEF.api = undefined

The address used by TAPI().

Returns String Default: undefined.

Assign it to use TAPI().

Set the endpoint
DEF.api = '/admin/api/';
console.log(DEF.api); // /admin/api/
config

DEF.baseurl = ''

The prefix that String.ROOT() adds to relative addresses.

Returns String|Function Default: ''.

A function receives the address and returns the final address. DEF.root takes priority. See String.

Prefix an address
DEF.baseurl = '/app';
console.log('/users/'.ROOT()); // /app/users/
config

DEF.cdn = ''

The value of the ~CDN~ keyword in imported content.

Returns String Default: ''.

The keyword is replaced by ADAPT().

Use the keyword
DEF.cdn = 'https://cdn.example.com';
console.log(ADAPT(null, null, '~CDN~/logo.png')); // https://cdn.example.com/logo.png
config

DEF.cl = {}

The loaded code lists.

Returns Object Default: {}.

The path prefix # points here, so #countries is DEF.cl.countries. See CL().

Read a list through its path
SET('#colors', ['red']);
console.log(DEF.cl.colors); // ["red"]
config

DEF.color = '#4285F4'

The accent colour of the app.

Returns String Default: '#4285F4'.

APPEARANCE() updates it.

Change the colour
APPEARANCE({ color: '#FF0000' });
console.log(DEF.color); // #FF0000
config

DEF.currencies = {}

The formatters used by Number.currency().

Returns Object Default: {}.

Each key is a currency name and each value is a function that receives the number. See Number.

Define a currency
DEF.currencies.eur = function(value) {
	return value.format(2) + ' EUR';
};

console.log((10).currency('eur')); // 10.00 EUR
config

DEF.currency = ''

The default currency of Number.currency().

Returns String Default: ''.

Set the default currency
DEF.currencies.usd = function(value) {
	return '$' + value.format(2);
};

DEF.currency = 'usd';
console.log((5).currency()); // $5.00
config

DEF.dateformat = 'yyyy-MM-dd'

The default format of Date.format() and of date parsing.

Returns String Default: 'yyyy-MM-dd'.

See Date.

Change the format
DEF.dateformat = 'dd.MM.yyyy';
console.log(new Date(2024, 0, 15).format()); // 15.01.2024
config

DEF.dateformatutc = false

Formats all dates in UTC.

Returns Boolean Default: false.

It applies to Date.format(). See Date.

Format in UTC
DEF.dateformatutc = true;
console.log(new Date(Date.UTC(2024, 0, 15, 12, 30)).format('HH:mm')); // 12:30
config

DEF.decimalseparator = '.'

The decimal separator of formatted numbers.

Returns String Default: '.'.

It is used by Number.format() and when numbers are parsed. See Number.

Use a decimal comma
DEF.decimalseparator = ',';
console.log((1.5).format(2)); // 1,50
config

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

The width ranges of the device sizes.

Returns Object Default: { xs: { max: 768 }, sm: { min: 768, max: 992 }, md: { min: 992, max: 1200 }, lg: { min: 1200 } }.

The ranges are used by WIDTH() and by the jc-xs, jc-sm, jc-md and jc-lg body classes.

Read a range
console.log(DEF.devices.md); // {"min":992,"max":1200}
config

DEF.dictionary = {}

The translations loaded with LOCALIZE().

Returns Object Default: {}.

Read the dictionary
LOCALIZE('Tabc : Hola');
console.log(DEF.dictionary.Tabc); // Hola
config

DEF.empty = '---'

The text displayed for an empty value.

Returns String Default: '---'.

It is used by the empty command of ui-bind and by the empty Tangular helper.

Read the text
console.log(DEF.empty); // ---
config

DEF.env = { ts: 'yyyy-MM-dd - HH:mm', date: 'yyyy-MM-dd', time: 'HH:mm' }

The environment variables.

Returns Object Default: { ts: 'yyyy-MM-dd - HH:mm', date: 'yyyy-MM-dd', time: 'HH:mm' }.

Variables are managed with ENV(). The default values can be used as date formats, for example [ts].

Use a variable as a date format
var date = new Date(2024, 0, 15, 8, 5);
console.log(date.format('[ts]')); // 2024-01-15 - 08:05
config

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

The address from which unknown components are downloaded.

Returns String Default: 'https://cdn.componentator.com/j-{0}.html'.

The {0} keyword becomes the component name. The source attribute of ui-component overrides it.

Read the address
console.log(DEF.fallback.format('input')); // https://cdn.componentator.com/j-input.html
config

DEF.firstdayofweek = 1

The first day of the week, for components that display a calendar.

Returns Number Default: 1.

The value 0 is Sunday and 1 is Monday. The library only stores it.

Start the week on Sunday
DEF.firstdayofweek = 0;
console.log(DAYS[DEF.firstdayofweek]); // Sunday
config

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

The headers added to every AJAX() request.

Returns Object Default: { 'X-Requested-With': 'XMLHttpRequest' }.

Add a header
DEF.headers['x-token'] = '123456';
console.log(DEF.headers['x-token']); // 123456
config

DEF.iconprefix = 'ti ti-'

The prefix added to icon names by component.icon().

Returns String Default: 'ti ti-'.

A value that contains a space is used as it is. See Component.

Change the prefix
<ui-component name="box"></ui-component>

<script>
COMPONENT('box', function(self) {
	self.make = function() {
		DEF.iconprefix = 'fa fa-';
		console.log(self.icon('home')); // fa fa-home
	};
});
</script>
config

DEF.language = undefined

The language added to the query string of every AJAX() request.

Returns String Default: undefined.

The name of the parameter is in DEF.languagekey. ENVIRONMENT() can set this value.

Set the language
DEF.language = 'en';
console.log(DEF.language); // en
config

DEF.languagekey = 'language'

The name of the query parameter that carries the language.

Returns String Default: 'language'.

Read the name
console.log(DEF.languagekey); // language
config

DEF.localstorage = 'jc'

The localStorage key of the cache.

Returns String Default: 'jc'.

ENVIRONMENT() can set this value.

Read the key
console.log(DEF.localstorage); // jc
config

DEF.onstorageread = function(callback)

Loads the persistent cache when the library starts.

Returns Function Default: function(callback).

Assign your own function directly after the library script. It must call callback with the stored object. The default function reads localStorage.

Provide the stored data
DEF.onstorageread = function(callback) {
	callback({});
};

ON('ready', function() {
	console.log('loaded'); // loaded
});
config

DEF.onstoragesave = function(data)

Saves the persistent cache.

Returns Function Default: function(data).

The function receives an object with all the items that have an expiration. The default function writes to localStorage.

Observe saving
DEF.onstoragesave = function(data) {
	console.log(Object.keys(data).length); // 1
};

ON('ready', function() {
	CACHE('filter', 1, '1 day');
});
config

DEF.path = { common: 'common.', cl: 'DEF.cl.', plugins: 'jComponent.data.', tmp: 'DEF.tmp.' }

The targets of the short path prefixes.

Returns Object Default: { common: 'common.', cl: 'DEF.cl.', plugins: 'jComponent.data.', tmp: 'DEF.tmp.' }.

common is the target of *, cl of # and tmp of %. plugins holds the data of plugins with a generated path. The function DEF.path.clean(name) returns a value without the final dot. See Paths.

Read a prefix
console.log(DEF.path.common); // common.
console.log(DEF.path.clean('common')); // common
config

DEF.pipe = undefined

The address used by PIPE().

Returns String Default: undefined.

Assign it to use PIPE().

Set the endpoint
DEF.pipe = '/pipe/';
console.log(DEF.pipe); // /pipe/
config

DEF.prefixcsscomponents = 'ui-'

The prefix of the CSS class that a component receives as cls.

Returns String Default: 'ui-'.

Change the prefix
<ui-component name="box"></ui-component>

<script>
DEF.prefixcsscomponents = 'my-';

COMPONENT('box', function(self, config, cls) {
	console.log(cls); // my-box
});
</script>
config

DEF.prefixcsslibrary = 'ui-'

The prefix of the CSS classes created by the library.

Returns String Default: 'ui-'.

It is used by APPEARANCE() and SCROLLBAR().

Change the prefix
DEF.prefixcsslibrary = 'app-';
APPEARANCE({ dark: true });
console.log($('body').hclass('app-dark')); // true
config

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

The regular expressions used by the helpers.

Returns Object Default: { int, float, date, pluralize, format, url, phone, email }.

For example, String.isEmail() uses DEF.regexp.email. See String.

Validate an e-mail address
console.log(DEF.regexp.email.test('info@example.com')); // true
console.log('invalid'.isEmail()); // false
config

DEF.root = ''

The prefix that String.ROOT() adds to every relative address.

Returns String|Function Default: ''.

It takes priority over DEF.baseurl, and ROOT(true) applies only this value. See String.

Prefix an address
DEF.root = '/admin';
console.log('/users/'.ROOT()); // /admin/users/
config

DEF.scrollbaranimate = true

Animates the bar of a custom scrollbar at the edges of the scrolling area.

Returns Boolean Default: true.

Disable the animation
DEF.scrollbaranimate = false;
console.log(DEF.scrollbaranimate); // false
config

DEF.thousandsseparator = ' '

The thousands separator of formatted numbers.

Returns String Default: ' '.

It is used by Number.format() and when numbers are parsed. See Number.

Use a comma
DEF.thousandsseparator = ',';
console.log((1234567).format(0)); // 1,234,567
config

DEF.timeformat = 'HH:mm'

The time format copied into the environment variables at startup.

Returns String Default: 'HH:mm'.

To change the format later, write the variables time and ts with ENV().

Read the format
console.log(DEF.timeformat); // HH:mm
console.log(ENV('time')); // HH:mm
config

DEF.tmp = {}

The storage of temporary paths.

Returns Object Default: {}.

The path prefix % points here, so %form is DEF.tmp.form. See Paths.

Write a temporary value
SET('%search', 'phone');
console.log(DEF.tmp.search); // phone
config

DEF.version = undefined

The version added to .html addresses requested with AJAX().

Returns String Default: undefined.

The name of the parameter is in DEF.versionkey. ENVIRONMENT() can set this value.

Set the version
DEF.version = '1.0';
console.log(DEF.version); // 1.0
config

DEF.versionhtml = undefined

The version for .html addresses when DEF.version is empty.

Returns String Default: undefined.

Set the version of HTML files
DEF.versionhtml = '2';
console.log(DEF.versionhtml); // 2
config

DEF.versionkey = 'version'

The name of the query parameter that carries the version.

Returns String Default: 'version'.

Read the name
console.log(DEF.versionkey); // version
config

DEF.warnings = false

Prints the warnings of the library to the console.

Returns Boolean Default: false.

Enable it during development, for example to report a method that was not found.

Enable warnings
DEF.warnings = true;
console.log(DEF.warnings); // true
Made in Europe