Spanish Total.js
English
Documentation For AI agents
Contents

Component

The properties, the methods and the delegates of a component instance.

.md GitHub
On this page

A component instance is the first argument of the function given to COMPONENT(). It is created for each ui-component element. The Creating components guide shows how the parts work together.

API

property

id

The identifier of the instance.

Returns String The identifier of the instance.

The value is generated, and the $id config key replaces it.

property

ID

The generated identifier of the instance.

Returns String The generated identifier of the instance.

The $id config key does not change it.

property

name

The name of the component.

Returns String The name of the component.

property

path

The path of the component, or null when the element has none.

Returns Path The path of the component, or null when the element has none.

See Path.

property

config

The current configuration.

Returns Object The current configuration.

Change it with reconfigure(), so that configure is called.

property

element

The <ui-component> element as a jQuery object.

Returns jQuery The <ui-component> element as a jQuery object.

property

dom

The <ui-component> element.

Returns HTMLElement The <ui-component> element.

property

plugin

The parent plugin, or null.

Returns Plugin The parent plugin, or null.

See Plugin.

property

scope

The object that paths are resolved against, which is window.

Returns Object The object that paths are resolved against, which is window.

property

cls

The CSS class name of the component, for example ui-grid.

Returns String The CSS class name of the component, for example ui-grid.

The class is not added to the element automatically.

property

def

A function that returns the value of the default attribute. It exists only when the attribute is used.

Returns Function A function that returns the value of the default attribute. It exists only when the attribute is used.

property

ready

Is true once the instance starts to initialize.

Returns Boolean Is true once the instance starts to initialize.

delegate

init()

Runs once per declaration, for the first instance of the component.

It runs ahead of make. Use it for work shared by all instances.

The order of the delegates
<ui-component name="demo" path="common.value"></ui-component>

<script>
COMPONENT('demo', function(self) {
    self.init = () => console.log('init');
    self.make = () => console.log('make');
    self.configure = key => console.log('configure', key);
    self.setter = () => console.log('setter');
    self.done = () => console.log('done');
});
// logs: init
// logs: make
// logs: setter
// logs: done
</script>
delegate

make()

Runs when the instance is created.

Build the content of the element here.

delegate

configure(key, value, init, prev)

Runs for each config key when the configuration changes.
ParameterTypeDescription
key String The config key.
value Object The new value.
init Boolean true during the initialization.
prev Object The previous value, or null during the initialization.

It runs for all keys when the component initializes.

React to a config key
<ui-component name="demo" config="title:Hello"></ui-component>

<script>
COMPONENT('demo', function(self) {
    self.configure = function(key, value, init, prev) {
        key === 'title' && console.log(value, !!init, prev);
    };
    self.make = () => setTimeout(() => self.reconfigure({ title: 'Bye' }), 100);
});
// logs: Hello true null
// logs: Bye false Hello
</script>
delegate

setter(value, path, flags)

Receives each change of the value at the path.
ParameterTypeDescription
value Object The current value.
path String The path that changed.
flags Object The flags of the change, for example { init: 1 }.

The default implementation writes the value to the first input, textarea or select inside the element. A checkbox is checked when the value, as text, is true, 1, on, yes or ok. Assign your own function to render the value.

Render the value
<ui-component name="demo" path="common.value"></ui-component>

<script>
COMPONENT('demo', function(self) {
    self.setter = function(value, path, flags) {
        console.log(value, path, JSON.stringify(flags));
    };
});

SET('common.value @touched', 5);
// logs: 5 common.value {"touched":1}
</script>
delegate

setter2(value, path, flags)

Receives each change of the value, including the changes written with rewrite().
ParameterTypeDescription
value Object The current value.
path String The path that changed.
flags Object The flags of the change.
See the values that skip the setter
<ui-component name="demo" path="common.value"></ui-component>

<script>
COMPONENT('demo', function(self) {
    window.com = self;
    self.setter = value => value && console.log('setter', value);
    self.setter2 = value => value && console.log('setter2', value);
});

