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
/
bitbucket.js
207 lines (172 loc) · 5.26 KB
/
bitbucket.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
(function() {
function collapseDiff(diff, callback) {
$(diff).find('.bpr-collapse-expand').text('Expand').addClass('bpr-is-collapsed');
$(diff).find('.diff-content-container, .bpr-file-footer').hide(0, callback || $.noop);
}
function expandDiff(diff, callback) {
$(diff).find('.bpr-collapse-expand').text('Collapse').removeClass('bpr-is-collapsed');
$(diff).find('.diff-content-container, .bpr-file-footer').show(0, callback || $.noop);
}
function toggleDiff(diff) {
var button = $(diff).find('.bpr-collapse-expand');
if (button.hasClass('bpr-is-collapsed')) {
expandDiff(diff);
} else {
collapseDiff(diff);
}
}
function collapseAll() {
$('.bb-udiff').each(function(index, element) {
collapseDiff(element);
});
}
function expandAll() {
$('.bb-udiff').each(function(index, element) {
expandDiff(element);
});
}
function collapseAndScrollToNext(diff) {
collapseDiff(diff, function() {
var otherDiffs = $(diff).nextAll('.bb-udiff');
if (otherDiffs.length <= 0) {
return;
}
$('html, body').animate({
scrollTop: otherDiffs.first().offset().top
}, 0);
});
}
function hideComments(diff) {
$(diff).find('.bpr-hide-show-comments').text('Show Comments').addClass('bpr-is-hidden');
$(diff).find('.comment-thread-container').hide();
}
function showComments(diff) {
$(diff).find('.bpr-hide-show-comments').text('Hide Comments').removeClass('bpr-is-hidden');
$(diff).find('.comment-thread-container').show();
}
function toggleComments(diff) {
var button = $(diff).find('.bpr-hide-show-comments');
if (button.hasClass('bpr-is-hidden')) {
showComments(diff);
} else {
hideComments(diff);
}
}
function hideAllComments() {
$('.bb-udiff').each(function(index, element) {
hideComments(element);
});
}
function showAllComments() {
$('.bb-udiff').each(function(index, element) {
showComments(element);
});
}
function addFileHeaderButtons(diff) {
var otherButtons = $(diff).find('.diff-actions .aui-buttons').first();
var collapseButton =
'<div class="aui-buttons">' +
'<a class="aui-button aui-button-light bpr-collapse-expand">Collapse</a>' +
'</div>';
var $collapseButton = $(collapseButton).insertBefore(otherButtons).click(function() {
toggleDiff(diff);
});
var commentButton =
'<div class="aui-buttons">' +
'<a class="aui-button aui-button-light bpr-hide-show-comments">Hide Comments</a>' +
'</div>';
$(commentButton).insertBefore($collapseButton).click(function() {
toggleComments(diff);
});
}
function addFileFooterButton(diff) {
var diffContainer = $(diff).find('.diff-content-container');
var footer =
'<div class="bpr-file-footer">' +
'<span>Collapse</span>' +
'</div>';
$(footer).insertAfter(diffContainer).click(function() {
collapseAndScrollToNext(diff);
});
}
function hasGlobalHeaderButtons() {
return ($('#bpr-global-actions').length > 0);
}
function addGlobalHeaderButtons() {
var globalActions =
'<div id="bpr-global-actions">' +
'<div class="aui-buttons">' +
'<button id="bpr-hide-comments" class="aui-button aui-button">Hide All Comments</button>' +
'<button id="bpr-show-comments" class="aui-button aui-button">Show All Comments</button>' +
'</div>' +
'<div class="aui-buttons">' +
'<button id="bpr-collapse-all" class="aui-button aui-button">Collapse All</button>' +
'<button id="bpr-expand-all" class="aui-button aui-button">Expand All</button>' +
'</div>' +
'</div>';
$(globalActions).insertBefore($('#compare'));
$('#bpr-collapse-all').click(collapseAll);
$('#bpr-expand-all').click(expandAll);
$('#bpr-hide-comments').click(hideAllComments);
$('#bpr-show-comments').click(showAllComments);
}
function shouldOverrideTableOfContentsClick() {
var $summary = $('.commit-files-summary');
if ($summary.length <= 0) {
return false;
}
return !$summary.data('bpr-initialized');
}
function overrideTableOfContentsClick() {
$('.commit-files-summary a[href|="#chg"]').each(function(index, element) {
$(element).off('click.bpr').on('click.bpr', function() {
var fileName = $(this).attr('href').slice(1);
// Try to use jQuery, I dare you. ;)
expandDiff(document.getElementById(fileName));
});
});
$('.commit-files-summary').attr('data-bpr-initialized', true);
}
function setupDiffView(diffView) {
$(diffView).each(function(index, element) {
addFileHeaderButtons(element);
addFileFooterButton(element);
});
}
function setup() {
$('.bb-udiff').each(function(index, element) {
var $element = $(element);
if (!$element.data('bpr-initialized')) {
setupDiffView(element);
$element.attr('data-bpr-initialized', true);
}
});
if (!hasGlobalHeaderButtons()) {
addGlobalHeaderButtons();
}
if (shouldOverrideTableOfContentsClick()) {
overrideTableOfContentsClick();
}
}
runIfValidDomain('bitbucketDomains', 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);
});
});
})();