-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathindex.html
72 lines (65 loc) · 1.31 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Diff JS objects</title>
<link rel="stylesheet" href="objectDiff.css"/>
<link rel="stylesheet" href="style.css"/>
</head>
<body>
<table>
<tr>
<td><textarea id="a" spellcheck="false">{
a: {
b: 1
},
"2b": {
foo: 'bar'
}
}</textarea></td>
<td><textarea id="b" spellcheck="false">{
a: {
b: 2
},
x: 1
}</textarea></td>
<td><pre id="result"></pre></td>
</tr>
</table>
<a class="footer" href="https://github.com/NV/objectDiff.js">objectDiff.js on GitHub</a>
<script src="objectDiff.js"></script>
<script defer>
var a = document.getElementById('a');
var b = document.getElementById('b');
var result = document.getElementById('result');
window.onload =
a.onpaste = a.onchange = a.oninput =
b.onpaste = b.onchange = b.oninput = function changed(e) {
var aError;
try {
var aObj = eval('(' + a.value + ')');
} catch (e) {
aError = true;
a.className = 'error';
}
if (!aError) {
a.className = '';
}
var bError;
try {
var bObj = eval('(' + b.value + ')');
} catch (e) {
bError = true;
b.className = 'error';
}
if (!bError) {
b.className = '';
}
if (!bError && !aError) {
var diff = objectDiff.diffOwnProperties(aObj, bObj);
result.innerHTML = objectDiff.convertToXMLString(diff);
}
};
</script>
</body>
</html>