com.rewrite(1);
// logs: setter2 1
</script>
delegate

getter(value, [realtime])

Processes a value entered by the user and writes it to the path.
ParameterTypeDescription
value Object The entered value.
realtime? Boolean Writes the value without calling the setter. Default: false

The value goes through the function set with parser() and is converted according to the type config key. With realtime, the value is written without calling the setter.

Write a value from code
com.getter('5');
console.log(common.value);
// logs: 5
delegate

validate(value)

Decides whether the value is valid.
ParameterTypeDescription
value Object The value to check.

Returns Boolean The result of the validation. A string is also accepted.

Return true or an empty string for a valid value. A returned string is stored in config.invalid as the message, and any other result sets config.invalid to true. The method runs after each change of the value.

Require a value
<ui-component name="demo" path="common.value"></ui-component>

<script>
COMPONENT('demo', function(self, config) {
    window.com = self;
    self.validate = value => value ? true : 'The value is required';
});

console.log(com.config.invalid);
// logs: The value is required
SET('common.value', 'x');
console.log(com.config.invalid);
// logs: false
</script>
delegate

state()

Runs when the state of the component changes.

Read the state from config.touched, config.modified, config.invalid and config.disabled.

Follow the state
<ui-component name="demo" path="common.value"></ui-component>

<script>
COMPONENT('demo', function(self, config) {
    window.com = self;
    self.state = () => console.log(!!config.touched);
});

com.touch();
// logs: true
</script>
delegate

state2(component)

Runs when another component with the same path reports its state.
ParameterTypeDescription
component Component The component that reports the state.

The report is made with validate2() or with the notify flag of bind().

Listen to a sibling
<ui-component name="a" path="common.value"></ui-component>
<ui-component name="b" path="common.value"></ui-component>

<script>
COMPONENT('a', function(self) {
    window.com = self;
});

COMPONENT('b', function(self) {
    self.state2 = component => console.log(component.name);
});

com.validate2();
// logs: a
</script>
delegate

done()

Runs at the end of the initialization, when the value is set.
delegate

destroy()

Runs when the instance is removed.

It is called by remove(), and by the regular cleanup for elements that left the page. Release timers and global handlers here.

Clean up
<ui-component name="demo"></ui-component>

<script>
COMPONENT('demo', function(self) {
    window.com = self;
    self.destroy = () => console.log('destroyed');
});

com.remove();
// logs: destroyed
</script>
method

get()

Reads the value at the path of the component.

Returns Object The value, or null without a path.

Read the value
SET('common.value', 1);
console.log(com.get());
// logs: 1
method

set(value, [flags])

Writes a value to the path and notifies everything bound to it.
ParameterTypeDescription
value Object The value to write.
flags? String Flags such as @touched @modified.
Write the value
com.set(5, '@touched');
console.log(common.value);
// logs: 5
method

rewrite(value, [flags])

Writes a value to the path without calling the setter of this instance.
ParameterTypeDescription
value Object The value to write.
flags? String Flags such as @touched @modified.

Other components and watchers are notified.

Write without rendering
com.rewrite(7);
console.log(com.get());
// logs: 7
method

modify(value, [flags])

Writes a value and marks the component as touched and modified.
ParameterTypeDescription
value Object The value to write.
flags? String Flags such as @touched @modified.
Write a value entered by the user
com.modify('x');
console.log(com.element.attr('class'));
// logs: ui-touched ui-modified
method

push(value)

Adds a value to the array at the path.
ParameterTypeDescription
value Object The value to write.

An empty path is initialized with a new array and a single value is wrapped in an array.

Add an item
com.push('a');
com.push('b');
console.log(common.value.join());
// logs: a,b
method

upd([flags])

Notifies everything bound to the path, without changing the value.
ParameterTypeDescription
flags? String Flags such as @touched @modified.

The method is also available as update().

