Skip to content

Commit 9c62e56

Browse files
author
Fabio Picheli
committed
added support for commit view as well
1 parent 9b4a975 commit 9c62e56

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

app/app.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
$(document).ready(start);
22

3+
var isCommit = false;
4+
35
$(window).scroll(() => {
6+
if (isCommit) return;
47
if($('.is-stuck').length) {
58
$('.gct-file-tree').addClass('gct-file-tree-fixed');
69
}else {
@@ -14,21 +17,25 @@ function start() {
1417
if(location.origin + location.pathname != oldLocation) {
1518
oldLocation = location.origin + location.pathname;
1619

17-
urlRegex = /(http|https):\/\/(www\.)?github\.com\/[-a-zA-Z0-9]*\/[-a-zA-Z0-9]*\/pull\/[0-9]*\/(files|commits)/;
18-
if(location.href.match(urlRegex)) { // show only on PR files page
20+
urlPullRegex = /(http|https):\/\/(www\.)?github\.com\/[-a-zA-Z0-9]*\/[-a-zA-Z0-9]*\/pull\/[0-9]*\/(files|commits)/;
21+
urlCommitRegex = /(http|https):\/\/(www\.)?github\.com\/[-a-zA-Z0-9]*\/[-a-zA-Z0-9]*\/commit/;
22+
23+
isCommit = location.href.match(urlCommitRegex);
24+
25+
if(location.href.match(urlPullRegex) || location.href.match(urlCommitRegex)) { // show only on PR files page
1926
initialSetup();
2027
}
2128
}
2229
}, 500);
2330
}
2431

2532
function initialSetup() {
26-
if ($('.js-diff-progressive-spinner').length) {
33+
if ($('.js-diff-progressive-spinner').length || !$('#files').length) {
2734
setTimeout(initialSetup, 100);
2835
return;
2936
}
3037

31-
injectCss(); // style.js
38+
injectCss(isCommit ? 0 : 178, isCommit ? 20 : 0); // style.js
3239
injectHTML();
3340

3441
areDiffBlocksCollapsed() ? $('#collapseAll').hide() : $('#expandAll').hide();

app/style.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function injectCss() {
1+
function injectCss(offsetTop, offsetLeft) {
22
$('#gct-style').remove();
33
$(`<style type='text/css' id="gct-style">
44
#files {
@@ -17,9 +17,9 @@ function injectCss() {
1717
1818
.gct-file-tree {
1919
position: absolute;
20-
top: ${$('#files').offset().top - 178}px;
20+
top: ${$('#files').offset().top - offsetTop}px;
2121
background-color: #fff;
22-
left: 0;
22+
left: ${offsetLeft}px;
2323
z-index: 28;
2424
width: 280px;
2525
border: 1px solid #ddd;

0 commit comments

Comments
 (0)