The App.Helpers.Hotkeys
helpers start and stop loaders for the entire page or specific elements.
This helper is only available outside the script sandbox.
App.Helpers.Hotkeys.bind(keys, options)
This method is also available as App.Hotkey.bind()
for convenience.
The bind
method attaches a function to a hotkey combination, and automatically handles disabling certain combinations when inputs are focused.
The keys
argument is an array of keys, which can be String
or RegExp
objects. Special keys have easier names like "esc", "ctrl", "left", and "del". A full list of named keys is available below. Special characters like "!", and "@" are also supported.
The options
argument accepts an object with the following values:
-
do — The callback function to be run when the combination is pressed.
-
if — An optional function to check conditions before firing the
do
callback. Only one binding can be fired by a key press, so returningfalse
from this method lets other bindings attached to the same combination check their conditions. -
timeout — An optional integer that prevents this binding from firing again for the number of milliseconds passed.
App.Hotkey.bind(["CTRL", "F"], { timeout: 100, if: function(event) { return event.target == document }, do: function(event) { var search = App.menu().search_option(); search.open(); search.focus(); } });
Named Keys
Named keys are case-insensitive, and are listed below:
Escape, Esc
Left, Up, Right, Down
Delete, Del