Announce a change made directly
common.value = 5;
com.upd();
console.log(com.get());
// logs: 5
method

refresh()

Calls the setter with the current value.
Render again
<ui-component name="demo" path="common.value"></ui-component>

<script>
COMPONENT('demo', function(self) {
    window.com = self;
    self.setter = (value, path, flags) => flags.refresh && console.log('refresh');
});

com.refresh();
// logs: refresh
</script>
method

setPath(path)

Changes the path of the component.
ParameterTypeDescription
path String The new path.

A ? is replaced with the path of the parent plugin. The setter is not called until the next change, so call refresh() to render the new value.

Point the component to another value
com.setPath('common.other');
console.log(com.path.toString());
// logs: common.other
method

makepath(path)

Replaces the ? in a path with the path of the parent plugin.
ParameterTypeDescription
path String The path.

Returns String The resulting path.

Resolve a relative path
<ui-plugin path="orders"><ui-component name="demo"></ui-component></ui-plugin>

<script>
COMPONENT('demo', function(self) {
    self.make = () => console.log(self.makepath('?.items'));
});
// logs: orders.items
</script>
method

bind(flags, [value])

Changes the state of the component and optionally writes a value without calling the setter.
ParameterTypeDescription
flags String The flags.
value? Object The value to write.

The flags are separated with a space, a comma or |, with or without @:

FlagEffect
touched, touchMarks the component as touched.
modified, changed, modify, changeMarks the component as modified.
resetClears the touched and modified state.
validateRuns the validation.
notifyCalls state2 of the other components with the same path.
setterCalls the setter.
Mark a value as entered by the user
com.bind('@touched @modified', 'x');
console.log(com.get(), com.element.attr('class'));
// logs: x ui-touched ui-modified
method

touch()

Marks the component as touched and runs the validation.
Mark as touched
com.touch();
console.log(com.config.touched);
// logs: 1
method

change()

Marks the component as touched and modified and runs the validation.
Mark as changed
com.change();
console.log(com.element.attr('class'));
// logs: ui-touched ui-modified
method

reset([noemit])

Clears the touched and modified state.
ParameterTypeDescription
noemit? Boolean Skips the validation. Default: false

The validation runs unless noemit is true.

Clear the state
com.change();
com.reset();
console.log(com.config.touched, com.config.modified);
// logs: 0 0
method

isInvalid()

Tells whether the component is touched and invalid.

Returns Boolean A truthy value when the component is touched and invalid.

Show an error only after the user was here
<ui-component name="demo" path="common.value"></ui-component>

<script>
COMPONENT('demo', function(self) {
    window.com = self;
    self.validate = value => !!value;
});

console.log(!!com.isInvalid());
// logs: false
com.touch();
console.log(!!com.isInvalid());
// logs: true
</script>
method

validate2([value])

Runs the validation and calls state2 of the other components with the same path.
ParameterTypeDescription
value? Object The value to validate. The default is the current value.
method

reconfigure(value)

Changes the configuration and calls configure for each key.
ParameterTypeDescription
value Object The keys to change.

The value is an object or a string in the form key:value;key:value. It accepts the special keys of the ui-component element, such as $class and =key.

Change the configuration
com.reconfigure('title:Orders;limit:5');
console.log(com.config.title, com.config.limit);
// logs: Orders 5
method

watchconfig(key, path)

Keeps a config key equal to the value at a path.
ParameterTypeDescription
key String The config key, or null.
path String The path to observe.

With null as the key, the object at the path is applied as the configuration.

Follow a value
com.watchconfig('limit', 'common.limit');
SET('common.limit', 10);
console.log(com.config.limit);
// logs: 10
method

formatter(fn)

Sets a function that converts the value for display, or converts a value with it.
ParameterTypeDescription
fn Function A function (path, value, type, format) that returns the value to display, or the value to convert.

Returns Object The converted value, when a value is given.

With a function as the argument, the default setter uses it from then on. With any other value, the method returns the converted value.

