This repository has been archived by the owner on May 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
gitlab.js
100 lines (83 loc) · 2.36 KB
/
gitlab.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
(function() {
runIfValidDomain('gitlabDomains', function() {
$(function() {
// All the timeouts!
var setupTimer = null;
var debouncedSetup = function() {
if (setupTimer) {
clearTimeout(setupTimer);
}
setupTimer = setTimeout(function() {
setupTimer = null;
setup();
}, 500);
};
setTimeout(function() {
debouncedSetup();
setTimeout(function() {
$(document).livequery('*', debouncedSetup);
}, 1000);
}, 500);
});
});
function setup() {
if ($('.gpr-global-button-group').length === 0) {
addHeaderButtons();
}
addFooterButtons();
}
function addHeaderButtons() {
var newButtons =
'<div class="btn-group gpr-global-button-group">' +
'<a id="gpr-hide-all-comments" class="btn btn-default">Hide All Comments</a>' +
'<a id="gpr-show-all-comments" class="btn btn-default">Show All Comments</a>' +
'<a id="gpr-collapse-all" class="btn btn-default">Collapse All</a>' +
'<a id="gpr-expand-all" class="btn btn-default">Expand All</a>' +
'</div>';
$(newButtons).insertAfter($('.files-changed').first());
$('#gpr-hide-all-comments').click(hideAllComments);
$('#gpr-show-all-comments').click(showAllComments);
$('#gpr-collapse-all').click(collapseAll);
$('#gpr-expand-all').click(expandAll);
}
function hideAllComments() {
$('.js-toggle-diff-comments.active').toArray().forEach(function(element) {
element.click();
});
}
function showAllComments() {
$('.js-toggle-diff-comments:not(.active)').toArray().forEach(function(element) {
element.click();
});
}
function collapseAll() {
$('.diff-toggle-caret.fa-caret-down').toArray().forEach(function(element) {
element.click();
});
}
function expandAll() {
$('.diff-toggle-caret.fa-caret-right').toArray().forEach(function(element) {
element.click();
});
}
function addFooterButtons() {
$('.diff-file').toArray().forEach(function(diff) {
addFooterButton($(diff));
});
}
function addFooterButton($diff) {
if ($diff.find('.gpr-footer-collapse-row').length > 0) {
return;
}
var html =
'<tr class="gpr-footer-collapse-row">' +
'<td colspan="3">' +
'<button>Collapse</button>' +
'</td>' +
'</tr>';
var dom = $(html).insertAfter($diff.find('table.code tr:last-of-type'));
dom.find('button').click(function() {
$diff.find('.diff-toggle-caret.fa-caret-down')[0].click();
});
}
})();