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

# Udalosti

> Udalosti, ktoré knižnica vysiela.

Tieto udalosti spracuj pomocou [ON()](../globals/#on) a obslužné funkcie odstráň pomocou [OFF()](../globals/#off). Tvoje vlastné udalosti používajú tie isté funkcie spolu s [EMIT()](../globals/#emit).

## API

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

Type: `event`

Spustí sa raz, keď sú pripravené prvé komponenty, tesne pred `ready`.

Stránka bez komponentov túto udalosť nevyšle.

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

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

Type: `event`

Spustí sa raz, keď sú pripravené prvé komponenty.

Obslužná funkcia zaregistrovaná neskôr sa spustí okamžite. Stránka bez komponentov túto udalosť nevyšle.

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

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

Type: `event`

Spustí sa, keď je komponent pripravený.

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

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

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

Type: `event`

Spustí sa, keď je pripravený komponent s týmto názvom.

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

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

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

Type: `event`

Spustí sa, keď je pripravený komponent s týmto identifikátorom.

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

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

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

Type: `event`

Spustí sa, keď je komponent deklarovaný.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Názov. |
| `declaration` | `Object` | yes |  | Deklarácia. |

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

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

Type: `event`

Spustí sa, keď sa komponent odstráni.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Názov. |
| `component` | `Component` | yes |  | Komponent. |

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

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

Type: `event`

Spustí sa, keď sa komponent odstráni.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Názov. |
| `component` | `Component` | yes |  | Komponent. |

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

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

Type: `event`

Spustí sa, keď komponent s odloženým načítaním začne a dokončí načítavanie.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Názov. |
| `loading` | `Boolean` | yes |  | `true` na začiatku, `false` na konci. |

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

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

Type: `event`

Spustí sa, keď je dátová väzba pripravená.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `binder` | `Object` | yes |  | Väzba. |

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

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

Type: `event`

Spustí sa pri vytvorení pluginu.

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

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

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

Type: `event`

Spustí sa, keď sa plugin odstráni.

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

Example: Príklad
```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`

Spustí sa pred odoslaním príkazu komponentom.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Príkaz. |
| `a` | `Object` | yes |  | Až päť argumentov. |

Example: Príklad
```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`

Spustí sa predtým, ako [EXEC()](../globals/#exec) zavolá funkciu alebo metódu pluginu.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | Cieľ. |
| `a` | `Object` | yes |  | Až štyri argumenty. |

Example: Príklad
```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`

Spustí sa predtým, ako [SETTER()](../globals/#setter) zavolá komponenty.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `selector` | `String` | yes |  | Selektor. |
| `method` | `String` | yes |  | Metóda. |
| `a` | `Object` | yes |  | Prvé dva argumenty, `a` a `b`. |

Example: Príklad
```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`

Spustí sa pri zápise premennej prostredia.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Názov. |
| `value` | `Object` | yes |  | Hodnota. |

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

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

Type: `event`

Spustí sa po importe obsahu.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `url` | `String` | yes |  | URL. Pri obsahu HTML začína na `$import`. |
| `target` | `jQuery` | yes |  | Cieľový element alebo vytvorený element `script` či `link`. |

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

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

Type: `event`

Spustí sa pred odoslaním požiadavky.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `options` | `Object` | yes |  | Požiadavka: `url`, `method`, `headers`, `data`, `upload`, `scope` a ďalšie. |

Nastav `options.cancel = true`, ak chceš požiadavku zastaviť. `options.respond(response, [headers])` na ňu odpovie bez servera a `options.throw(response, [headers], code)` na ňu odpovie chybou.

Example: Príklad
```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`

Spustí sa po prijatí odpovede, pred callbackom požiadavky.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `output` | `Object` | yes |  | Výsledok: `url`, `method`, `status`, `response`, `raw`, `headers`, `error`, `duration` a ďalšie. |

Nastav `output.process = false`, ak chceš callback požiadavky preskočiť.

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

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

Type: `event`

Spustí sa, keď požiadavka zlyhá.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `output` | `Object` | yes |  | Výsledok požiadavky. |

Udalosť sa nevyšle, keď má `DEF.ajaxerrors` hodnotu `true`.

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

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

Type: `event`

Spustí sa, keď [ERROR()](../globals/#error) nájde chybu.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `response` | `Object` | yes |  | Kontrolovaná hodnota. |

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

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

Type: `event`

Spustí sa každú minútu.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `counter` | `Number` | yes |  | Počet spustení. |

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

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

Type: `event`

Spúšťa sa každú minútu, tesne pred `knockknock`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `counter` | `Number` | yes |  | Počet spustení. |

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

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

Type: `event`

Spustí sa po zmene veľkosti okna.

Je oneskorená o 300 milisekúnd a spustí sa aj raz pri štarte stránky.

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

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

Type: `event`

Spustí sa, keď sa začne posúvanie v [SCROLLBAR()](../globals/#scrollbar).

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `area` | `jQuery` | yes |  | Posúvaný element. |

Example: Príklad
```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`

Spustí sa, keď sa posúvanie v [SCROLLBAR()](../globals/#scrollbar) zastaví.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `area` | `jQuery` | yes |  | Posúvaný element. |

Example: Príklad
```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`

Spustí sa, keď stránka prejde na pozadie alebo sa z neho vráti.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `visible` | `Boolean` | yes |  | `true`, keď je stránka viditeľná. |

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

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

Type: `event`

Spustí sa, keď sa path alebo metóda použije s vlastným flagom `@name`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | Path. |
| `value` | `Object` | yes |  | Hodnota. |
| `type` | `Number` | yes |  | Typ zmeny. |

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