Format a price
<ui-component name="demo" path="common.value"><input /></ui-component>

<script>
COMPONENT('demo', function(self) {
    self.formatter((path, value) => value ? '$' + value : '');
});

SET('common.value', 7);
console.log($('input').val());
// logs: $7
</script>
method

parser(fn)

Sets a function that converts the entered value for the model, or converts a value with it.
ParameterTypeDescription
fn Function A function (path, value, type, format) that returns the value to store, or the value to convert.

Returns Object The converted value, when a value is given.

With a function as the argument, getter() uses it from then on. With any other value, the method returns the converted value.

Parse a price
<ui-component name="demo" path="common.value"></ui-component>

<script>
COMPONENT('demo', function(self) {
    window.com = self;
    self.parser((path, value) => value.replace('$', ''));
});

com.getter('$9');
console.log(common.value);
// logs: 9
</script>
method

autobind20([delay], [realtimebinding])

Connects the input, select and textarea inside the element with the path.
ParameterTypeDescription
delay? Number The delay in milliseconds. Default: 200
realtimebinding? Boolean Calls the setter also while the user types. Default: false

The value is written after the delay, and the touched and modified states are updated from the user events.

Bind an input
<ui-component name="demo" path="common.value"><input /></ui-component>

<script>
COMPONENT('demo', function(self) {
    self.make = () => self.autobind20(50);
});

$('input').val('typed').trigger('input');
setTimeout(() => console.log(common.value), 200);
// logs: typed
</script>
method

autofill([enabled])

Writes the values that the browser fills in on its own to the model.
ParameterTypeDescription
enabled? Boolean false turns the feature off. Default: true

A browser can fill a form with saved data, such as a name or an address, without any input event. One second after the library starts, it reads the first input, textarea or select of each component that calls this method, and a value found there is written to the path with the flags @change and @init. The parser of the component converts the value first.

It works with the default setter. Components with a default attribute, select elements and range inputs are skipped. autofill(false) turns it off.

Keep a value filled in by the browser
<ui-component name="login" path="form.email"><input type="email" /></ui-component>

<script>
COMPONENT('login', function(self) {
    self.autofill();
});

// the browser fills the input with a saved address
setTimeout(() => $('input').val('ann@example.com'), 100);

setTimeout(() => console.log(GET('form.email')), 1500);
// logs: ann@example.com
</script>
method

readonly()

Turns the component into a display without getter, setter and validation.
method

blind()

Excludes the component from notifications and from searches by path.
method

singleton()

Allows only one instance of the component.

Other <ui-component> elements with the same name are removed.

Keep one instance
<ui-component name="demo"></ui-component>
<ui-component name="demo"></ui-component>

<script>
COMPONENT('demo', function(self) {
    self.singleton();
});

console.log($('ui-component').length);
// logs: 1
</script>
method

watch(path, callback, [autoinit])

Calls a function on each change at a path.
ParameterTypeDescription
path String The path to observe.
callback Function A function (value, flags, path).
autoinit? Boolean Calls the function right away with the current value. Default: false

Join several paths with +. With a function as the first argument, the path of the component is observed. A ? is replaced with the path of the parent plugin.

Observe another path
com.watch('common.user', (value, flags, path) => console.log(value, path));
SET('common.user', 'Anna');
// logs: Anna common.user
method

unwatch(path, [callback])

Removes watchers registered with watch().
ParameterTypeDescription
path String The observed path.
callback? Function The watcher to remove.

Without callback, all the watchers of the path registered by this component are removed. With a function as the only argument, the watcher of the component path is removed. Join several paths with +. A ? is replaced with the path of the parent plugin.

Stop observing a path
var log = value => console.log('changed', value);

com.watch('common.count', log);
SET('common.count', 1);
com.unwatch('common.count', log);
SET('common.count', 2);
// logs: changed 1
method

datasource(path, callback, [init])

