-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
137 lines (110 loc) · 4.19 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
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
<html>
<head>
<link rel="stylesheet" href="traviz.css" type="text/css"/>
<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<script src="traviz-min.js" type="text/javascript"></script>
<script src="papaparse.min.js" type="text/javascript"></script>
<style>
.outerWrapper {border-top: 1px solid black;}
#textWrapper {}
</style>
</head>
<body>
<div id="textWrapper">
<div class="outerWrapper">
<div class="navbar"></div>
<div id="TRAVizContainerDiv" class="relatedItem"><img src="http://thinkfuture.com/wp-content/uploads/2013/10/loading_spinner.gif"/></div>
</div>
</div>
<script>
function getUrlVar() {
var result = {};
var location = window.location.href.split('#');
var parts = location[0].replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
result [key] = value;
});
return result;
}
var blockId = getUrlVar()['id'];
//get manifestations (loop through manifestsions, add promises to array)
const sparqlEndpoint = "https://sparql-docker.scta.info/ds/query"
function displayCollation(blockId, wrapper){
var query = [
"SELECT ?transcription ?block_transcription ?next ?previous ?shortId ",
"WHERE",
"{",
"<" + blockId + "> <http://scta.info/property/hasManifestation> ?block_manifestation .",
"?block_manifestation <http://scta.info/property/hasCanonicalTranscription> ?block_transcription .",
"OPTIONAL {",
"<" + blockId + "> <http://scta.info/property/next> ?next .",
"}",
"OPTIONAL {",
"<" + blockId + "> <http://scta.info/property/previous> ?previous .",
"}",
"<" + blockId + "> <http://scta.info/property/shortId> ?shortId .",
"}"].join('');
$.get(sparqlEndpoint, {query: query}, function(data){
var results = data.results.bindings;
$("#" + wrapper).prev(".navbar").append("Collation for " + blockId);
if (results[0].previous){
$("#" + wrapper).prev(".navbar").append("<a href=?id=" + results[0].previous.value + "> Previous </a> | ");
}
if (results[0].next){
$("#" + wrapper).prev(".navbar").append("<a href=?id=" + results[0].next.value + ">Next </a> ");
}
promiseArray = results.map(function(r){
var textPromise = new Promise(function(resolve, reject){
$.get("https://exist.scta.info/exist/apps/scta-app/csv-pct.xq?resourceid=" + r.block_transcription.value, function(data){
var dataObject = {
"text": data,
"id": r.block_transcription.value
}
resolve(dataObject)
});
});
return textPromise
});
Promise.all(promiseArray).then(function(values){
var traviz = new TRAViz(wrapper);
var data = values.map(function(r){
var object = {
edition: r.id,
text: r.text
}
return object
});
traviz.align(data);
traviz.visualize();
});
});
}
function displayRelated(){
const isRelatedToQuery = [
"SELECT ?isRelatedTo ?shortId ",
"WHERE",
"{",
"<" + blockId + "> <http://scta.info/property/isRelatedTo> ?isRelatedTo .",
"?isRelatedTo <http://scta.info/property/shortId> ?shortId .",
"}"].join('');
$.get(sparqlEndpoint, {query: isRelatedToQuery}, function(data){
const results = data.results.bindings;
results.forEach(function(item){
$("#textWrapper").append("<div class='outerWrapper'><div class='navbar'></div><div id='" + item.shortId.value + "' class='relatedItem'>" + item.isRelatedTo.value + "</div></div>");
});
});
}
$(document).on("click", ".relatedItem", function(e){
console.log(e);
shortId = e.target.id
url = e.target.innerText
console.log(url)
displayCollation(url, shortId)
});
displayCollation(blockId, "TRAVizContainerDiv")
displayRelated()
</script>
</body>
</html>