mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-13 02:12:41 +01:00
49 lines
993 B
JavaScript
49 lines
993 B
JavaScript
|
/**
|
||
|
* @provides javelin-behavior-differential-keyboard-navigation
|
||
|
* @requires javelin-behavior
|
||
|
* javelin-dom
|
||
|
* phabricator-keyboard-shortcut
|
||
|
*/
|
||
|
|
||
|
JX.behavior('differential-keyboard-navigation', function(config) {
|
||
|
|
||
|
var cursor = null;
|
||
|
var changesets;
|
||
|
|
||
|
function init() {
|
||
|
if (changesets) {
|
||
|
return;
|
||
|
}
|
||
|
changesets = JX.DOM.scry(document.body, 'div', 'differential-changeset');
|
||
|
}
|
||
|
|
||
|
function jump(manager, delta) {
|
||
|
init();
|
||
|
|
||
|
if (cursor === null) {
|
||
|
cursor = -1;
|
||
|
}
|
||
|
|
||
|
cursor = (cursor + changesets.length + delta) % changesets.length;
|
||
|
|
||
|
var selected = changesets[cursor];
|
||
|
|
||
|
manager.scrollTo(selected);
|
||
|
manager.focusOn(selected);
|
||
|
}
|
||
|
|
||
|
new JX.KeyboardShortcut('j', 'Jump to next change.')
|
||
|
.setHandler(function(manager) {
|
||
|
jump(manager, 1);
|
||
|
})
|
||
|
.register();
|
||
|
|
||
|
new JX.KeyboardShortcut('k', 'Jump to previous change.')
|
||
|
.setHandler(function(manager) {
|
||
|
jump(manager, -1);
|
||
|
})
|
||
|
.register();
|
||
|
|
||
|
});
|
||
|
|