Observes a path with data for the component.
ParameterTypeDescription
path String The path to observe.
callback Function A function (value, flags, path).
init? Boolean Set false to skip the first call. Default: true

Returns Component The instance.

The function is called with the current value when the component initializes, unless init is false, and on each change. A new call replaces the data source registered before, and datasource(null) removes it.

Render items from a path
<ui-component name="demo"></ui-component>

<script>
var common = { items: ['a'] };

COMPONENT('demo', function(self) {
    self.make = function() {
        self.datasource('common.items', value => console.log(value.join()));
    };
});

SET('common.items', ['a', 'b']);
// logs: a
// logs: a,b
</script>
method

on(name, callback)

Registers a handler of a global event.
ParameterTypeDescription
name String The event name.
callback Function The handler.

Join several event names with +. See Events.

Handle an event
var handler = value => console.log(value);
com.on('refresh', handler);
EMIT('refresh', 1);
com.off('refresh', handler);
EMIT('refresh', 2);
// logs: 1
method

off(name, [callback])

Removes a handler of a global event.
ParameterTypeDescription
name String The event name.
callback? Function The handler to remove.

Without a callback, all handlers of the event registered on this instance are removed.

method

emit(name, [a], [b], [c], [d])

Emits a global event.
ParameterTypeDescription
name String The event name.
a? Object The first argument.
b? Object The second argument.
c? Object The third argument.
d? Object The fourth argument.
Emit an event
ON('saved', value => console.log(value));
com.emit('saved', 'ok');
// logs: ok
method

command(name, callback)

Registers a command of this instance.
ParameterTypeDescription
name String The command name.
callback Function The handler.
Register and run a command
com.command('clear', value => console.log('clear', value));
com.CMD('clear', 1);
// logs: clear 1
method

CMD(name, [a], [b], [c], [d], [e])

Runs a command registered on this instance with command().
ParameterTypeDescription
name String The command name.
a? Object The first argument.
b? Object The second argument.
c? Object The third argument.
d? Object The fourth argument.
e? Object The fifth argument.
method

GET(path)

Reads a value from a path. A ? is replaced with the path of the parent plugin.
ParameterTypeDescription
path String The path.

Returns Object The value.

Work with the model of the plugin
<ui-plugin path="orders"><ui-component name="demo"></ui-component></ui-plugin>

<script>
COMPONENT('demo', function(self) {
    self.make = function() {
        self.SET('?.count', 3);
        console.log(self.GET('?.count'));
    };
});
// logs: 3
</script>
method

SET(path, value)

Writes a value to a path and notifies everything bound to it. A ? is replaced with the path of the parent plugin.
ParameterTypeDescription
path String The path.
value Object The value to write.
method

EXEC(name, [a], [b], [c], [d])

Calls a function or a plugin method.
ParameterTypeDescription
name String For example FUNC.save, ?/save or @save.
a? Object The first argument.
b? Object The second argument.
c? Object The third argument.
d? Object The fourth argument.

A ? is replaced with the path of the parent plugin. A name that starts with @ calls a method of the closest parent component.

Call a method of the parent component
<ui-component name="parent">
    <ui-component name="child"></ui-component>
</ui-component>

<script>
COMPONENT('parent', function(self) {
    self.refreshlist = value => console.log('parent', value);
});

COMPONENT('child', function(self) {
    window.com = self;
});

com.EXEC('@refreshlist', 1);
// logs: parent 1
</script>
method

SEEX(name, [a], [b], [c], [d])

Calls a plugin method or a global function, or writes the first argument to the path.
ParameterTypeDescription
name String The method, the function or the path.
a? Object The first argument.
b? Object The second argument.
c? Object The third argument.
d? Object The fourth argument.

The form plugin/method calls a method of the plugin and a name of a global function calls that function. Any other name is a path that receives a.

Write to a path
com.SEEX('common.status', 'done');
console.log(common.status);
// logs: done
method

SETTER(name, [a], [b], [c], [d])

