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

# Plugin

> Vlastnosti, delegate a metódy inštancie pluginu.

Inštancia pluginu je objekt odovzdaný deklarácii `PLUGIN()`. Obsahuje logiku časti stránky a pracuje s údajmi pod vlastnou path. Koncept vysvetľuje časť [Pluginy](../../guides/plugins/) a element popisuje časť [ui-plugin](../ui-plugin/). V príkladoch je `plugin` inštancia pluginu `users`.

## API

### exports.destroy = function()

Type: `delegate`

Spustí sa pri odstránení pluginu.

Example: Uvoľnenie zdrojov
```html
<ui-plugin path="users"><span></span></ui-plugin>

<script>
    PLUGIN('users', function(exports) {
        exports.destroy = () => console.log('destroyed');  // destroyed
    });
    setTimeout(() => PLUGINS.users.remove(), 500);
</script>
```

### plugin.name

Type: `property`

Path pluginu.

Example: Čítanie name
```js
console.log(plugin.name);  // users
```

### plugin.id

Type: `property`

Identifikátor pluginu.

Je to názov s predponou `plug`.

Example: Čítanie id
```js
console.log(plugin.id);  // plugusers
```

### plugin.element

Type: `property`

Element pluginu ako objekt jQuery.

Je to element scopu. Plugin bez scopu používa `body`.

Example: Čítanie element
```js
console.log(plugin.element.prop('tagName'));  // UI-PLUGIN
```

### plugin.model

Type: `property`

Prečíta alebo nahradí celý model pluginu.

Čítanie chýbajúceho modelu vráti prázdny objekt.

Example: Čítanie model
```js
plugin.model = { name: 'Peter' };
console.log(plugin.model.name);  // Peter
```

### plugin.data

Type: `property`

Prečíta alebo nahradí celý model pluginu.

Je to to isté ako `model`.

Example: Čítanie data
```js
plugin.data = { name: 'Anna' };
console.log(plugin.data.name);  // Anna
```

### plugin.form

Type: `property`

Vráti model a resetuje stav jeho komponentov.

Čítanie tejto vlastnosti vymaže stav dotknutia a úpravy komponentov naviazaných na model.

Example: Čítanie form
```js
plugin.set('name', 'Peter');
console.log(plugin.form);  // {"name":"Peter"}
```

### plugin.modified

Type: `property`

Vráti polia zmenené komponentmi.

Čítanie tejto vlastnosti vymaže stav dotknutia a úpravy komponentov naviazaných na model.

Example: Čítanie modified
```js
FIND('field').modify('Peter');
console.log(plugin.modified);  // {"name":"Peter"}
```

### plugin.parent

Type: `property`

Plugin nadradeného scopu.

Ak nadradený scope neexistuje, hodnota je `null`.

Example: Čítanie parent
```js
console.log(PLUGINS['users.detail'].parent.name);  // users
```

### plugin.caller

Type: `property`

Plugin, ktorý bol aktívny pri vytvorení tohto pluginu.

Ak nebol aktívny žiadny plugin, hodnota je `null`.

Example: Čítanie caller
```js
console.log(plugin.caller);  // null
```

### plugin.set([path], value, [type])

Type: `method`

Zapíše hodnotu na path pluginu.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | no |  | Relatívny path. |
| `value` | `Object` | yes |  | Hodnota. |
| `type` | `Number` | no |  | Typ zmeny. Hodnota `10` alebo vyššia je oneskorenie v milisekundách. |

Returns: `Plugin` Plugin.

Pri jednom argumente hodnota nahradí celý model.

Example: Použitie set()
```js
plugin.set('name', 'Peter');
console.log(GET('users.name'));  // Peter
```

### plugin.get([path])

Type: `method`

Prečíta path pluginu.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | no |  | Relatívny path. |

Returns: `Object` Hodnota.

Bez argumentu metóda vráti celý model.

Example: Použitie get()
```js
plugin.set('name', 'Peter');
console.log(plugin.get('name'));  // Peter
```

### plugin.nul(path, [type])

Type: `method`

Zapíše `null` na path pluginu.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | Relatívny path. |
| `type` | `Number` | no |  | Typ zmeny. Hodnota `10` alebo vyššia je oneskorenie v milisekundách. |

Returns: `Plugin` Plugin.

Example: Použitie nul()
```js
plugin.set('name', 'Peter');
plugin.nul('name');
console.log(plugin.get('name'));  // null
```

### plugin.push([path], value, [type])

Type: `method`

Pridá položku do poľa.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | no |  | Relatívny path. |
| `value` | `Object` | yes |  | Položka. |
| `type` | `Number` | no |  | Typ zmeny. Hodnota `10` alebo vyššia je oneskorenie v milisekundách. |

