-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathih.js
79 lines (70 loc) · 3.81 KB
/
ih.js
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
jQuery(document).ready(function($){
$( function() {
$("#imageswidget").tooltip();
$("#images").tooltip();
} );
$(document).ready(function() {
$("#input").ready(function(event){
window.onload = function WindowLoad() {
params = window.location.search.substring(1).split("=");
o = 0;
pg = 1;
if (params[0] == 'pg') {
pg = params[1];
o = (+pg * 500) - 500;
$(window).scrollTop(0);
generate(o)
}
else {
generate(o)
}
}
function generate(o) {
$("#images").html('<center><img width=500 src="https://catalog.archives.gov/images/loader.gif"/></center>');
var images = '';
rows= 500;
if (location.href.split("/").slice(-1) == 'innovation-hub.html') { rows = 20 };
$.getJSON('https://catalog.archives.gov/OpaAPI/iapi/v1?action=search&q=%22citizen%20contributor%22&tabType=online&sort=naIdSort%20desc&rows=' + rows + '&f.locationIds=32 or 36&offset=' + o, function(t) {
for (i = 0; i < t.opaResponse.results.result.length; i++) {
for (d = 0; d < t.opaResponse.results.result[i].briefResults.metadataArea.length; d++) {
if (t.opaResponse.results.result[i].briefResults.metadataArea[d].name == 'creators') {
creators = t.opaResponse.results.result[i].briefResults.metadataArea[d].value
if (creators.isArray == 'True') {
creatorarray = creators
creators = creatorarray[0]
// for (c = 0; c < creators.length; c++) {
// creators = creators + '
' + creatorarray[c]
// }
}
}
if (t.opaResponse.results.result[i].briefResults.metadataArea[d].name == 'naId') { naid = t.opaResponse.results.result[i].briefResults.metadataArea[d].value }
}
if (t.opaResponse.results.result[i].thumbnailFile.startsWith('http', 0) == true) {
images = images + '<a href="https://catalog.archives.gov/id/' + t.opaResponse.results.result[i].naId + '"><img data-html="true" title="Title:
"' + t.opaResponse.results.result[i].briefResults.titleLine[0].value + '"

Creator:
' + creators + '

National Archives Identifier: ' + naid + '

(Click image for full catalog record.)" src="' + t.opaResponse.results.result[i].thumbnailFile + '" style="width:50px; height:50px" /></a>';
}
else {
images = images + '<a href="https://catalog.archives.gov/id/' + t.opaResponse.results.result[i].naId + '"><img data-html="true" title="Title:
"' + t.opaResponse.results.result[i].briefResults.titleLine[0].value + '"

Creator:
' + creators + '

National Archives Identifier: ' + naid + '

(Click image for full catalog record.)" src="https://catalog.archives.gov/OpaAPI/media/' + t.opaResponse.results.result[i].naId + '/' + t.opaResponse.results.result[i].thumbnailFile + '" style="width:50px; height:50px" /></a>';
} }
total = t.opaResponse.results['@total']
if ((t.opaResponse.results.result.length == 500) && ((total - o) !== 500)) {
$('#images').html('<p>There are currently <strong>' + total + '</strong> records with citizen-contributed images. Showing 500:</p><br/>' + images);
$('#more').show()
}
else {
$('#more').hide();
$('#images').html('<p>There are currently <strong>' + total + '</strong> records with citizen-contributed images. This is the end of the results set. Showing final ' + t.opaResponse.results.result.length + ':</p><br/>' + images)
$('#imageswidget').html('<p>There are currently <strong>' + total + '</strong> records with citizen-contributed images from the Innovation Hub. Here are the last 20:</p><br/>' + images);
}
});
}
$("#more").click(function(event){
pg = +pg + 1;
var url = window.location.pathname;
newParam="?pg=" + pg;
newUrl=url.replace(newParam,"");
newUrl+=newParam;
window.location.href = newUrl;
});
});
});
});