1
1
mirror of https://github.com/github/semantic.git synced 2024-11-29 02:44:36 +03:00
semantic/prototype/UI/index.html
2015-10-13 10:57:07 -04:00

66 lines
1.8 KiB
HTML

<!doctype html>
<html>
<head>
<title>semantic-diff</title>
<style type="text/css">
#left {
position: absolute;
left: 0; top: 0;
width: 50%;
outline: 1px solid green;
}
#right {
position: absolute;
right: 0; top: 0;
width: 50%;
outline: 1px solid red;
}
</style>
<script type="text/javascript">
function loadJSON(path, callback) {
var request = new XMLHttpRequest();
request.overrideMimeType("application/json");
request.open('GET', '' + path, true);
request.onreadystatechange = function () {
if (request.readyState == 4 && (request.status == "200" || request.status == 0)) {
callback(JSON.parse(request.responseText));
}
};
request.send(null);
}
function toDOM(json) {
var div = document.createElement("div");
if (json instanceof Array) {
console.log("it's an array");
for (index in json) {
div.appendChild(toDOM(json[index]));
}
} else if (json instanceof Object) {
if (json['source'] != null) {
div.textContent = json['source'];
}
if (json['categories'] != null) {
for (index in json['categories']) {
div.classList.add('category-'+json['categories'][index]);
}
}
for (key in json) {
console.log(key);
}
}
return div;
}
</script>
</head>
<body>
<div id="left"></div>
<div id="right"></div>
<script type="text/javascript">
loadJSON('Fixtures/swift.json', function (json) {
document.getElementById("left").appendChild(toDOM(json));
});
</script>
</body>
</html>