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