mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-28 00:10:57 +01:00
Add keyboard shortcuts to Pholio
Summary: Fixes T2657. Adds j/k for previous/next image. This is consistent with Differential. We could add left/right later but it needs a little work to make those available. Test Plan: Mashed j/k, saw images switch. Reviewers: chad Reviewed By: chad CC: aran Maniphest Tasks: T2657 Differential Revision: https://secure.phabricator.com/D5220
This commit is contained in:
parent
5a7d9fb522
commit
2ea4d17f71
2 changed files with 38 additions and 3 deletions
|
@ -1891,7 +1891,7 @@ celerity_register_resource_map(array(
|
|||
),
|
||||
'javelin-behavior-pholio-mock-view' =>
|
||||
array(
|
||||
'uri' => '/res/c2586731/rsrc/js/application/pholio/behavior-pholio-mock-view.js',
|
||||
'uri' => '/res/d993bd2b/rsrc/js/application/pholio/behavior-pholio-mock-view.js',
|
||||
'type' => 'js',
|
||||
'requires' =>
|
||||
array(
|
||||
|
@ -1902,6 +1902,7 @@ celerity_register_resource_map(array(
|
|||
4 => 'javelin-vector',
|
||||
5 => 'javelin-magical-init',
|
||||
6 => 'javelin-request',
|
||||
7 => 'phabricator-keyboard-shortcut',
|
||||
),
|
||||
'disk' => '/rsrc/js/application/pholio/behavior-pholio-mock-view.js',
|
||||
),
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
* javelin-vector
|
||||
* javelin-magical-init
|
||||
* javelin-request
|
||||
* phabricator-keyboard-shortcut
|
||||
*/
|
||||
JX.behavior('pholio-mock-view', function(config) {
|
||||
var is_dragging = false;
|
||||
|
@ -73,15 +74,23 @@ JX.behavior('pholio-mock-view', function(config) {
|
|||
};
|
||||
})();
|
||||
|
||||
function get_image(id) {
|
||||
function get_image_index(id) {
|
||||
for (var ii = 0; ii < config.images.length; ii++) {
|
||||
if (config.images[ii].id == id) {
|
||||
return config.images[ii];
|
||||
return ii;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function get_image(id) {
|
||||
var idx = get_image_index(id);
|
||||
if (idx === null) {
|
||||
return idx;
|
||||
}
|
||||
return config.images[idx];
|
||||
}
|
||||
|
||||
function onload_image(id) {
|
||||
if (active_image.id != id) {
|
||||
// The user has clicked another image before this one loaded, so just
|
||||
|
@ -93,6 +102,16 @@ JX.behavior('pholio-mock-view', function(config) {
|
|||
redraw_image();
|
||||
}
|
||||
|
||||
function switch_image(delta) {
|
||||
if (!active_image) {
|
||||
return;
|
||||
}
|
||||
var idx = get_image_index(active_image.id)
|
||||
JX.log(idx);
|
||||
idx = (idx + delta + config.images.length) % config.images.length;
|
||||
select_image(config.images[idx].id);
|
||||
}
|
||||
|
||||
function redraw_image() {
|
||||
if (!active_image || !active_image.tag) {
|
||||
return;
|
||||
|
@ -553,4 +572,19 @@ JX.behavior('pholio-mock-view', function(config) {
|
|||
JX.Stratcom.listen('resize', null, redraw_image);
|
||||
redraw_image();
|
||||
|
||||
|
||||
/* -( Keyboard Shortcuts )------------------------------------------------ */
|
||||
|
||||
|
||||
new JX.KeyboardShortcut('j', 'Show next image.')
|
||||
.setHandler(function() {
|
||||
switch_image(1);
|
||||
})
|
||||
.register();
|
||||
|
||||
new JX.KeyboardShortcut('k', 'Show previous image.')
|
||||
.setHandler(function() {
|
||||
switch_image(-1);
|
||||
})
|
||||
.register();
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue