jComponent V19 19.194
/
Reference
Events
The events that the library emits.
On this page
API
Handle these events with ON() and remove the handlers with OFF() . Your own events use the same functions with EMIT() .
API
Expand all
Collapse all
event
ON('init', function() {})
Runs once when the first components are ready, just before ready.
A page without components does not emit this event.
Example
ON('init', function() {
console.log('init'); // init
});
event
ON('ready', function() {})
Runs once when the first components are ready.
A handler registered later runs immediately. A page without components does not emit this event.
Example
ON('ready', function() {
console.log('ready'); // ready
});
event
ON('component', function(component) {})
Runs when a component is ready.
Parameter Type Description
component
Component
The component.
Example
ON('component', function(com) {
console.log(com.path); // data.box
});
event
ON('@name', function(component) {})
Runs when a component with this name is ready.
Parameter Type Description
component
Component
The component.
Example
ON('@box', function(com) {
console.log(com.name); // box
});
event
ON('#id', function(component) {})
Runs when a component with this identifier is ready.
Parameter Type Description
component
Component
The component.
Example
ON('#mybox', function(com) {
console.log(com.id); // mybox
});
event
ON('component.compile', function(name, declaration) {})
Runs when a component is declared.
Parameter Type Description
name
String
The name.
declaration
Object
The declaration.
Example
ON('component.compile', function(name) {
console.log(name); // hello
});
COMPONENT('hello', NOOP);
event
ON('component.destroy', function(name, component) {})
Runs when a component is removed.
Parameter Type Description
name
String
The name.
component
Component
The component.
Example
ON('component.destroy', function(name) {
console.log(name); // box
});
ON('ready', function() {
FIND('box').remove();
});
event
ON('destroy', function(name, component) {})
Runs when a component is removed.
Parameter Type Description
name
String
The name.
component
Component
The component.
Example
ON('destroy', function(name) {
console.log(name); // box
});
ON('ready', function() {
FIND('box').remove();
});
event
ON('lazy', function(name, loading) {})
Runs when a lazy component starts and finishes loading.
Parameter Type Description
name
String
The name.
loading
Boolean
true at the start, false at the end.
Example
ON('lazy', function(name, loading) {
console.log(name, loading); // box true
});
setTimeout(() => SETTER('box', 'hello', 'Peter'), 500);
event
ON('binder', function(binder) {})
Runs when a data binding is ready.
Parameter Type Description
binder
Object
The binding.
Example
ON('binder', function(binder) {
console.log(binder.path); // user.name
});
event
ON('plugin', function(plugin) {})
Runs when a plugin is created.
Parameter Type Description
plugin
Plugin
The plugin.
Example
ON('plugin', function(plugin) {
console.log(plugin.name); // users
});
PLUGIN('users', NOOP);
event
ON('plugin.destroy', function(plugin) {})
Runs when a plugin is removed.
Parameter Type Description
plugin
Plugin
The plugin.
Example
ON('plugin.destroy', function(plugin) {
console.log(plugin.name); // users
});
// Declaring a plugin again removes the previous one
setTimeout(() => PLUGIN('users', NOOP), 300);
setTimeout(() => PLUGIN('users', NOOP), 600);
event
ON('cmd', function(name, a, b, c, d, e) {})
Runs before a command is sent to components.
Parameter Type Description
name
String
The command.
a
Object
Up to five arguments.
Example
ON('cmd', function(name, value) {
console.log(name, value); // refresh 1
});
CMD('refresh', 1);
event
ON('exec', function(path, a, b, c, d) {})
Runs before EXEC() calls a function or a plugin method.
Parameter Type Description
path
String
The target.
a
Object
Up to four arguments.
Example
ON('exec', function(path, value) {
console.log(path, value); // app.run 1
});
window.app = { run: NOOP };
EXEC('app.run', 1);
event
ON('setter', function(selector, method, a, b) {})
Runs before SETTER() calls components.
Parameter Type Description
selector
String
The selector.
method
String
The method.
a
Object
The first two arguments, a and b.
Example
ON('setter', function(selector, method, value) {
console.log(selector, method, value); // box hello 1
});
SETTER('box', 'hello', 1);
event
ON('env', function(name, value) {})
Runs when an environment variable is written.
Parameter Type Description
name
String
The name.
value
Object
The value.
Example
ON('env', function(name, value) {
console.log(name, value); // api /v1/
});
ENV('api', '/v1/');
event
ON('import', function(url, target) {})
Runs after content is imported.
Parameter Type Description
url
String
The URL. For HTML content, it starts with $import.
target
jQuery
The target element, or the created script or link element.
Example
ON('import', function(url, target) {
console.log(target.length); // 1
});
IMPORT('/part.html');
event
ON('request', function(options) {})
Runs before a request is sent.
Parameter Type Description
options
Object
The request: url, method, headers, data, upload, scope and more.
Set options.cancel = true to stop the request. options.respond(response, [headers]) answers it without a server, and options.throw(response, [headers], code) answers it with an error.
Example
ON('request', function(options) {
console.log(options.method, options.url); // GET /api/
options.respond({ ok: true });
});
AJAX('GET /api/', NOOP);
event
ON('response', function(output) {})
Runs after a response arrives, before the callback of the request.
Parameter Type Description
output
Object
The result: url, method, status, response, raw, headers, error, duration and more.
Set output.process = false to skip the callback of the request.
Example
ON('response', function(output) {
console.log(output.status, output.response.ok); // 200 true
});
AJAX('GET /api/', NOOP);
event
ON('error', function(output) {})
Runs when a request fails.
Parameter Type Description
output
Object
The result of the request.
The event is not emitted when DEF.ajaxerrors is true.
Example
ON('error', function(output) {
console.log(output.status); // 500
});
AJAX('GET /api/', NOOP);
event
ON('ERROR', function(response) {})
Runs when ERROR() finds an error.
Parameter Type Description
response
Object
The checked value.
Example
ON('ERROR', function(response) {
console.log(response[0].error); // Invalid
});
ERROR([{ error: 'Invalid' }]);
event
ON('knockknock', function(counter) {})
Runs every minute.
Parameter Type Description
counter
Number
The number of runs.
Example
ON('knockknock', function(counter) {
console.log(counter); // 1
});
event
ON('service', function(counter) {})
Runs every minute, just before knockknock.
Parameter Type Description
counter
Number
The number of runs.
Example
ON('service', function(counter) {
console.log(counter); // 1
});
event
ON('resize2', function() {})
Runs after the size of the window changes.
It is delayed by 300 milliseconds, and it also runs once when the page starts.
Example
ON('resize2', function() {
console.log(typeof(WW)); // number
});
event
ON('scroll', function(area) {})
Runs when scrolling in a SCROLLBAR() starts.
Parameter Type Description
area
jQuery
The scrolled element.
Example
ON('scroll', function(area) {
console.log(area.length); // 1
});
var scrollbar = SCROLLBAR($('#box'), { native: true });
scrollbar.area.trigger('scroll');
event
ON('scrollidle', function(area) {})
Runs when scrolling in a SCROLLBAR() stops.
Parameter Type Description
area
jQuery
The scrolled element.
Example
ON('scrollidle', function(area) {
console.log(area.length); // 1
});
var scrollbar = SCROLLBAR($('#box'), { native: true });
scrollbar.area.trigger('scroll');
event
ON('visible', function(visible) {})
Runs when the page moves to the background or back.
Parameter Type Description
visible
Boolean
true when the page is visible.
Example
ON('visible', function(visible) {
console.log(visible); // true
});
$(window).trigger('visibilitychange');
event
ON('@flag name', function(path, value, type) {})
Runs when a path or a method is used with the custom flag @name.
Parameter Type Description
path
String
The path.
value
Object
The value.
type
Number
The change type.
Example
ON('@flag saved', function(path, value) {
console.log(path, value); // user.age 30
});
SET('user.age @saved', 30);