---
title: Eventi
project: jComponent V19
version: 19.194
section: reference
language: it
license: MIT
url: https://totaljs.es/docs/it/jcomponent-v19/19-194/reference/events/
updated: 2026-11-18T13:58:24.464Z
---

# Eventi

> Gli eventi emessi dalla libreria.

Gestisci questi eventi con [ON()](../globals/#on) e rimuovi i gestori con [OFF()](../globals/#off). I tuoi eventi usano le stesse funzioni con [EMIT()](../globals/#emit).

## API

### ON('init', function() {})

Type: `event`

Viene eseguito una volta quando i primi componenti sono pronti, subito prima di `ready`.

Una pagina senza componenti non emette questo evento.

Example: Esempio
```js
ON('init', function() {
	console.log('init'); // init
});
```

### ON('ready', function() {})

Type: `event`

Viene eseguito una volta quando i primi componenti sono pronti.

Un gestore registrato in seguito viene eseguito immediatamente. Una pagina senza componenti non emette questo evento.

Example: Esempio
```js
ON('ready', function() {
	console.log('ready'); // ready
});
```

### ON('component', function(component) {})

Type: `event`

Viene eseguito quando un componente è pronto.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `component` | `Component` | yes |  | Il componente. |

Example: Esempio
```js
ON('component', function(com) {
	console.log(com.path); // data.box
});
```

### ON('@name', function(component) {})

Type: `event`

Viene eseguito quando un componente con questo nome è pronto.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `component` | `Component` | yes |  | Il componente. |

Example: Esempio
```js
ON('@box', function(com) {
	console.log(com.name); // box
});
```

### ON('#id', function(component) {})

Type: `event`

Viene eseguito quando un componente con questo identificatore è pronto.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `component` | `Component` | yes |  | Il componente. |

Example: Esempio
```js
ON('#mybox', function(com) {
	console.log(com.id); // mybox
});
```

### ON('component.compile', function(name, declaration) {})

Type: `event`

Viene eseguito quando viene dichiarato un componente.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Il nome. |
| `declaration` | `Object` | yes |  | La dichiarazione. |

Example: Esempio
```js
ON('component.compile', function(name) {
	console.log(name); // hello
});
COMPONENT('hello', NOOP);
```

### ON('component.destroy', function(name, component) {})

Type: `event`

Viene eseguito quando viene rimosso un componente.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Il nome. |
| `component` | `Component` | yes |  | Il componente. |

Example: Esempio
```js
ON('component.destroy', function(name) {
	console.log(name); // box
});
ON('ready', function() {
	FIND('box').remove();
});
```

### ON('destroy', function(name, component) {})

Type: `event`

Viene eseguito quando viene rimosso un componente.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Il nome. |
| `component` | `Component` | yes |  | Il componente. |

Example: Esempio
```js
ON('destroy', function(name) {
	console.log(name); // box
});
ON('ready', function() {
	FIND('box').remove();
});
```

### ON('lazy', function(name, loading) {})

Type: `event`

Viene eseguito quando un componente lazy inizia e finisce il caricamento.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Il nome. |
| `loading` | `Boolean` | yes |  | `true` all'inizio, `false` alla fine. |

Example: Esempio
```js
ON('lazy', function(name, loading) {
	console.log(name, loading); // box true
});
setTimeout(() => SETTER('box', 'hello', 'Peter'), 500);
```

### ON('binder', function(binder) {})

Type: `event`

Viene eseguito quando un'associazione dei dati è pronta.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `binder` | `Object` | yes |  | L'associazione. |

Example: Esempio
```js
ON('binder', function(binder) {
	console.log(binder.path); // user.name
});
```

### ON('plugin', function(plugin) {})

Type: `event`

Viene eseguito quando viene creato un plugin.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `plugin` | `Plugin` | yes |  | Il plugin. |

Example: Esempio
```js
ON('plugin', function(plugin) {
	console.log(plugin.name); // users
});
PLUGIN('users', NOOP);
```

### ON('plugin.destroy', function(plugin) {})

Type: `event`

Viene eseguito quando viene rimosso un plugin.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `plugin` | `Plugin` | yes |  | Il plugin. |

Example: Esempio
```js
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);
```

### ON('cmd', function(name, a, b, c, d, e) {})

Type: `event`

Viene eseguito prima che un comando venga inviato ai componenti.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Il comando. |
| `a` | `Object` | yes |  | Fino a cinque argomenti. |

Example: Esempio
```js
ON('cmd', function(name, value) {
	console.log(name, value); // refresh 1
});
CMD('refresh', 1);
```

### ON('exec', function(path, a, b, c, d) {})

Type: `event`

Viene eseguito prima che [EXEC()](../globals/#exec) chiami una funzione o un metodo di un plugin.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | La destinazione. |
| `a` | `Object` | yes |  | Fino a quattro argomenti. |

Example: Esempio
```js
ON('exec', function(path, value) {
	console.log(path, value); // app.run 1
});
window.app = { run: NOOP };
EXEC('app.run', 1);
```

### ON('setter', function(selector, method, a, b) {})

Type: `event`

Viene eseguito prima che [SETTER()](../globals/#setter) chiami i componenti.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `selector` | `String` | yes |  | Il selettore. |
| `method` | `String` | yes |  | Il metodo. |
| `a` | `Object` | yes |  | I primi due argomenti, `a` e `b`. |

Example: Esempio
```js
ON('setter', function(selector, method, value) {
	console.log(selector, method, value); // box hello 1
});
SETTER('box', 'hello', 1);
```

### ON('env', function(name, value) {})

Type: `event`

Viene eseguito quando viene scritta una variabile d'ambiente.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Il nome. |
| `value` | `Object` | yes |  | Il valore. |

Example: Esempio
```js
ON('env', function(name, value) {
	console.log(name, value); // api /v1/
});
ENV('api', '/v1/');
```

### ON('import', function(url, target) {})

Type: `event`

Viene eseguito dopo l'importazione dei contenuti.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `url` | `String` | yes |  | L'URL. Per i contenuti HTML, inizia con `$import`. |
| `target` | `jQuery` | yes |  | L'elemento di destinazione, oppure l'elemento `script` o `link` creato. |

Example: Esempio
```js
ON('import', function(url, target) {
	console.log(target.length); // 1
});
IMPORT('/part.html');
```

### ON('request', function(options) {})

Type: `event`

Viene eseguito prima dell'invio di una richiesta.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `options` | `Object` | yes |  | La richiesta: `url`, `method`, `headers`, `data`, `upload`, `scope` e altro. |

Imposta `options.cancel = true` per interrompere la richiesta. `options.respond(response, [headers])` risponde senza un server e `options.throw(response, [headers], code)` risponde con un errore.

Example: Esempio
```js
ON('request', function(options) {
	console.log(options.method, options.url); // GET /api/
	options.respond({ ok: true });
});
AJAX('GET /api/', NOOP);
```

### ON('response', function(output) {})

Type: `event`

Viene eseguito dopo l'arrivo di una risposta, prima della callback della richiesta.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `output` | `Object` | yes |  | Il risultato: `url`, `method`, `status`, `response`, `raw`, `headers`, `error`, `duration` e altro. |

Imposta `output.process = false` per saltare la callback della richiesta.

Example: Esempio
```js
ON('response', function(output) {
	console.log(output.status, output.response.ok); // 200 true
});
AJAX('GET /api/', NOOP);
```

### ON('error', function(output) {})

Type: `event`

Viene eseguito quando una richiesta non riesce.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `output` | `Object` | yes |  | Il risultato della richiesta. |

L'evento non viene emesso quando `DEF.ajaxerrors` è `true`.

Example: Esempio
```js
ON('error', function(output) {
	console.log(output.status); // 500
});
AJAX('GET /api/', NOOP);
```

### ON('ERROR', function(response) {})

Type: `event`

Viene eseguito quando [ERROR()](../globals/#error) trova un errore.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `response` | `Object` | yes |  | Il valore controllato. |

Example: Esempio
```js
ON('ERROR', function(response) {
	console.log(response[0].error); // Invalid
});
ERROR([{ error: 'Invalid' }]);
```

### ON('knockknock', function(counter) {})

Type: `event`

Viene eseguito ogni minuto.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `counter` | `Number` | yes |  | Il numero di esecuzioni. |

Example: Esempio
```js
ON('knockknock', function(counter) {
	console.log(counter); // 1
});
```

### ON('service', function(counter) {})

Type: `event`

Viene eseguito ogni minuto, subito prima di `knockknock`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `counter` | `Number` | yes |  | Il numero di esecuzioni. |

Example: Esempio
```js
ON('service', function(counter) {
	console.log(counter); // 1
});
```

### ON('resize2', function() {})

Type: `event`

Viene eseguito dopo che la dimensione della finestra è cambiata.

È ritardato di 300 millisecondi e viene eseguito anche una volta all'avvio della pagina.

Example: Esempio
```js
ON('resize2', function() {
	console.log(typeof(WW)); // number
});
```

### ON('scroll', function(area) {})

Type: `event`

Viene eseguito quando inizia lo scorrimento in una [SCROLLBAR()](../globals/#scrollbar).

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `area` | `jQuery` | yes |  | L'elemento fatto scorrere. |

Example: Esempio
```js
ON('scroll', function(area) {
	console.log(area.length); // 1
});
var scrollbar = SCROLLBAR($('#box'), { native: true });
scrollbar.area.trigger('scroll');
```

### ON('scrollidle', function(area) {})

Type: `event`

Viene eseguito quando si ferma lo scorrimento in una [SCROLLBAR()](../globals/#scrollbar).

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `area` | `jQuery` | yes |  | L'elemento fatto scorrere. |

Example: Esempio
```js
ON('scrollidle', function(area) {
	console.log(area.length); // 1
});
var scrollbar = SCROLLBAR($('#box'), { native: true });
scrollbar.area.trigger('scroll');
```

### ON('visible', function(visible) {})

Type: `event`

Viene eseguito quando la pagina passa in background o torna in primo piano.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `visible` | `Boolean` | yes |  | `true` quando la pagina è visibile. |

Example: Esempio
```js
ON('visible', function(visible) {
	console.log(visible); // true
});
$(window).trigger('visibilitychange');
```

### ON('@flag name', function(path, value, type) {})

Type: `event`

Viene eseguito quando un path o un metodo viene usato con il flag personalizzato `@name`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | Il path. |
| `value` | `Object` | yes |  | Il valore. |
| `type` | `Number` | yes |  | Il tipo di modifica. |

Example: Esempio
```js
ON('@flag saved', function(path, value) {
	console.log(path, value); // user.age 30
});
SET('user.age @saved', 30);
```
