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

# Macro

> Delegate, vlastnosti a metódy inštancie macro.

Inštancia macro je objekt odovzdaný deklarácii `MACRO()`. Pridáva elementu správanie pomocou príkazu [`macro`](../ui-bind/#macro) elementu `<ui-bind>`. Koncept vysvetľuje časť [Macro](../../guides/macros/). V príkladoch je `macro` inštancia pripojená k `<ui-bind>` naviazanému na `form.name`.

## API

### self.make = function()

Type: `delegate`

Spustí sa raz po deklarácii.

Example: Príprava elementu
```html
<ui-bind path="form.name" config="macro:card"></ui-bind>

<script>
    MACRO('card', function(self, element, cls) {
        self.make = function() {
            element.aclass(cls);
        };
    });
</script>
```

### self.setter = function(value, path, type)

Type: `delegate`

Dostáva hodnotu na path.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `Object` | yes |  | Hodnota na path. |
| `path` | `String` | yes |  | Path, ktorý sa zmenil. |
| `type` | `Number` | yes |  | Typ zmeny. |

Delegate sa spustí pri každej aktualizácii binderu.

Example: Vykreslenie hodnoty
```html
<ui-bind path="form.name" config="macro:card"></ui-bind>

<script>
    MACRO('card', function(self) {
        self.setter = function(value) {
            self.text(value);
        };
    });
    SET('form.name', 'Peter');
</script>
```

### self.service = function(counter)

Type: `delegate`

Spúšťa sa raz za minútu.

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

Delegate dostáva počítadlo, ktoré sa pri každom spustení zvýši o jednotku.

### self.destroy = function()

Type: `delegate`

Spustí sa, keď sa odstráni element binderu.

Example: Uvoľnenie zdrojov
```html
<ui-bind path="form.name" config="macro:card"></ui-bind>

<script>
    MACRO('card', function(self) {
        self.destroy = () => console.log('destroyed');  // destroyed
    });
    setTimeout(function() {
        $('ui-bind').remove();
        FREE();
    }, 500);
</script>
```

### self.name

Type: `property`

Názov macra.

Example: Čítanie name
```js
console.log(macro.name);  // demo
```

### self.path

Type: `property`

Path binderu.

Example: Čítanie path
```js
console.log(macro.path);  // form.name
```

### self.element

Type: `property`

Element binderu ako objekt jQuery.

Example: Čítanie element
```js
console.log(macro.element.attr('id'));  // box
```

### self.dom

Type: `property`

Element binderu ako uzol DOM.

Example: Čítanie dom
```js
console.log(macro.dom.id);  // box
```

### self.binder

Type: `property`

Binder, ktorý vytvoril macro.

Pozri metódy [`refresh()`](../ui-bind/#refresh) a [`exec()`](../ui-bind/#exec).

Example: Čítanie binder
```js
console.log(macro.binder.path);  // form.name
```

### self.scope

Type: `property`

[Scope](../scope/) binderu.

Vlastnosť sa priradí po delegate `make` a existuje, keď path obsahuje `?`.

Example: Čítanie scope
```js
console.log(macro.scope.path);  // users
```

### self.get()

Type: `method`

Prečíta hodnotu na path.

Returns: `Object` Hodnota.

Example: Použitie get()
```js
SET('form.name', 'Peter');
console.log(macro.get());  // Peter
```

### self.set(value)

Type: `method`

Zapíše hodnotu na path.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `Object` | yes |  | Nová hodnota. |

Example: Použitie set()
```js
macro.set('Peter');
console.log(GET('form.name'));  // Peter
```

### self.refresh()

Type: `method`

Znova spustí binder s aktuálnou hodnotou.

Returns: `Macro` Macro.

Example: Použitie refresh()
```js
macro.setter = value => console.log(value);  // Peter
window.form.name = 'Peter';
macro.refresh();
```

### self.EXEC(path, [a], [b], [c], [d])

Type: `method`

Zavolá funkciu podľa jej path.

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

Returns: `Macro` Macro.

Znak `?` sa nahradí za path scopu. Predpona `@` zavolá metódu nadradeného komponentu.

Example: Použitie EXEC()
```js
macro.EXEC('@ping', 5);
```

### self.SEEX(path, [a], [b], [c], [d])

Type: `method`

Zavolá funkciu alebo zapíše hodnotu.

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

Returns: `Macro` Macro.

Keď na path nie je žiadna funkcia, zapíše sa na ňu prvý argument.

Example: Použitie SEEX()
```js
macro.SEEX('@title', 'Orders');
console.log(FIND('owner').title);  // Orders
```

### self.find(selector)

Type: `method`

Nájde vnorené elementy.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `selector` | `String|Object` | yes |  | Selektor alebo objekt selektorov. |

Returns: `jQuery|Object` Výsledok.

Objekt selektorov vráti objekt výsledkov jQuery s rovnakými kľúčmi.

Example: Použitie find()
```js
console.log(macro.find('.label').text());  // Text
```

### self.closest(selector)

Type: `method`

Nájde najbližší zodpovedajúci nadradený element.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `selector` | `String` | yes |  | Selektor. |

Returns: `jQuery` Výsledok.

Example: Použitie closest()
```js
console.log(macro.closest('body').length);  // 1
```

### self.parent([selector])

Type: `method`

Vráti nadradený element.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `selector` | `String` | no |  | Selektor. |

Returns: `jQuery` Výsledok.

Argument prijíma rovnaké hodnoty ako [`parent()`](../component/#parent) komponentu.

Example: Použitie parent()
```js
console.log(macro.parent().prop('tagName'));  // BODY
```

### self.html([value])

Type: `method`

Prečíta alebo nahradí obsah HTML.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `String|Array` | no |  | Nový obsah. |

Returns: `String|jQuery` Obsah, alebo element, keď odovzdáš `value`.

Pole sa spojí.

Example: Použitie html()
```js
macro.html('<i>A</i>');
console.log(macro.html());  // <i>A</i>
```

### self.text([value])

Type: `method`

Prečíta alebo nahradí textový obsah.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `String|Array` | no |  | Nový obsah. |

Returns: `String|jQuery` Obsah, alebo element, keď odovzdáš `value`.

Pole sa spojí.

Example: Použitie text()
```js
macro.text('A');
console.log(macro.text());  // A
```

### self.append(value)

Type: `method`

Pridá obsah na koniec elementu.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `String|Array` | yes |  | Obsah. |

Returns: `jQuery` Element.

Pole sa spojí.

Example: Použitie append()
```js
macro.append('<i>A</i>');
console.log(macro.find('i').length);  // 1
```

### self.empty()

Type: `method`

Odstráni obsah elementu.

Returns: `jQuery` Element.

Example: Použitie empty()
```js
macro.empty();
console.log(macro.html() === '');  // true
```

### self.event(name, [selector], callback)

Type: `method`

Pripojí k elementu udalosť jQuery.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Názov udalosti. |
| `selector` | `String` | no |  | Delegovaný selektor. |
| `callback` | `Function` | yes |  | Obslužná funkcia. |

Returns: `Macro` Macro.

Argumenty sú rovnaké ako pri metóde jQuery `on()`.

Example: Použitie event()
```js
macro.event('click', '.label', () => console.log('clicked'));  // clicked
macro.find('.label').click();
```

### self.aclass(classes, [timeout])

Type: `method`

Pridá triedy CSS.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `classes` | `String` | yes |  | Triedy. |
| `timeout` | `Number` | no |  | Oneskorenie v milisekundách. |

Returns: `Macro` Macro.

Example: Použitie aclass()
```js
macro.aclass('active');
console.log(macro.hclass('active'));  // true
```

### self.rclass([classes], [timeout])

Type: `method`

Odstráni triedy CSS.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `classes` | `String` | no |  | Triedy. |
| `timeout` | `Number` | no |  | Oneskorenie v milisekundách. |

Returns: `Macro` Macro.

Bez argumentu sa odstránia všetky triedy.

Example: Použitie rclass()
```js
macro.aclass('active');
macro.rclass('active');
console.log(macro.hclass('active'));  // false
```

### self.rclass2(search)

Type: `method`

Odstráni triedy CSS, ktoré obsahujú zadaný text.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `search` | `String|RegExp` | yes |  | Text alebo regulárny výraz. |

Returns: `Macro` Macro.

Example: Použitie rclass2()
```js
macro.aclass('col-1 col-2');
macro.rclass2('col-');
console.log(macro.hclass('col-2'));  // false
```

### self.tclass(classes, [state])

Type: `method`

Prepne triedy CSS.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `classes` | `String` | yes |  | Triedy. |
| `state` | `Boolean` | no |  | Vynúti stav. |

Returns: `Macro` Macro.

Example: Použitie tclass()
```js
macro.tclass('active', true);
console.log(macro.hclass('active'));  // true
```

### self.hclass(name)

Type: `method`

Zistí, či má element triedu CSS.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Trieda. |

Returns: `Boolean` Výsledok.

Example: Použitie hclass()
```js
console.log(macro.hclass('missing'));  // false
```

### self.attr(name, [value])

Type: `method`

Prečíta alebo zapíše atribút.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Atribút. |
| `value` | `String` | no |  | Nová hodnota. |

Returns: `String|Macro` Hodnota, alebo macro, keď odovzdáš `value`.

Example: Použitie attr()
```js
macro.attr('title', 'Orders');
console.log(macro.attr('title'));  // Orders
```

### self.attrd(name, [value])

Type: `method`

Prečíta alebo zapíše atribút `data-`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Názov bez prefixu `data-`. |
| `value` | `String` | no |  | Nová hodnota. |

Returns: `String|Macro` Hodnota, alebo macro, keď odovzdáš `value`.

Example: Použitie attrd()
```js
macro.attrd('id', '5');
console.log(macro.attr('data-id'));  // 5
```

### self.attrd2(name)

Type: `method`

Prečíta atribút `data-` z elementu alebo z jeho najbližšieho nadradeného elementu, ktorý ho má.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Názov bez prefixu `data-`. |

Returns: `String` Hodnota.

Example: Použitie attrd2()
```js
console.log(macro.attrd2('area'));  // main
```

### self.css(name, [value])

Type: `method`

Prečíta alebo zapíše vlastnosť CSS.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Vlastnosť. |
| `value` | `String` | no |  | Nová hodnota. |

Returns: `String|Macro` Hodnota, alebo macro, keď odovzdáš `value`.

Example: Použitie css()
```js
macro.css('display', 'block');
console.log(macro.css('display'));  // block
```

### self.visible([callback])

Type: `method`

Určuje, či je element viditeľný.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `callback` | `Function` | no |  | Spustí sa, keď je element viditeľný. |

Returns: `Boolean` Aktuálna viditeľnosť.

S callbackom sa funkcia spustí, hneď ako je element viditeľný.

Example: Použitie visible()
```js
console.log(macro.visible());  // true
```

### self.width([callback])

Type: `method`

Vráti šírku elementu v pixeloch.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `callback` | `Function` | no |  | Dostane šírku. |

Returns: `Number` Šírka.

S callbackom sa funkcia spustí, hneď ako je šírka väčšia ako nula.

Example: Použitie width()
```js
macro.css('display', 'block');
macro.css('width', '200px');
console.log(macro.width());  // 200
```

### self.height([callback])

Type: `method`

Vráti výšku elementu v pixeloch.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `callback` | `Function` | no |  | Dostane výšku. |

Returns: `Number` Výška.

S callbackom sa funkcia spustí, hneď ako je výška väčšia ako nula.

Example: Použitie height()
```js
macro.css('display', 'block');
macro.css('height', '50px');
console.log(macro.height());  // 50
```

### self.autofocus([selector])

Type: `method`

Presunie fokus na prvé viditeľné pole.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `selector` | `String` | no | `input,select,textarea` | Polia. |

Returns: `Macro` Macro.

Na mobilných zariadeniach metóda nerobí nič.

Example: Použitie autofocus()
```js
macro.autofocus();
console.log(document.activeElement.tagName);  // INPUT
```

### self.faicon(value)

Type: `method`

Doplní názov ikony.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `String` | yes |  | Názov ikony. |

Returns: `String` Triedy CSS.

Názov bez medzery dostane `DEF.iconprefix`, čo je `ti ti-`.

Example: Použitie faicon()
```js
console.log(macro.faicon('home'));  // ti ti-home
```
