Spanish Total.js
English
Documentation For AI agents
Contents

ui-plugin

The attributes and configuration keys of the ui-plugin element.

.md GitHub
On this page

The <ui-plugin> element creates a Scope for its content and connects it to the Plugin with the same path. The concept is explained in Scopes and Plugins.

API

property

path="path"

Sets the path of the scope and selects the plugin.

The path of a nested element is appended to the path of its parent scope. The attribute accepts these forms:

ValueMeaning
usersThe scope users, or parent.users inside another scope.
!usersAn isolated scope. Its path ignores the parent scope.
?A scope with a generated unique path. An empty or missing path does the same.
*The scope common, taken from DEF.pathcommon.
users templateThe scope users with a new plugin created from PLUGIN('* template', fn).
users__config__defaultThe path, configuration and default value in one attribute.

The plugin of an element without content is removed when the library cleans up unused objects.

Nested scopes
<ui-plugin path="users">
    <ui-plugin path="detail">
        <span></span>
    </ui-plugin>
</ui-plugin>

<script>
    PLUGIN('users', function(exports) {});
    PLUGIN('users.detail', function(exports) {});
    setTimeout(() => console.log($('span').scope().path), 500);  // users.detail
</script>
An isolated scope
<ui-plugin path="users">
    <ui-plugin path="!settings">
        <span></span>
    </ui-plugin>
</ui-plugin>

<script>
    PLUGIN('users', function(exports) {});
    PLUGIN('settings', function(exports) {});
    setTimeout(() => console.log($('span').scope().path), 500);  // settings
</script>
A reusable plugin template
<ui-plugin path="orders counter"><span></span></ui-plugin>
<ui-plugin path="invoices counter"><span></span></ui-plugin>

<script>
    PLUGIN('* counter', function(exports) {
        console.log(exports.name);
    });
</script>
Path, configuration and default value together
<ui-plugin path="users__aclass:1__{ page: 1 }"><span></span></ui-plugin>

<script>
    PLUGIN('users', function(exports) {});
    setTimeout(() => console.log(GET('users.page'), $('ui-plugin').attr('class')), 500);  // 1 users
</script>
property

config="key:value"

Configures the scope.

The value is a list of key:value pairs. The keys are listed on this page, and all of them are available in scope.config.

Reading the configuration
<ui-plugin path="users" config="limit:10"><span></span></ui-plugin>

<script>
    PLUGIN('users', function(exports) {});
    setTimeout(() => console.log($('span').scope().config.limit), 500);  // 10
</script>
property

default="expression"

Sets the initial value of the scope path.

The attribute contains a JavaScript expression. The default() method of the scope restores the value.

An initial model
<ui-plugin path="users" default="{ page: 1 }"><span></span></ui-plugin>

<script>
    PLUGIN('users', function(exports) {});
    setTimeout(() => console.log(GET('users')), 500);  // {"page":1}
</script>
property

data-jc-value="expression"

Sets the initial value of the scope path.

It is used when the default attribute is missing.

An initial model
<ui-plugin path="users" data-jc-value="{ page: 2 }"><span></span></ui-plugin>

<script>
    PLUGIN('users', function(exports) {});
    setTimeout(() => console.log(GET('users.page')), 500);  // 2
</script>
property

data-jc-class="classes"

Toggles CSS classes on the element.

It is used when the class configuration key is missing.

A class after the initialization
<ui-plugin path="users" data-jc-class="ready" config="delay:10"><span></span></ui-plugin>
<script>PLUGIN('users', function(exports) {});</script>
property

data-jc-init="path"

Calls a function when the scope is created.

It is used when the init configuration key is missing. The function has the same arguments as init.

An initialization function
<ui-plugin path="users" data-jc-init="common.onscope"><span></span></ui-plugin>

<script>
    window.common = { onscope: path => console.log(path) };  // users
    PLUGIN('users', function(exports) {});
</script>
config

isolated:true

Makes the path of the scope independent of the parent scope.

It has the same effect as the ! prefix of the path.

An isolated scope
<ui-plugin path="users">
    <ui-plugin path="settings" config="isolated:true"><span></span></ui-plugin>
</ui-plugin>

<script>
    PLUGIN('users', function(exports) {});
    PLUGIN('settings', function(exports) {});
    setTimeout(() => console.log($('span').scope().path), 500);  // settings
</script>
config

aclass:true

Adds the path of the scope to the element as a CSS class.
The path as a class
<ui-plugin path="users" config="aclass:true"><span></span></ui-plugin>
<script>PLUGIN('users', function(exports) {});</script>
config

class:classes

Toggles CSS classes on the element after a delay.

Separate several classes with a space. The delay key sets the delay.

Classes after the delay
<ui-plugin path="users" config="class:ready"><span></span></ui-plugin>
<script>PLUGIN('users', function(exports) {});</script>
config

delay:milliseconds

Sets the delay of the class key in milliseconds.

The default value is 300.

A shorter delay
<ui-plugin path="users" config="class:ready;delay:10"><span></span></ui-plugin>

<script>
    PLUGIN('users', function(exports) {});
    setTimeout(() => console.log($('ui-plugin').hclass('ready')), 500);  // true
</script>
config

init:path

Calls a function when the scope is created.

The function receives the path and the element of the scope, and this is the Scope. A ? in the value is replaced with the path of the scope.

An initialization function
<ui-plugin path="users" config="init:common.onscope"><span></span></ui-plugin>

<script>
    window.common = {
        onscope: function(path, element) {
            console.log(path, element.prop('tagName'), this.path);  // users UI-PLUGIN users
        }
    };
    PLUGIN('users', function(exports) {});
</script>
type

plugin="path"

Other elements can create a scope with an attribute.

Use plugin, data-plugin, scope or data-scope on any element. The <ui-component>, <ui-bind> and <ui-import> elements accept only the plugin attribute. The value has the same forms as path.

A scope on a div
<div plugin="users"><span></span></div>

<script>
    PLUGIN('users', function(exports) {});
    setTimeout(() => console.log($('span').scope().path), 500);  // users
</script>
Made in Europe