Returns: `Plugin` Plugin.

Pri jednom argumente sa položka pridá priamo do modelu.

Example: Použitie push()
```js
plugin.push('items', 'A');
plugin.push('items', 'B');
console.log(plugin.get('items'));  // ["A","B"]
```

### plugin.extend([path], value, [type])

Type: `method`

Zlúči objekt do path.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | no |  | Relatívny path. |
| `value` | `Object` | yes |  | Polia. |
| `type` | `Number` | no |  | Typ zmeny. Hodnota `10` alebo vyššia je oneskorenie v milisekundách. |

Returns: `Plugin` Plugin.

Pri jednom argumente sa objekt zlúči priamo do modelu.

Example: Použitie extend()
```js
plugin.extend('user', { name: 'Peter' });
plugin.extend('user', { age: 30 });
console.log(plugin.get('user'));  // {"name":"Peter","age":30}
```

### plugin.inc([path], value, [type])

Type: `method`

Zvýši číslo.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | no |  | Relatívny path. |
| `value` | `Number` | yes |  | Prírastok. |
| `type` | `Number` | no |  | Typ zmeny. Hodnota `10` alebo vyššia je oneskorenie v milisekundách. |

Returns: `Plugin` Plugin.

Pri jednom argumente sa zvýši priamo model.

Example: Použitie inc()
```js
plugin.inc('count', 2);
plugin.inc('count', 3);
console.log(plugin.get('count'));  // 5
```

### plugin.toggle(path, [type])

Type: `method`

Invertuje logickú hodnotu.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | Relatívny path. |
| `type` | `Number` | no |  | Typ zmeny. Hodnota `10` alebo vyššia je oneskorenie v milisekundách. |

Returns: `Plugin` Plugin.

Example: Použitie toggle()
```js
plugin.toggle('open');
console.log(plugin.get('open'));  // true
```

### plugin.upd([path], [type])

Type: `method`

Upozorní poslucháčov path.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | no |  | Relatívny path. |
| `type` | `Number` | no |  | Typ zmeny. Hodnota `10` alebo vyššia je oneskorenie v milisekundách. |

Returns: `Plugin` Plugin.

Example: Použitie upd()
```js
plugin.watch('name', value => console.log(value));  // Peter
window.users.name = 'Peter';
plugin.upd('name');
```

### plugin.reset([path])

Type: `method`

Vymaže stav komponentov naviazaných na path.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | no |  | Relatívny path. |

Returns: `Plugin` Plugin.

Vymaže sa stav dotknutia a úpravy. Hodnota sa nezmení.

Example: Použitie reset()
```js
var com = FIND('field');
com.modify('Peter');
plugin.reset();
console.log(com.config.touched, GET('users.name'));  // false Peter
```

### plugin.watch(path, callback, [init])

Type: `method`

Sleduje path pluginu.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | Relatívny path. |
| `callback` | `Function` | yes |  | Funkcia, ktorá dostáva zmeny. |
| `init` | `Boolean` | no |  | `true` zavolá callback okamžite. |

Returns: `Plugin` Plugin.

Callback dostane `value`, `path` a `type`. Viacero path oddeľ čiarkou alebo ` + `.

Example: Použitie watch()
```js
plugin.watch('name', (value, path) => console.log(value, path));  // Peter users.name
plugin.set('name', 'Peter');
```

### plugin.on(name, callback)

Type: `method`

Počúva globálnu udalosť.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Názov udalosti. |
| `callback` | `Function` | yes |  | Poslucháč. |

Returns: `Plugin` Plugin.

Pri registrácii poslucháča je aktívny scope pluginu.

Example: Použitie on()
```js
plugin.on('saved', value => console.log(value));  // 5
EMIT('saved', 5);
```

### plugin.exec(name, [a], [b], [c], [d], [e])

Type: `method`

Zavolá metódu pluginu.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Názov metódy. |

Returns: `Plugin` Plugin.

Neznáma metóda sa ignoruje. Metóda prijíma najviac päť argumentov.

Example: Použitie exec()
```js
plugin.hello = name => console.log('Hello ' + name);  // Hello Peter
plugin.exec('hello', 'Peter');
```

### plugin.makepath([path])

Type: `method`

Preloží path relatívnu k pluginu.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | no |  | Path. |

Returns: `String` Preložená path.

Tvary sú:

| Argument | Výsledok pre plugin `users` |
| --- | --- |
| vynechaný | `users` |
| `name` alebo `?.name` | `users.name` |
| `*name` | `common.name` |
| `@flag` | `users @flag` |
| `^name` | `^users.name` |
| `+name` | `+users.name` |
| `\|name` | `users\|name` |
| `%name` | `%name` |
| `#name` | `#name` |

