Coral.Keys provides key combination functionality Coral components.

Coral.Keys API

Constructor

Handle key combination events.

JavaScript:

new Coral.Keys()
Parameters:
Name Type Optional Description
elOrSelector * No
The selector or element to listen for keyboard events on. This should be the common parent of all elements you wish to listen for events on.
options Object Yes

Options for this combo handler.

Name Type Optional Default Description
options.context function Yes
The desired value of the this keyword context when executing listeners. Defaults to the element on which the event is listened for.
options.preventDefault function Yes
Whether to prevent the default behavior when a key combo is matched.
options.stopPropagation function Yes
Whether to stop propagation when a key combo is matched.
options.filter function Yes
Coral.Keys.filterInputs The filter function for keyboard events. This can be used to stop events from being triggered when they originate from specific elements.

Static Properties

Coral.Keys.sequenceTime {Number}

The time allowed between keypresses for a sequence in miliseconds
Default Value:
  • 1500

Methods

Coral.Keys.filterInputs

The default keycombo event filter function. Ignores key combos triggered on input, select, and textarea.
Parameters:
Name Type Description
event The event passed
Returns:
True, if event.target is not editable and event.target.tagname is not restricted {Boolean}

Coral.Keys.keyToCode

Convert a key to its character code representation.
Parameters:
Name Type Description
key String The key character that needs to be converted. If the String contains more than one character, an error will be produced.
Returns:
The character code of the given String. {Number}

instance.destroy

Destroy this instance. This removes all event listeners, references, and state.
Parameters:
Name Type Description
globalsOnly Boolean Whether only global listeners should be removed
Returns:
this, chainable. {Coral.Keys}

instance.init

Initialize an instance created without the new keyword or revive a destroyed instance. This method will be called automatically if an instance is created with new Coral.keys, but otherwise will not be called.
Parameters:
Name Type Description
globalsOnly Boolean Whether only global listeners should be added
Returns:
this, chainable. {Coral.Keys}

instance.off

Remove a key combo listener.
Parameters:
Name Type Optional Description
keyCombo String No
The key combination to listen for, such as 'ctrl-f'.
selector String Yes
A selector to use for event delegation.
listener function No
The listener that was passed to on.
Returns:
this, chainable. {Coral.Keys}

instance.on

Add a key combo listener.
Parameters:
Name Type Optional Description
keyCombo String No
The key combination to listen for, such as 'ctrl-f'.
selector String Yes
A selector to use for event delegation.
data String Yes
Data to pass to listeners as event.data.
listener function No
The listener to execute when this key combination is pressed. Executes on keydown, or, if too many keys are pressed and one is released, resulting in the correct key combination, executes on keyup.
Returns:
this, chainable. {Coral.Keys}

instance.reset

Reset the state of this instance. This resets the currently pressed keys.
Returns:
this, chainable. {Coral.Keys}