-
Notifications
You must be signed in to change notification settings - Fork 5
/
dv.js
144 lines (123 loc) · 3.61 KB
/
dv.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
function DiffViewer() {
this.diff = false;
this.dts = 0;
}
function handleError(xhr, mes, err) {
console.log("[dv.DiffViewer] "+mes+" ("+err+")");
}
/*DiffViewer.prototype.show2 = function(original, modified, diff, elem, mode, line1, line2, ess1, ess2, ess12) {
var self = this;
console.log("[dv.DiffViewer] mode="+mode);
self.mv = CodeMirror.MergeView(elem,{
revertButtons:false,
diffRight:diff,
value:original,
origRight:modified,
mode:mode,
scrollbarStyle:"simple",
foldGutter:true,
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
lineNumbers:true,
lineSeparator:'\n',
line:line2,
lineLeft:line1,
essentials:ess2,
essentialsLeft:ess1,
essentialsMapped:ess12,
showDifferences:self.diff,
showDts:self.dts
});
self.mv.init();
}*/
DiffViewer.prototype.show = function(url0, url1, urld, elem, mode, line1, line2, ess1, ess2, ess12,
blob0, blob1) {
var self = this;
console.log("[dv.DiffViewer] mode="+mode);
console.log("[dv.DiffViewer] loading files...");
console.log("[dv.DiffViewer] url0="+url0);
console.log("[dv.DiffViewer] url1="+url1);
console.log("[dv.DiffViewer] urld="+urld);
if (blob0) {
const original = blob0;
const modified = blob1;
$.ajax({
type:"GET",
mimeType:"application/json",
url:urld,
error:handleError
}).done(function(diff, status2, xhr2) {
console.log("[dv.DiffViewer] diff file loaded.");
self.mv = CodeMirror.MergeView(elem,{
revertButtons:false,
diffRight:diff,
value:original,
origRight:modified,
mode:mode,
scrollbarStyle:"simple",
foldGutter:true,
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
lineNumbers:true,
lineSeparator:'\n',
line:line1,
lineRight:line2,
essentials:ess2,
essentialsLeft:ess1,
essentialsMapped:ess12,
showDifferences:self.diff,
showDts:self.dts
});
self.mv.init();
})
} else {
$.ajax({
type:"GET",
mimeType:"text/plain",
url:url0,
error:handleError
}).done(function(original, status0, xhr0) {
console.log("[dv.DiffViewer] original source file loaded.");
$.ajax({
type:"GET",
mimeType:"text/plain",
url:url1,
error:handleError
}).done(function(modified, status1, xhr1) {
console.log("[dv.DiffViewer] modified source file loaded.");
$.ajax({
type:"GET",
mimeType:"application/json",
url:urld,
error:handleError
}).done(function(diff, status2, xhr2) {
console.log("[dv.DiffViewer] diff file loaded.");
self.mv = CodeMirror.MergeView(elem,{
revertButtons:false,
diffRight:diff,
value:original,
origRight:modified,
mode:mode,
scrollbarStyle:"simple",
foldGutter:true,
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
lineNumbers:true,
lineSeparator:'\n',
line:line1,
lineRight:line2,
essentials:ess2,
essentialsLeft:ess1,
essentialsMapped:ess12,
showDifferences:self.diff,
showDts:self.dts
});
self.mv.init();
})
})
})
}
}
DiffViewer.prototype.toggleDifferences = function() {
this.mv.setShowDifferences(this.diff = !this.diff);
}
DiffViewer.prototype.toggleDts = function() {
this.mv.setShowDts(this.dts = this.dts > 0 ? 0 : 1);
}