Example: Použitie makepath()
```js
console.log(plugin.makepath('name'));  // users.name
```

### plugin.format([text])

Type: `method`

Vloží názov pluginu do textu.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `text` | `String` | no |  | Text. |

Returns: `String` Výsledok.

Názov nahradí `{0}`. Do textu bez zástupného symbolu sa názov pridá na koniec.

Example: Použitie format()
```js
console.log(plugin.format('/api/{0}/'));  // /api/users/
```

### plugin.scope([path])

Type: `method`

Nastaví plugin ako aktívny scope.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | no |  | Scope, ktorý sa má aktivovať. |

Returns: `Plugin` Plugin.

Ostatné funkcie potom prekladajú `?` na tento plugin. Môžeš odovzdať aj inú path a `null` aktívny scope vymaže. Metóda je dostupná aj ako `plugin()`.

Example: Použitie scope()
```js
plugin.scope();
console.log(M.scope());  // users
```

### plugin.ajax(url, [data], [callback])

Type: `method`

Odošle požiadavku.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `url` | `String` | yes |  | Metóda a URL. |
| `data` | `Object` | no |  | Údaje požiadavky. |
| `callback` | `Function|String` | no |  | Funkcia alebo relatívna path. |

Returns: `Plugin|Promise` Plugin, alebo `Promise`, keď nie je zadaný callback.

Metóda volá `AJAX()`. Textový callback je path relatívna k pluginu, ktorá dostane odpoveď. Bez `data` a callbacku metóda vráti `Promise`.

Example: Použitie ajax()
```js
plugin.ajax('GET /api/users/', 'response');
console.log(plugin.get('response.url'));  // GET /api/users/
```

### plugin.api(url, [data], [callback])

Type: `method`

Zavolá koncový bod API.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `url` | `String` | yes |  | Názov koncového bodu. |
| `data` | `Object` | no |  | Údaje požiadavky. |
| `callback` | `Function|String` | no |  | Funkcia alebo relatívna path. |

Returns: `Plugin|Promise` Plugin, alebo `Promise`, keď nie je zadaný callback.

Metóda volá `API()` a prijíma rovnaké tvary callbacku ako [`ajax()`](#ajax).

Example: Použitie api()
```js
plugin.api('users_read', function(response) {
    console.log(response);  // users_read
});
```

### plugin.dapi(name, [data], [callback])

Type: `method`

Zavolá koncový bod DAPI.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Názov koncového bodu. |
| `data` | `Object` | no |  | Údaje požiadavky. |
| `callback` | `Function|String` | no |  | Funkcia alebo relatívna path. |

Returns: `Plugin|Promise` Plugin, alebo `Promise`, keď nie je zadaný callback.

Metóda volá `DAPI()` a prijíma rovnaké tvary callbacku ako [`ajax()`](#ajax).

Example: Použitie dapi()
```js
plugin.dapi('users', function(response) {
    console.log(response);  // users
});
```

### plugin.tapi(name, [data], [callback])

Type: `method`

Zavolá koncový bod TAPI.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Názov koncového bodu. |
| `data` | `Object` | no |  | Údaje požiadavky. |
| `callback` | `Function|String` | no |  | Funkcia alebo relatívna path. |

Returns: `Plugin|Promise` Plugin, alebo `Promise`, keď nie je zadaný callback.

Metóda volá `TAPI()` a prijíma rovnaké tvary callbacku ako [`ajax()`](#ajax).

Example: Použitie tapi()
```js
plugin.tapi('users', function(response) {
    console.log(response);  // users
});
```

### plugin.upload(url, data, [callback])

Type: `method`

Nahrá údaje.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `url` | `String` | yes |  | URL. |
| `data` | `FormData|Object` | yes |  | Dáta. |
| `callback` | `Function|String` | no |  | Funkcia alebo relatívna path. |

Returns: `Plugin|Promise` Plugin, alebo `Promise`, keď nie je zadaný callback.

Metóda volá `UPLOAD()` a prijíma rovnaké tvary callbacku ako [`ajax()`](#ajax).

Example: Použitie upload()
```js
plugin.upload('/upload/', new FormData(), function(response) {
    console.log(response);  // /upload/
});
```

### plugin.remove()

Type: `method`

Odstráni plugin.

Returns: `Boolean` Vždy `true`.

Spustí sa delegate `destroy` a odstránia sa udalosti a sledovače zaregistrované počas deklarácie. Element na stránke zostane.

Example: Použitie remove()
```js
console.log(plugin.remove(), PLUGINS.users === undefined);  // true true
```
