Keyboard shortcuts
Summary
A key-sequence registry replacing AJS.whenIType
(which needed jQuery + jquery.hotkeys). Sequences like
gd mean g then d; modifiers
chain with + (ctrl+b); a space-separated
string binds alternatives. Shortcuts never fire while an input,
textarea, select, or contenteditable has focus, nor while a modal
dialog is open.
Try it here
Press j / k to move through the list, Enter follows the focused link, g then t jumps to the top of the page, and ? shows a message.
JavaScript API
Neura.shortcuts('gd').or('gh').goTo('/dashboard');
Neura.shortcuts('c').click('#create'); // appends "(Type 'c')" to its title
Neura.shortcuts('j').moveToNextItem('.issue'); // roving .focused class
Neura.shortcuts('k').moveToPrevItem('.issue', { wrapAround: false });
Neura.shortcuts('gg').moveToAndClick('#top'); // scroll into view, then click
Neura.shortcuts('/').moveToAndFocus('#search'); // scroll into view, then focus
Neura.shortcuts('r').followLink('#report'); // navigate to the link's href
Neura.shortcuts('ctrl+return').execute((e) => save()); // 'return' = the Enter key
sc.unbind(); // remove a binding
A sequence resets after 1 second without a keypress. Named
keys use AUI's token names: return,
esc, space, tab,
backspace, del, up /
down / left / right,
home / end, pageup /
pagedown, insert, f1–f12.
Shift only matters for those (g also
matches Shift+G).
Each fluent call appends a handler, so one binding can do several
things. moveToNextItem / moveToPrevItem
accept { focusedClass: 'focused', wrapAround: true }
and focus the item (or its first link / button / tabbable child).
click, moveToAndClick,
moveToAndFocus, and followLink append
"(Type 'c')" to the target's title;
unbind() removes the binding and those
title notes. evaluate(fn) is AUI's deprecated
immediate-execution hook: it runs fn right away,
not on a keypress.
AUI compatibility
AJS.whenIType('gh').or('gd').goTo('/secure/Dashboard.jspa');
AJS.whenIType('c').click('#create_link');
AJS.whenIType.fromJSON(descriptorJson); // keyboard-shortcut plugin format