forked from cemerick/jsdifflib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.html
executable file
·140 lines (124 loc) · 3.99 KB
/
demo.html
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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
<title>Soft Align Demo</title>
<link rel="stylesheet" type="text/css" href="diffview.css"/>
<script type="text/javascript" src="diffview.js"></script>
<script type="text/javascript" src="difflib.js"></script>
<style type="text/css">
body {
font-size: 12px;
font-family: Sans-Serif;
}
h2 {
margin: 0.5em 0 0.1em;
text-align: center;
}
.top {
text-align: center;
}
.textInput {
display: block;
width: 49%;
float: left;
}
textarea {
width:100%;
height:300px;
}
label:hover {
text-decoration: underline;
cursor: pointer;
}
.spacer {
margin-left: 10px;
}
.viewType {
font-size: 16px;
clear: both;
text-align: center;
padding: 1em;
}
#diffoutput {
width: 100%;
}
</style>
<script type="text/javascript">
function sanitise(str) {
return (str.replace(/ /g, "\n").replace(/\./g, "").replace(/,/g, "").replace(/’/g, "'").replace(/“/g, "").replace(/’/g, "”").toLowerCase());
}
function diffUsingJS(viewType) {
"use strict";
var byId = function (id) { return document.getElementById(id); },
base = difflib.stringAsLines(sanitise(byId("baseText").value)),
newtxt = difflib.stringAsLines(sanitise(byId("newText").value)),
sm = new difflib.SequenceMatcher(base, newtxt),
opcodes = sm.get_opcodes(),
diffoutputdiv = byId("diffoutput"),
contextSize = byId("contextSize").value;
//console.dir(sm);
diffoutputdiv.innerHTML = "";
contextSize = contextSize || null;
diffoutputdiv.appendChild(diffview.buildView({
baseTextLines: base,
newTextLines: newtxt,
opcodes: opcodes,
baseTextName: "Base Text",
newTextName: "New Text",
contextSize: contextSize,
viewType: viewType
}).debug);
}
function passData() {
var byId = function (id) { return document.getElementById(id); },
base = difflib.stringAsLines(sanitise(byId("baseText").value)),
newtxt = difflib.stringAsLines(sanitise(byId("newText").value)),
sm = new difflib.SequenceMatcher(base, newtxt),
opcodes = sm.get_opcodes(),
diffoutputdiv = byId("diffoutput"),
contextSize = byId("contextSize").value;
//console.dir(sm);
diffoutputdiv.innerHTML = "";
contextSize = contextSize || null;
document.getElementById('diffoutput').appendChild(diffview.buildView({
baseTextLines: base,
newTextLines: newtxt,
opcodes: opcodes,
baseTextName: "Base Text",
newTextName: "New Text",
contextSize: contextSize,
viewType: 0,
pass: true,
baseObject : [{text: "I", start: 10000, end: 10500},{text: "am", start: 11000, end: 11500},{text: "a", start: 12000, end: 12500},{text: "mole", start: 13000, end: 13500},{text: "and", start: 14000, end: 14500},{text: "I", start: 15000, end: 15500},{text: "live", start: 16000, end: 16500}, {text: "in", start: 17000, end: 17500}, {text: "a", start: 18000, end: 18500}, {text: "hole", start: 19000, end: 19500}],
newText: "Hey, I am a fat mole and I like to live in a hole!",
boundaryStart: 9000,
boundaryEnd: 20000
}).debug);
return false;
}
</script>
</head>
<body>
<div class="top">
<strong>Context size (optional):</strong> <input type="text" id="contextSize" value="" />
</div>
<div class="textInput">
<h2>Base Text</h2>
<textarea id="baseText"></textarea>
</div>
<div class="textInput spacer">
<h2>New Text</h2>
<textarea id="newText"></textarea>
</div>
<div class="viewType">
<input type="radio" name="_viewtype" id="sidebyside" onclick="diffUsingJS(0);" /> <label for="sidebyside">Side by Side Diff</label>
<input type="radio" name="_viewtype" id="inline" onclick="diffUsingJS(1);" /> <label for="inline">Inline Diff</label>
</div>
<div>Matched : <span id="matched"></span></div><div style="background-color: #9E9">Inserted : <span id="inserted"></span></div><div style="background-color: #FD8">Replaced : <span id="replaced"></span></div><div style="background-color: #E99">Deleted : <span id="deleted"></span></div>
<div id="diffoutput"> </div>
<button id="pass-data" onclick="passData()">Pass data</button>
</body>
</html>