-
Notifications
You must be signed in to change notification settings - Fork 2
/
collatexView.html
647 lines (563 loc) · 24.7 KB
/
collatexView.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
<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="papaparse.min.js" type="text/javascript"></script>
<style>
body,html{
margin: 0;
padding: 0;
}
.outerWrapper {
border-top: 1px solid black;
}
#textWrapper {
padding-bottom: 300px;
}
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
td {
padding: 5px
}
.navbar{background-color: white;;}
.variant {
border-color: red;
color: red
}
.invariant {
border-color: black;
color: black;
}
.chosen {
color: green
}
.unchosen{
}
.reason{
cursor: pointer;
}
.reason:hover{
text-decoration: underline;
}
.hidden{
display: none;
}
.lbp-link{
color:inherit;
text-decoration: none;
}
.lbp-link:hover{
text-decoration: underline;
}
#imageViewer{
height: 200px;
position: fixed;
bottom:0%;
width:100%;
background-color: #ffffff;
opacity: 1;
display: none;
box-shadow: 3px 0px 7px #888888;
text-align: center;
padding: 10px;
}
</style>
</head>
<body>
<div id="textWrapper">
<div class="outerWrapper" style="max-height: 40vh">
<div class="navbar"></div>
<div id="view" style="width: 100%; overflow: scroll;"></div>
</div>
<div>
<table id="tableView" style="overflow: scroll; border: 1px solid black"><tr></tr></table>
</div>
<div id="relatedExpressions">
</div>
</div>
</div>
</div>
<div id="imageViewer"></div>
</div>
<!-- </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'].split("@")[0];
var wordRange = getUrlVar()['id'].split("@")[1];
var wordRangeStart = wordRange && wordRange.split("-")[0]
var wordRangeEnd = wordRange && wordRange.split("-")[1]
const state = [blockId]
//get manifestations (loop through manifestsions, add promises to array)
const sparqlEndpoint = "https://sparql-docker.scta.info/ds/query";
function getRelatedExpressionsQuery(resourceid, offset, pagesize, rangeStart, rangeEnd) {
let rangeFilter;
if (rangeStart && rangeEnd) {
rangeFilter = ["FILTER (?isRelatedToRangeEnd <=" + rangeEnd + ")",
"FILTER (?isRelatedToRangeStart >=" + rangeStart + ")"].join(" ")
}
let activeSource;
if (!rangeStart && !rangeEnd) {
activeSource = [
"{",
"?element <http://scta.info/property/source> ?isRelatedTo .",
"FILTER (!isBlank(?isRelatedTo)) .",
"}",
"UNION",
"{",
"?element <http://scta.info/property/source> ?bn .",
"?bn <http://scta.info/property/source> ?isRelatedTo .",
"?bn <http://scta.info/property/canonicalRangeStart> ?isRelatedToRangeStart .",
"?bn <http://scta.info/property/canonicalRangeEnd> ?isRelatedToRangeEnd .",
"}"].join(" ")
}
else {
activeSource = ["?element <http://scta.info/property/source> ?bn .",
"?bn <http://scta.info/property/source> ?isRelatedTo .",
"?bn <http://scta.info/property/canonicalRangeStart> ?isRelatedToRangeStart .",
"?bn <http://scta.info/property/canonicalRangeEnd> ?isRelatedToRangeEnd .",
rangeFilter].join(" ")
}
let inverseSource;
if (!rangeStart && !rangeEnd) {
inverseSource = ["{",
"?isRelatedTo <http://scta.info/property/source> ?element .",
"}",
"UNION",
"{",
"?isRelatedTo <http://scta.info/property/source> ?bn .",
"?bn <http://scta.info/property/source> ?element .",
"?bn <http://scta.info/property/canonicalRangeStart> ?isRelatedToRangeStart .",
"?bn <http://scta.info/property/canonicalRangeEnd> ?isRelatedToRangeEnd .",
"}"].join(" ")
}
else {
inverseSource = ["?isRelatedTo <http://scta.info/property/source> ?bn .",
"?bn <http://scta.info/property/source> ?element .",
"?bn <http://scta.info/property/canonicalRangeStart> ?isRelatedToRangeStart .",
"?bn <http://scta.info/property/canonicalRangeEnd> ?isRelatedToRangeEnd .",
rangeFilter].join(" ")
}
const query = [
"SELECT DISTINCT ?isRelatedTo ?label ?element ?longTitle ?author ?authorTitle ?isRelatedToRangeStart ?isRelatedToRangeEnd ?parentBlock ",
"WHERE",
"{ ",
//"BIND (<" + resourceid + "> as ?resource)",
"{",
"<" + resourceid + "> ?o ?isRelatedTo .",
"?o a <http://scta.info/resource/textRelation> .",
"FILTER (?o != <http://scta.info/property/quotes>)",
"FILTER (?o != <http://scta.info/property/quotedBy>)",
"FILTER (?o != <http://scta.info/property/references>)",
"FILTER (?o != <http://scta.info/property/referencedBy>)",
"?o <http://www.w3.org/1999/02/22-rdf-syntax-ns#label> ?label . ",
"?isRelatedTo a <http://scta.info/resource/expression> .",
"}",
"UNION",
"{",
"{",
"<" + resourceid + "> <http://scta.info/property/structureType> <http://scta.info/resource/structureElement> .",
"BIND (<" + resourceid + "> as ?element)",
"}",
"UNION",
"{",
"?element <http://scta.info/property/isMemberOf> <" + resourceid + "> .",
"}",
"{",
activeSource,
"?element <http://scta.info/property/structureElementType> <http://scta.info/resource/structureElementQuote> .",
"BIND ('quotes' as ?label) .",
"}",
"UNION",
"{",
activeSource,
"?element <http://scta.info/property/structureElementType> <http://scta.info/resource/structureElementRef> .",
"BIND ('refs' as ?label) .",
"}",
"}",
"UNION",
"{",
"{",
"BIND (<" + resourceid + "> as ?element)",
"}",
"UNION",
"{",
"?element <http://scta.info/property/isMemberOf> <" + resourceid + "> .",
"}",
"{",
inverseSource,
"?isRelatedTo <http://scta.info/property/structureElementType> <http://scta.info/resource/structureElementQuote> .",
"BIND ('isQuotedBy' as ?label) .",
"}",
"UNION",
"{",
inverseSource,
//"?isRelatedTo <http://scta.info/property/source> ?element.",
"?isRelatedTo <http://scta.info/property/structureElementType> <http://scta.info/resource/structureElementRef> .",
"BIND ('isReferencedBy' as ?label) .",
"}",
"}",
"?isRelatedTo <http://scta.info/property/longTitle> ?longTitle .",
"?isRelatedTo <http://scta.info/property/isMemberOf> ?mem .",
"?mem <http://scta.info/property/level> '1' .",
"OPTIONAL",
"{",
"?mem <http://www.loc.gov/loc.terms/relators/AUT> ?author .",
"?author <http://purl.org/dc/elements/1.1/title> ?authorTitle",
"}",
"OPTIONAL",
"{",
"?isRelatedTo <http://scta.info/property/isPartOfStructureBlock> ?parentBlock .",
//"?isRelatedTo <http://scta.info/property/isMemberOf> ?parentBlock .",
//"?parentBlock <http://scta.info/property/structureType> <http://scta.info/resource/stuctureBlock> .",
"}",
"}",
"ORDER BY ?authorTitle",
"LIMIT " + pagesize,
"OFFSET " + offset
].join(' ');
return query
}
function getRelatedExpressions(resourceid, offset, pagesize, rangeStart, rangeEnd) {
query = getRelatedExpressionsQuery(resourceid, offset, pagesize, rangeStart, rangeEnd)
promiseContainer = new Promise(function (resolve, reject) {
$.get(sparqlEndpoint, { query: query }, function (data) {
const dataArray = data.results.bindings.map((i) => {return i.isRelatedTo.value})
resolve(dataArray)
});
});
return promiseContainer
}
function displayRelatedExpressions(blockid, offset, pagesize, rangeStart, rangeEnd){
const relatedExpressions = getRelatedExpressions(blockid, offset, pagesize, rangeStart, rangeEnd)
relatedExpressions.then((d) => {
d.forEach((i) => {
$("#relatedExpressions").append("<p class='addRelated' data-id='" + i + "'>" + i + "</p>");
})
})
}
function addRelated(id){
state.push(id)
const relatedTranscriptions = displayCollateX([...state, id], "view")
}
function textReduce(text, wordRange) {
const wordTokenStart = wordRange.split("-")[0]
const wordTokenEnd = wordRange.split("-")[1]
const wordTokens = text.split(" ")
// NOTE: I'm not sure what this .filter(Boolean) is doing??
const wordTokensClean = wordTokens.filter(Boolean)
//const wordTokensBefore = wordTokensClean.slice(0, wordTokenStart - 1);
//const wordTokensAfter = wordTokensClean.slice(wordTokenEnd)
const wordTokensFocus = wordTokensClean.slice(wordTokenStart - 1, wordTokenEnd)
const reducedText = wordTokensFocus.join(" ")
return reducedText
}
/**
* @description get transcriptions return json object as Promise
*
**/
function getTranscriptions(resourceId, wrapper){
$("#tableView").html("loading");
var idsArray = state.map((i) => {return "<" + i + ">"})
var ids = idsArray.join(" ")
var query = [
"SELECT ?transcription ?block_transcription ?next ?previous ?shortId ?itemShortId ?topLevelShortId ?individualBlockId ",
"WHERE",
"{",
"VALUES ?blockid {" + ids + "} . " ,
//"BIND(<http://scta.info/resource/adt-l14-d1e1535> as ?blockid)",
"?blockid <http://scta.info/property/hasManifestation> ?block_manifestation .",
"?block_manifestation <http://scta.info/property/isManifestationOf> ?individualBlockId .",
"?blockid <http://scta.info/property/shortId> ?shortId .",
"?block_manifestation <http://scta.info/property/hasCanonicalTranscription> ?block_transcription .",
"OPTIONAL",
"{",
"?blockid <http://scta.info/property/isPartOfStructureItem> ?structureItem .",
"?structureItem <http://scta.info/property/shortId> ?itemShortId .",
"?blockid <http://scta.info/property/isPartOfTopLevelExpression> ?topLevel .",
"?topLevel <http://scta.info/property/shortId> ?topLevelShortId .",
"}",
"MINUS {",
"?block_transcription <http://scta.info/property/transcriptionType> 'translation' .",
"}",
"OPTIONAL {",
"?blockid <http://scta.info/property/next> ?next .",
"}",
"OPTIONAL {",
"?blockid <http://scta.info/property/previous> ?previous .",
"}",
"}"].join('');
promiseContainer = new Promise(function (resolve, reject) {
$.get(sparqlEndpoint, { query: query }, function (data) {
var results = data.results.bindings;
const topLevelShortId = results[0].topLevelShortId ? results[0].topLevelShortId.value : "";
const itemShortId = results[0].topLevelShortId ? results[0].itemShortId.value : "";
if (state.length === 1){
$("#" + 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) {
// block of code to remove any lingering punctuation
// code retrieved from https://stackoverflow.com/a/48387827/731085
var punctuationRegEx = /[!-/:-@[-`{-~¡-©«-¬®-±´¶-¸»¿×÷˂-˅˒-˟˥-˫˭˯-˿͵;΄-΅·϶҂՚-՟։-֊־׀׃׆׳-״؆-؏؛؞-؟٪-٭۔۩۽-۾܀-܍߶-߹।-॥॰৲-৳৺૱୰௳-௺౿ೱ-ೲ൹෴฿๏๚-๛༁-༗༚-༟༴༶༸༺-༽྅྾-࿅࿇-࿌࿎-࿔၊-၏႞-႟჻፠-፨᎐-᎙᙭-᙮᚛-᚜᛫-᛭᜵-᜶។-៖៘-៛᠀-᠊᥀᥄-᥅᧞-᧿᨞-᨟᭚-᭪᭴-᭼᰻-᰿᱾-᱿᾽᾿-῁῍-῏῝-῟῭-`´-῾\u2000-\u206e⁺-⁾₊-₎₠-₵℀-℁℃-℆℈-℉℔№-℘℞-℣℥℧℩℮℺-℻⅀-⅄⅊-⅍⅏←-⏧␀-␦⑀-⑊⒜-ⓩ─-⚝⚠-⚼⛀-⛃✁-✄✆-✉✌-✧✩-❋❍❏-❒❖❘-❞❡-❵➔➘-➯➱-➾⟀-⟊⟌⟐-⭌⭐-⭔⳥-⳪⳹-⳼⳾-⳿⸀-\u2e7e⺀-⺙⺛-⻳⼀-⿕⿰-⿻\u3000-〿゛-゜゠・㆐-㆑㆖-㆟㇀-㇣㈀-㈞㈪-㉃㉐㉠-㉿㊊-㊰㋀-㋾㌀-㏿䷀-䷿꒐-꓆꘍-꘏꙳꙾꜀-꜖꜠-꜡꞉-꞊꠨-꠫꡴-꡷꣎-꣏꤮-꤯꥟꩜-꩟﬩﴾-﴿﷼-﷽︐-︙︰-﹒﹔-﹦﹨-﹫!-/:-@[-`{-・¢-₩│-○-�]|\ud800[\udd00-\udd02\udd37-\udd3f\udd79-\udd89\udd90-\udd9b\uddd0-\uddfc\udf9f\udfd0]|\ud802[\udd1f\udd3f\ude50-\ude58]|\ud809[\udc00-\udc7e]|\ud834[\udc00-\udcf5\udd00-\udd26\udd29-\udd64\udd6a-\udd6c\udd83-\udd84\udd8c-\udda9\uddae-\udddd\ude00-\ude41\ude45\udf00-\udf56]|\ud835[\udec1\udedb\udefb\udf15\udf35\udf4f\udf6f\udf89\udfa9\udfc3]|\ud83c[\udc00-\udc2b\udc30-\udc93]/g;
var string = data;
// truncate compare string
var string = r.individualBlockId.value === blockId && wordRange ? textReduce(string, wordRange) : string
var newString = string.replace(punctuationRegEx, '').replace(/(\s){2,}/g, '$1');
var dataObject = {
"text": newString,
"id": r.block_transcription.value,
topLevelShortId,
itemShortId,
}
resolve(dataObject)
});
});
return textPromise
});
resolve(promiseArray)
});
});
return promiseContainer
}
function displayCollateX(blockId, wrapper) {
promiseContainer = getTranscriptions(blockId, wrapper)
promiseContainer.then(function(promiseArray){
Promise.all(promiseArray).then(function (values) {
const witnesses = values.map(function (r, i) {
const eslug = r.id.split("/resource/")[1].split("/")[0]
const mslug = r.id.split("/resource/")[1].split("/")[1]
return { "id": eslug + "/" + mslug, "content": r.text }
});
const postObject = {
"algorithm": "dekker",
"joined": true,
"tokenComparator": { "type": "equality" },
"transpositions": true,
"witnesses": witnesses
}
const url = "https://collatex.net/demo/collate"
if (getUrlVar()['image'] === "true"){
getSVGView(url, postObject);
}
getTableView(url, postObject, values[0].topLevelShortId, values[0].itemShortId);
});
});
}
function getSVGView(url, postObject){
// get table view
//const url = "http://localhost:7369/collate"
// get graph view
$.ajax({
type: "POST",
url: url,
data: JSON.stringify(postObject),
headers: {
"Accept": "image/svg+xml",
"Content-Type": "application/json",
},
success: function (d) {
$("#view").append(d);
$("#view").html($("#view").html());
},
error: function (e) {
$("#view").append(e.responseText);
},
dataType: "json"
});
}
function getTableView(url, postObject, topLevelShortId, itemShortId){
$.ajax({
type: "POST",
url: url,
data: JSON.stringify(postObject),
headers: {
"Accept": "application/json",
"Content-Type": "application/json",
},
success: function (d) {
//$.get("https://gist.githubusercontent.com/jeffreycwitt/93fea5c642d4b61b60552827f582e33d/raw/ad742521bff479092a9100b50802891e233f915c/checkList.json", (d2) => {
const checkListUrl = getUrlVar()['checklist'] === "local" ? "http://localhost:8081/report.json" : "https://exist.scta.info/exist/apps/scta-data/" + topLevelShortId + "/" + itemShortId + "/report.json";
$.get(checkListUrl, (d2) => {
// display table with remote or local checklist
displayTable(d, d2)
})
.fail(function(){
//if checklist is not available display table with empty array in place of retrieved checklist
displayTable(d, [])
})
},
error: function (e) {
// error handling for original request for collatex json table info
console.log(e)
},
dataType: "json"
});
}
function displayTable(d, d2){
// get checklist corresponding to block id
checkList = d2[blockId] ? d2[blockId].segments : []
// create table headings
$("#tableView").append("<tr id='wit'>");
$("#wit").append("<th>seg</th>");
$("#wit").append("<th>checkList</th>");
$("#wit").append("<th>reason</th>");
$("#tableView").parent().append("<button class='clearFilter'>Clear Filter</button>");
//initiateChosenTextIndex and then set in following loop when witness title == "critical"
let chosenTextIndex;
d.witnesses.forEach((w, ix) => {
if (w === blockId + "critical"){
//if (w === "cod-pu6y7d"){
chosenTextIndex = ix
}
$("#wit").append("<th>" + w + "</th>");
})
// populate segments with variants
let variantNumberSkips = 0;
d.table.forEach((seg, ix) => {
//calculate if segment is status variant or invariant
const variantStatus = checkVariantStatus(d.table, ix)
const variantClass = variantStatus ? "invariant" : "variant"
let status = "unknown"
let reasons;
if (variantStatus){
status = "invariant"
variantNumberSkips++;
}
else{
// get checkList status for segment
status = checkList[ix-variantNumberSkips] && checkList[ix-variantNumberSkips].status
reasons = checkList[ix-variantNumberSkips] && checkList[ix-variantNumberSkips].reasons
}
// add segment row
$("#tableView").append("<tr class='textRow " + variantClass + "' id='row-" + ix + "'>");
// add segment number and status
$("#row-" + ix).append("<td>" + (ix + 1) + "</td>");
$("#row-" + ix).append("<td>" + status + "</td>");
let reasonLinks = ""
if (reasons){
reasonLinks = reasons.map((r) => {
const description = d2.principles[r]
return "<span class='reason' title='" + description + "'>" + r + "</span>";
})
reasonLinks = reasonLinks && reasonLinks.join(" ");
}
$("#row-" + ix).append("<td>" + reasonLinks + "</td>");
// get word range for each segment
const segCount = []
seg.forEach((i, ix2) => {
if (ix > 0){
//const prevLength = seg[ix2].length
let prevLength = 0
d.table.forEach((seg2, ix3) => {
if (ix3 < ix){
prevLength = prevLength + seg2[ix2].length
}
})
const newStart = prevLength + 1
const count = {start: newStart, end: i.length + prevLength}
segCount.push(count)
}
else{
const count = {start: 1, end: i.length}
segCount.push(count)
}
// if seg is variant (not invariant) and does match chosenText, set chosen status to "chosen" otherwise set to "unchosen"
const chosenStatus = (!variantStatus && seg[chosenTextIndex] && seg[chosenTextIndex].join(" ").toLowerCase() === i.join(" ").toLowerCase()) ? "chosen" : "unchosen"
// add segment text for each witness
$("#row-" + ix).append("<td class=" + chosenStatus + "><a class='lbp-link' target='_new' href='https://scta.lombardpress.org/res?resourceid=http://scta.info/resource/" + d.witnesses[ix2] + "/transcription@" + segCount[ix2].start + "-" + segCount[ix2].end + "'>" + i.join(" ").toLowerCase() + "</a></td>");
})
})
}
function checkVariantStatus(table, ix){
segmentArray = table[ix].map((i)=> {
return i.join(" ").trimRight().toLowerCase();
})
const invariant = dedupe(segmentArray).length == 1 //true or false
return invariant
}
function filterReasons(reason){
$( ".textRow:not(:contains(" + reason + "))").addClass("hidden");
}
function unfilterReasons(){
$(".textRow").removeClass("hidden");
}
//items = Array
// see https://js-algorithms.tutorialhorizon.com/2016/01/25/dedupe-an-array-javascript/
function dedupe(items){
var result = [];
items.forEach(function(element) {
if (result.indexOf(element) === -1) {
result.push(element);
}
});
return result;
}
displayCollateX(blockId, "view")
displayRelatedExpressions(blockId, 0, 200, wordRangeStart, wordRangeEnd)
$(document).on("click", ".reason", function(e){
const reason = $(e.target).text()
filterReasons(reason);
})
$(document).on("click", ".clearFilter", function(e){
unfilterReasons();
})
$(document).on("click", ".addRelated", function(e){
console.log("test firing");
const id = $(e.target).attr("data-id")
addRelated(id)
})
$(document).on("click", ".lbp-link", function(e){
event.preventDefault()
const link = $(this).attr("href")
const resourceid = link.split("resourceid=")[1]
const pid = resourceid.split("@")[0]
const manifestationSlug = pid.split("/")[pid.split("/").length - 2 ]
const wordRange = resourceid.split("@")[1]
const firstWord = parseInt(wordRange.split("-")[0])
$.get("https://exist.scta.info/exist/apps/scta-app/word-line-lookup.xq?tid=" + pid, function(d){
const entry = d[firstWord -1]
const line = entry.line
const wordLinePosition = entry.wordLinePosition
const wordLineTotal = entry.wordLineTotal
const page = entry.precedingpb.replace("-", '');
const shortSurfaceId= manifestationSlug + "/" + page;
const coordsUrl = "https://exist.scta.info/exist/apps/scta-app/folio-annotaiton-list-from-simpleXmlCoordinates.xq?surfaceid=" + shortSurfaceId + "&coords=loose";
$.get(coordsUrl, function(d2){
const lr = d2.resources[line - 1]
const imageUrlBase = lr.imageUrl
const coords = lr.on.split("#")[1].split("=")[1]
const text = lr.resource.chars
const lineWidth = parseInt(coords.split(",")[2])
const x = parseInt(coords.split(",")[0])
const lineWidthDivision = lineWidth / wordLineTotal
const xOffSet = (x + (lineWidthDivision * (wordLinePosition - 1)))
const newCoords = (parseInt(xOffSet) - 300) + "," + coords.split(",")[1] + "," + (parseInt(lineWidthDivision) + 300) + "," + coords.split(",")[3]
//const imageUrl = imageUrlBase + "/" + newCoords + "/full/0/default.jpg"
const imageUrl = imageUrlBase + "/" + coords + "/full/0/default.jpg"
$("#imageViewer").css("display", "block")
$("#imageViewer").html("<div><img src='" + imageUrl + "'/><p>" + lr.label + ": " + lr.resource.chars + "</p><p><a href='" + link + "' target='_new'>view in lbpweb</a></p></div>");
});
});
})
</script>
</body>
</html>