ui-plugin
The attributes and configuration keys of the ui-plugin element.
On this page
API
property
path="path"
Sets the path of the scope and selects the plugin.
path="path"The path of a nested element is appended to the path of its parent scope. The attribute accepts these forms:
| Value | Meaning |
|---|---|
users | The scope users, or parent.users inside another scope. |
!users | An 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 template | The scope users with a new plugin created from PLUGIN('* template', fn). |
users__config__default | The path, configuration and default value in one attribute. |
The plugin of an element without content is removed when the library cleans up unused objects.
<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>
<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>
<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>
<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.
config="key:value"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.
<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.
default="expression"The attribute contains a JavaScript expression. The default() method of the scope restores the value.
<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.
data-jc-value="expression"It is used when the default attribute is missing.
<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.
data-jc-class="classes"It is used when the class configuration key is missing.
<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.
data-jc-init="path"It is used when the init configuration key is missing. The function has the same arguments as init.
<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.
isolated:trueIt has the same effect as the ! prefix of the path.
<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.
aclass:true<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.
class:classesSeparate several classes with a space. The delay key sets 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.
delay:millisecondsThe default value is 300.
<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.
init:pathThe 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.
<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.
plugin="path"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.
<div plugin="users"><span></span></div>
<script>
PLUGIN('users', function(exports) {});
setTimeout(() => console.log($('span').scope().path), 500); // users
</script>