# j-Shortcuts

> Tento komponent môže pomôcť pri vytváraní klávesových skratiek. Komponent je singleton.

Framework: jcomponent20
Product: jComponent 20 (jcomponent@20)
Language: sk
Content-SHA256: f263c05105bf560cc87823784247135142c57c574279a01354f915a5487cb35c
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: components@910ed1a86f6e72b4f031d3ad0dc7844f9fc5cb8e
Review: not-recorded

Táto zložka môže pomôcť pri vytváraní skratiek klávesnice.

__Metódy__:
- `component.register(shortcut, callback(e), [prevent], [preparation(e)])` - zaznamenáva nový krátky
- `component.exec('shortcut')` - hodnotenie krátkych

__krátkych__:
- `enter`
- `esc`
- `tab`
- `cmd`, `meta`, `win`
- `shift`, `capslock`
- `ctrl`
- `alt`
- `space`
- `backspace`, `del`, `delete`
- `left`, `up`, `right`, `down`
- `F1`, `F2`, `F3`, `F4`, `F5`, `F6`, `F7`, `F8`, `F9`, `F10`, `F11`, `F12`
- alebo prispôsobené kľúčové kódy `{Number}` alebo kľučové znaky `{String(1)}`
- `ins`
- `remove` znamená `backspace` alebo `delete`
- `save`
- `selectall`
- `clone`
- `undo`
- `redo`
-  podporuje `.shortcut`, čítajte ďalej

__Príklad__:

```javascript
// SETTER(true, ...) --> works in jComponent +v9.0.0

SETTER(true, 'shortcuts/register', 'cmd + enter', function(e) {
    console.log('PRESSED: CMD + ENTER');
});

SETTER(true, 'shortcuts/register', 'alt + p', function(e) {
    console.log('PRESSED: ALT + P');
});

SETTER(true, 'shortcuts/register', 'esc', function(e) {
    console.log('PRESSED: esc');
});

// +v3 supports multiple shortcuts at the one time:
SETTER(true, 'shortcuts/register', 'cmd+enter, ctrl+enter', function(e) {
    console.log('PRESSED: CMD + ENTER');
});

// NEW: you can make preparation for the shortcut
SETTER(true, 'shortcuts/register', 'cmd+enter, ctrl+enter', function(e) {
    console.log('PRESSED: CMD + ENTER');
}, function(e) {
	// You can enable/disable shortcut manually in the "preparation function"
	// but you need to "return {Boolean}", true will approve shortcut (it calls of the shortcut "callback")
	// otherwise "returning false" the shorcut will be skipped
	return e.target.tagName !== 'INPUT';
});
```

__Nové vložené vyhlásenie__:

```html
<button class="exec shortcut" data-shortcut="F1" data-exec="METHO_TO_CALL">Help</button>
```

- trieda `.shortcut` vydá udalosť `click`
- vlastnosť `e.shortcut` bude obsahovať inštanciu udalosti z udalosti `keydown`

__Nové skratky relácie__:

```javascript
// Open session for new shortcuts
// The methods disables all registered shortcuts while session is not end
SETTER('shortcuts/session', function(register) {
	register('esc', function() {

		// Cancels session
		SETTER('shortcuts/end');

	});
});
```

Použite ho so `<ui-component name="shortcuts">`. Keď komponent ešte nie je načítaný, jComponent ho stiahne pri prvom použití z adresy v `DEF.fallback` (predvolene CDN Componentator). Autor: Peter Širka. Zdroj: úložisko komponentov Componentator, licencia MIT.

```html example.html
<ui-component name="shortcuts"></ui-component>

<div>PRESS ENTER or INSERT</div>

<script>
    var keyvalue = {};
    SETTER(true, 'shortcuts/register', 'ENTER', () => alert('ENTER'));
    SETTER(true, 'shortcuts/register', 'ins', () => alert('INSERT'));
</script>
```
