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
|
var unified = true;
function make_unified(chunk) {
var pending_added = [];
function flush_adds(before) {
for (var i = 0; i < pending_added.length; i++) {
before.ancestor().insertBefore(pending_added[i], before);
}
pending_added.length = 0;
}
chunk.get('children').filter(".pseudorow").each(
function (line) {
if (line.hasClass("context-row")) {
flush_adds(line);
line.removeChild(line.query('.code'));
}
else if (line.hasClass("both-row")) {
var added_line = line.create('<div class="pseudorow insert-row"><div class="lineNumber first"> </div><div class="clear"> </div></div>');
var clear = added_line.query('.clear');
added_line.insertBefore(line.query('.lineNumber.second'), clear);
added_line.insertBefore(line.query('.code.insert'), clear);
pending_added[pending_added.length] = added_line;
line.insertBefore(line.create('<div class="lineNumber second"> </div>'), line.query('.code.delete'));
line.replaceClass("both-row", "delete-row");
}
else if (line.hasClass("insert-row")) {
flush_adds(line);
line.removeChild(line.query('.blank'));
}
else if (line.hasClass("delete-row")) {
line.removeChild(line.query('.blank'));
line.insertBefore(line.query('.lineNumber.second'), line.query('.code.delete'));
}
});
flush_adds(null);
chunk.replaceClass('sbs', 'unified');
}
function make_sbs(chunk) {
var added = [];
var removed = [];
function clear_bufs(before) {
if (!added.length && !removed.length) return;
var common = Math.min(added.length, removed.length);
for (var i = 0; i < common; i++) {
var a = added[i];
var r = removed[i];
a.ancestor().removeChild(a);
r.removeChild(r.query('.lineNumber.second'));
r.insertBefore(a.query('.lineNumber.second'), r.query('.clear'));
r.insertBefore(a.query('.code.insert'), r.query('.clear'));
r.replaceClass('removed-row', 'both-row');
}
if (added.length > removed.length) {
for (var j = common; j < added.length; j++) {
a = added[j];
a.insertBefore(a.create('<div class="blank"> </div>'), a.query('.lineNumber.second'));
}
}
else if (added.length < removed.length) {
for (var j = common; j < removed.length; j++) {
r = removed[j];
r.insertBefore(r.query('.code.delete'), r.query('.lineNumber.second'));
r.insertBefore(r.create('<div class="blank"> </div>'), r.query('.clear'));
}
}
added.length = 0;
removed.length = 0;
}
chunk.get('children').filter(".pseudorow").each(
function (line) {
if (line.hasClass("context-row")) {
clear_bufs(line);
line.insertBefore(line.query('.code').cloneNode(true), line.query(".second"));
}
else if (line.hasClass("insert-row")) {
added[added.length] = line;
}
else if (line.hasClass("delete-row")) {
removed[removed.length] = line;
}
});
clear_bufs(null);
chunk.replaceClass('unified', 'sbs');
}
function toggle_unified_sbs(event) {
event.preventDefault();
var pts = Y.all(".pseudotable");
if (unified) {
pts && pts.each(make_sbs);
unified = false;
Y.get("#toggle_unified_sbs").set('innerHTML', "Show unified diffs");
}
else {
pts && pts.each(make_unified);
unified = true;
Y.get("#toggle_unified_sbs").set('innerHTML', "Show diffs side-by-side");
}
}
Y.on("click", toggle_unified_sbs, '#toggle_unified_sbs');
function toggle_expand_all_revisionview(action)
{
var diffs = Y.all('.diff');
if (diffs == null) return;
diffs.each(
function(item, i)
{
var collapsable = item.collapsable;
if(action == 'close')
{
Y.get('#expand_all').setStyle('display','block');
Y.get('#collapse_all').setStyle('display','none');
collapsable.close();
}
else if(action == 'open')
{
Y.get('#expand_all').setStyle('display','none');
Y.get('#collapse_all').setStyle('display','block');
collapsable.open();
}
});
}
Y.on(
'click',
function (event) {
event.preventDefault();
toggle_expand_all_revisionview('open');
},
'#expand_all a'
);
Y.on(
'click',
function (event) {
event.preventDefault();
toggle_expand_all_revisionview('close');
},
'#collapse_all a'
);
function node_process(node) {
if (!unified) {
node.get('children').filter('.pseudotable').each(make_sbs);
}
}
function zoom_to_diff (path) {
var collapsable = Y.get('#' + path_to_id[path]).collapsable;
if (!collapsable.is_open) {
collapsable.open(
function () {
window.location.hash = '#' + path;
});
}
}
Y.on(
"domready", function () {
Y.all(".show_if_js").removeClass("show_if_js");
if (!specific_path) {
Y.all("#list-files a").on(
'click',
function (e) {
e.preventDefault();
var path = decodeURIComponent(e.target.get('href').split('#')[1]);
window.location.hash = '#' + path;
zoom_to_diff(path);
});
}
var diffs = Y.all('.diff');
if (diffs == null) return;
diffs.each(
function(item, i)
{
var source_url = null;
if (!specific_path)
source_url = global_path + '+filediff/' + link_data[item.get('id')];
item.query('.the-link').on(
'click',
function(e) {
e.preventDefault();
collapsable.toggle();
});
var collapsable = new Collapsable(
{
expand_icon: item.query('.expand_diff'),
open_node: item.query('.diffinfo'),
close_node: null,
source: source_url,
is_open: specific_path != null,
loading: item.query('.loading'),
node_process: node_process
});
item.collapsable=collapsable;
});
if (window.location.hash && !specific_path) {
zoom_to_diff(window.location.hash.substring(1));
}
});
|