Reference Source
public class | source

Keys

Handle key combination events.

Static Member Summary

Static Public Members
public static

The time allowed between keypresses for a sequence in miliseconds

  • 1500 by default.

Static Method Summary

Static Public Methods
public static

filterInputs(event: *): Boolean

The default keycombo event filter function.

public static

Convert a key to its character code representation.

Constructor Summary

Public Constructor
public

constructor(elOrSelector: *, options: Object)

Method Summary

Public Methods
public

destroy(globalsOnly: Boolean): Keys

Destroy this instance.

public

init(globalsOnly: Boolean): Keys

Initialize an instance created without the new keyword or revive a destroyed instance.

public

off(keyCombo: String, selector: String, listener: Function): Keys

Remove a key combo listener.

public

on(keyCombo: String, selector: String, data: String, listener: Function): Keys

Add a key combo listener.

public

reset(): Keys

Reset the state of this instance.

Static Public Members

public static sequenceTime: Number source

The time allowed between keypresses for a sequence in miliseconds

  • 1500 by default.

Static Public Methods

public static filterInputs(event: *): Boolean source

The default keycombo event filter function. Ignores key combos triggered on input, select, and textarea.

Params:

NameTypeAttributeDescription
event *

The event passed

Return:

Boolean

True, if event.target is not editable and event.target.tagname is not restricted

public static keyToCode(key: String): Number source

Convert a key to its character code representation.

Params:

NameTypeAttributeDescription
key String

The key character that needs to be converted. If the String contains more than one character, an error will be produced.

Return:

Number

The character code of the given String.

Public Constructors

public constructor(elOrSelector: *, options: Object) source

Params:

NameTypeAttributeDescription
elOrSelector *

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
  • optional

Options for this combo handler.

options.context Function
  • optional

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
  • optional
  • default: false

Whether to prevent the default behavior when a key combo is matched.

options.stopPropagation Function
  • optional
  • default: false

Whether to stop propagation when a key combo is matched.

options.filter Function
  • optional

The filter function for keyboard events. This can be used to stop events from being triggered when they originate from specific elements. Defaults to Keys.filterInputs.

Public Methods

public destroy(globalsOnly: Boolean): Keys source

Destroy this instance. This removes all event listeners, references, and state.

Params:

NameTypeAttributeDescription
globalsOnly Boolean

Whether only global listeners should be removed

Return:

Keys

this, chainable.

public init(globalsOnly: Boolean): Keys source

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.

Params:

NameTypeAttributeDescription
globalsOnly Boolean

Whether only global listeners should be added

Return:

Keys

this, chainable.

public off(keyCombo: String, selector: String, listener: Function): Keys source

Remove a key combo listener.

Params:

NameTypeAttributeDescription
keyCombo String

The key combination to listen for, such as 'ctrl-f'.

selector String
  • optional

A selector to use for event delegation.

listener Function

The listener that was passed to on.

Return:

Keys

this, chainable.

public on(keyCombo: String, selector: String, data: String, listener: Function): Keys source

Add a key combo listener.

Params:

NameTypeAttributeDescription
keyCombo String

The key combination to listen for, such as 'ctrl-f'.

selector String
  • optional

A selector to use for event delegation.

data String
  • optional

Data to pass to listeners as event.data.

listener Function

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.

Return:

Keys

this, chainable.

public reset(): Keys source

Reset the state of this instance. This resets the currently pressed keys.

Return:

Keys

this, chainable.