2020-04-30 00:09:37 +00:00
|
|
|
/* eslint-disable func-names, consistent-return, one-var, class-methods-use-this */
|
2018-03-09 20:18:59 +00:00
|
|
|
|
|
|
|
import $ from 'jquery';
|
2017-12-07 12:30:53 +00:00
|
|
|
import { visitUrl } from './lib/utils/url_utility';
|
2017-01-13 21:54:16 +00:00
|
|
|
|
2017-06-30 23:18:05 +00:00
|
|
|
export default class TreeView {
|
2017-06-30 21:27:31 +00:00
|
|
|
constructor() {
|
2017-07-05 17:20:41 +00:00
|
|
|
this.initKeyNav();
|
|
|
|
// Code browser tree slider
|
|
|
|
// Make the entire tree-item row clickable, but not if clicking another link (like a commit message)
|
2020-12-23 12:10:26 +00:00
|
|
|
$('.tree-content-holder .tree-item').on('click', function (e) {
|
2019-11-15 12:06:12 +00:00
|
|
|
const $clickedEl = $(e.target);
|
|
|
|
const path = $('.tree-item-file-name a', this).attr('href');
|
2017-07-05 17:20:41 +00:00
|
|
|
if (!$clickedEl.is('a') && !$clickedEl.is('.str-truncated')) {
|
|
|
|
if (e.metaKey || e.which === 2) {
|
|
|
|
e.preventDefault();
|
|
|
|
return window.open(path, '_blank');
|
2016-07-24 20:45:11 +00:00
|
|
|
}
|
2020-04-30 00:09:37 +00:00
|
|
|
return visitUrl(path);
|
2017-07-05 17:20:41 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
// Show the "Loading commit data" for only the first element
|
2020-12-23 12:10:26 +00:00
|
|
|
$('span.log_loading').first().removeClass('hide');
|
2017-07-05 17:20:41 +00:00
|
|
|
}
|
2016-07-24 20:45:11 +00:00
|
|
|
|
2017-06-30 21:27:31 +00:00
|
|
|
initKeyNav() {
|
2019-11-15 12:06:12 +00:00
|
|
|
const li = $('tr.tree-item');
|
|
|
|
let liSelected = null;
|
2020-12-23 21:10:24 +00:00
|
|
|
return $('body').keydown((e) => {
|
2019-11-15 12:06:12 +00:00
|
|
|
let next, path;
|
2018-10-10 07:13:34 +00:00
|
|
|
if ($('input:focus').length > 0 && (e.which === 38 || e.which === 40)) {
|
2017-07-05 17:20:41 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (e.which === 40) {
|
|
|
|
if (liSelected) {
|
|
|
|
next = liSelected.next();
|
|
|
|
if (next.length > 0) {
|
2018-10-10 07:13:34 +00:00
|
|
|
liSelected.removeClass('selected');
|
|
|
|
liSelected = next.addClass('selected');
|
2016-07-24 20:45:11 +00:00
|
|
|
}
|
2017-07-05 17:20:41 +00:00
|
|
|
} else {
|
2018-10-10 07:13:34 +00:00
|
|
|
liSelected = li.eq(0).addClass('selected');
|
2017-07-05 17:20:41 +00:00
|
|
|
}
|
|
|
|
return $(liSelected).focus();
|
|
|
|
} else if (e.which === 38) {
|
|
|
|
if (liSelected) {
|
|
|
|
next = liSelected.prev();
|
|
|
|
if (next.length > 0) {
|
2018-10-10 07:13:34 +00:00
|
|
|
liSelected.removeClass('selected');
|
|
|
|
liSelected = next.addClass('selected');
|
2016-07-24 20:45:11 +00:00
|
|
|
}
|
2017-07-05 17:20:41 +00:00
|
|
|
} else {
|
2018-10-10 07:13:34 +00:00
|
|
|
liSelected = li.last().addClass('selected');
|
2017-07-05 17:20:41 +00:00
|
|
|
}
|
|
|
|
return $(liSelected).focus();
|
|
|
|
} else if (e.which === 13) {
|
|
|
|
path = $('.tree-item.selected .tree-item-file-name a').attr('href');
|
|
|
|
if (path) {
|
2017-12-07 12:30:53 +00:00
|
|
|
return visitUrl(path);
|
2016-07-24 20:45:11 +00:00
|
|
|
}
|
2017-07-05 17:20:41 +00:00
|
|
|
}
|
|
|
|
});
|
2017-06-30 21:27:31 +00:00
|
|
|
}
|
|
|
|
}
|