Calls a method of components in the whole page, in the form component/method.
ParameterTypeDescription
name String The target, for example grid/refresh.
a? Object The first argument.
b? Object The second argument.
c? Object The third argument.
d? Object The fourth argument.
Call a method of another component
<ui-component name="grid"></ui-component>
<ui-component name="demo"></ui-component>

<script>
COMPONENT('grid', function(self) {
    self.reload = value => console.log('reload', value);
});

COMPONENT('demo', function(self) {
    window.com = self;
});

com.SETTER('grid/reload', 1);
// logs: reload 1
</script>
method

find(selector)

Finds elements inside the component.
ParameterTypeDescription
selector String A selector, or an object with selectors.

Returns jQuery The found elements, or an object of them.

With an object, the method searches for each selector and returns an object with the same keys.

Find elements
<ui-component name="demo"><input /><b></b></ui-component>

<script>
COMPONENT('demo', function(self) {
    window.com = self;
});

console.log(com.find('input').length, com.find({ title: 'b' }).title.length);
// logs: 1 1
</script>
method

closest(selector)

Finds the closest parent that matches a selector.
ParameterTypeDescription
selector String A jQuery selector.

Returns jQuery The found element.

Find a parent
console.log(com.closest('body')[0].tagName);
// logs: BODY
method

parent([selector])

Finds a parent element.
ParameterTypeDescription
selector? String The selector.

Returns jQuery The found element.

Without an argument, the method returns the direct parent. These values are also supported:

SelectorResult
autoThe closest parent with a height set in its style, or window
windowThe window object as jQuery
documentThe document as jQuery
parent followed by a numberThe parent that many levels above the direct parent
anything elseThe closest parent that matches the selector
Read the direct parent
console.log(com.parent()[0].tagName);
// logs: BODY
method

html([value])

Reads or replaces the HTML of the element.
ParameterTypeDescription
value? String The new content.

Returns jQuery The element, or the current HTML without an argument.

An array is joined into one string.

Set the content
com.html(['<b>', 'Hello', '</b>']);
console.log(com.html());
// logs: <b>Hello</b>
method

text([value])

Reads or replaces the text of the element.
ParameterTypeDescription
value? String The new text.

Returns jQuery The element, or the current text without an argument.

An array is joined into one string.

Set the text
com.text('Hello');
console.log(com.text());
// logs: Hello
method

append(value)

Adds HTML to the end of the element.
ParameterTypeDescription
value String The content.

Returns jQuery The element.

An array is joined into one string.

Add content
com.append('<i></i>');
com.append(['<b>', '</b>']);
console.log(com.html());
// logs: <i></i><b></b>
method

empty()

Removes the content of the element.

Returns Component The instance.

method

attr(name, [value])

Reads or sets an attribute of the element.
ParameterTypeDescription
name String The attribute.
value? String The new value.

Returns Object The value when reading, the instance when setting.

Attributes
com.attr('title', 'Hello');
com.attrd('id', 5);
console.log(com.attr('title'), com.attrd('id'));
// logs: Hello 5
method

attrd(name, [value])

Reads or sets a data- attribute of the element.
ParameterTypeDescription
name String The name without the data- prefix.
value? String The new value.

Returns String The value when reading.

method

css(name, [value])

Reads or sets a CSS property of the element.
ParameterTypeDescription
name String The property.
value? String The new value.

Returns Object The value when reading, the instance when setting.

Change a style
com.css('color', 'red');
console.log(com.css('color'));
// logs: rgb(255, 0, 0)
method

aclass(name, [timeout])

Adds a CSS class to the element.
ParameterTypeDescription
name String The class.
timeout? Number A delay in milliseconds.

Returns Component The instance.

Work with classes
com.aclass('a b');
com.rclass('a');
com.tclass('c');
console.log(com.element.attr('class'), com.hclass('c'));
// logs: b c true
method

rclass([name], [timeout])

Removes a CSS class from the element, or all classes without an argument.
ParameterTypeDescription
name? String The class.
timeout? Number A delay in milliseconds.

Returns Component The instance.

method

rclass2(search)

Removes all CSS classes that contain a text.
ParameterTypeDescription
search String The text to search for.

Returns Component The instance.

Remove a group of classes
com.aclass('size-1 size-2 box');
com.rclass2('size-');
console.log(com.element.attr('class'));
// logs: box
method

tclass(name, [enable])

Toggles a CSS class on the element.
ParameterTypeDescription
name String The class.
enable? Boolean Forces the state of the class.

Returns Component The instance.

method

hclass(name)

Tells whether the element has a CSS class.
ParameterTypeDescription
name String The class.

Returns Boolean true when the class is present.

method

width()

Returns the width of the element in pixels.

Returns Number The width.

method

height()

Returns the height of the element in pixels.

Returns Number The height.

method

event(name, [selector], callback)

Registers a DOM event handler on the element.
ParameterTypeDescription
name String The DOM event.
selector? String Limits the event to matching children.
callback Function The handler.

Returns Component The instance.

The arguments are passed to the jQuery .on() method.

Handle a click
<ui-component name="demo"><button>Save</button></ui-component>

<script>
COMPONENT('demo', function(self) {
    self.make = function() {
        self.event('click', 'button', () => console.log('clicked'));
    };
});

$('button').trigger('click');
// logs: clicked
</script>
method

autofocus([selector])

Moves the focus to the first visible control inside the element.
ParameterTypeDescription
selector? String The elements to focus.

Returns Component The instance.

The default selector is input,select,textarea. When no control can take the focus yet, the method tries again every 200 milliseconds, 15 times at most. The focus is not moved on mobile devices.

Focus the first input
<ui-component name="demo"><input id="first" /></ui-component>

<script>
COMPONENT('demo', function(self) {
    window.com = self;
});

com.autofocus();
console.log(document.activeElement.id);
// logs: first
</script>
method

import(url, [callback], [prepare])

Downloads content and appends it to the element.
ParameterTypeDescription
url String The address.
callback? Function Runs when the content is in the page.
prepare? Function A function (html) that returns the content to insert.

See IMPORT() in Importing content.

Import a part
com.import('/parts/help.html', () => console.log(com.html()), html => html + '<hr>');
// logs: <p>Help</p><hr>
method

replace(target, [remove])

Moves the component to another element.
ParameterTypeDescription
target Element The new element, as a selector, a DOM element or jQuery.
remove? Boolean Removes the original element. Default: false

Returns Component The instance.

With remove, the original element is removed from the page.

Move the component
com.replace('#box', true);
console.log(com.dom.id, $('ui-component').length);
// logs: box 0
method

remove()

Calls destroy and removes the component and its element.
method

icon(value)

Adds the icon prefix in DEF.iconprefix to an icon name.
ParameterTypeDescription
value String The icon name.

Returns String The CSS classes of the icon.

A value with a space already contains its prefix and stays unchanged.

Build icon classes
console.log(com.icon('home'));
// logs: ti ti-home
console.log(com.icon('fa fa-home'));
// logs: fa fa-home
method

caniuse(name)

Finds the first declared component in a list of names separated with a comma or |.
ParameterTypeDescription
name String The names.

Returns String The found name, or false.

Choose an available component
console.log(com.caniuse('missing,demo'));
// logs: demo
console.log(com.caniuse('missing|demo'));
// logs: demo
console.log(com.caniuse('missing'));
// logs: false
method

parseSource(value)

Parses a list in the form id|name|icon,id|name|icon.
ParameterTypeDescription
value String The list.

Returns Array Objects with id, name and icon.

The method is also available as parsesource(). When the type config key is number, the identifiers are converted to numbers.

Parse a list
var items = com.parseSource('1|One,2|Two|home');
console.log(JSON.stringify(items[1]));
// logs: {"id":"2","name":"Two","icon":"home"}
Made in Europe