generated from CollectionBuilder/collectionbuilder-gh
-
Notifications
You must be signed in to change notification settings - Fork 1
/
item-js.html
144 lines (133 loc) · 8.22 KB
/
item-js.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
{%- assign fields = site.data.config-metadata -%}
{%- assign stubs = site.data.config-nav | map: 'stub' | join: ';' -%}
<script>
(function(){
/* add item data */
var items = {
{%- for item in site.data[site.metadata] -%}
{{ item.objectid | jsonify }} : { {% unless fields contains 'title' %}"title": {{ item.title | jsonify }}, {% endunless %}{% for f in fields %}{% if item[f.field] %}{{ f.field | jsonify }}: {{ item[f.field] | jsonify }}, {% endif %}{% endfor %}{% if item.youtubeid %} "youtube": {{ item.youtubeid | jsonify }}, {% endif %}{% if item.vimeoid %} "vimeo": {{ item.vimeoid | jsonify }}, {% endif %}"format": {{ item.format | jsonify }}, {% if item.filename contains '/' %}"filename": "{{ item.filename }}" {% else %}"filename":{{ '/objects/' | relative_url | append: item.filename | jsonify }}{% endif %} }{% unless forloop.last %}, {% endunless %}
{% endfor %}
};
/* get query id from URL */
var queryString = window.location.search.substring(1).split("=")[1];
var record = items[queryString];
if (record) {
/* add item title */
var objectTitle = record.title;
document.getElementById("bc-title").innerHTML = objectTitle;
document.getElementById("item-title").innerHTML = objectTitle;
/* add object */
var format = "" + record.format;
var objectLink = record.filename;
var itemImage, itemLink;
if (format.includes('image')) {
itemImage= '<div class="spotlight gallery-img" data-download="true" data-src="' + objectLink + '"><img class="img-fluid" src="' + objectLink + '" alt="' + objectTitle + '"><p><small>Click to view full screen</small></p></div>';
itemLink= '<a href="' + objectLink + '" target="_blank" rel="noopener" class="m-2 btn btn-dark" title="Object download">Download Image</a>';
} else if (format.includes('pdf')) {
itemImage= '<object aria-label="' + objectTitle + '" data="' + objectLink + '" type="application/pdf" width="100%" height="450px"><p>The PDF is not rendering in your browser. Please use the button below to download the PDF.</p></object>';
itemLink= '<a href="' + objectLink + '" target="_blank" rel="noopener" class="m-2 btn btn-dark" title="Object download">Download PDF</a>';
} else if (format.includes('audio')) {
itemImage= '<audio controls class="w-100"><source src="' + objectLink + '">Your browser does not support the audio element.</audio>';
itemLink= '<a href="' + objectLink + '" target="_blank" rel="noopener" class="m-2 btn btn-dark" title="Object download">Download Audio File</a>';
} else if (record.youtube) {
itemImage= '<div class="ratio ratio-16x9"><iframe title="' + objectTitle + '" src="https://www.youtube-nocookie.com/embed/' + record.youtube + '?rel=0&modestbranding=1" allowfullscreen></iframe></div>';
itemLink= '<a href="https://youtu.be/' + record.youtube + '" target="_blank" rel="noopener" class="m-2 btn btn-dark" title="Object download">View on YouTube</a>';
} else if (record.vimeo) {
itemImage= '<div class="ratio ratio-16x9"><iframe title="' + objectTitle + '"src="https://player.vimeo.com/video/' + record.vimeo + '" allowfullscreen></iframe></div>';
itemLink= '<a href="https://vimeo.com/' + record.vimeo + '" target="_blank" rel="noopener" class="m-2 btn btn-dark" title="Object download">View on Vimeo</a>';
} else if (format.includes('video')) {
itemImage= '<video controls class="w-100"><source src="' + objectLink + '">Your browser does not support the video element.</audio>';
itemLink= '<a href="' + objectLink + '" target="_blank" rel="noopener" class="m-2 btn btn-dark" title="Object download">Download Video File</a>';
} else {
/* fall back to no preview if it doesn't know the format */
itemImage= '<img class="w-50" src="{{ "/assets/lib/icons/file-earmark.svg" | relative_url }}" alt="No preview found">';
itemLink= '<a href="' + objectLink + '" target="_blank" rel="noopener" class="m-2 btn btn-dark" title="Object download">Download Object</a>';
}
{% if stubs contains "timeline" %}
/* add link to view on timeline */
if (record.date) {
var itemYear;
if (record.date.includes('-')) {
itemYear = record.date.split('-')[0];
} else if (record.date.includes('/')) {
itemYear = record.date.split('/').pop();
} else {
itemYear = record.date;
}
itemLink += '<a href="{{ "/timeline.html" | relative_url }}#y' + itemYear + '" class="m-2 btn btn-outline-dark">View on Timeline</a>';
}
{%- endif -%}
{% if stubs contains "map" %}
/* add link to view on map */
if (record.latitude && record.longitude) {
itemLink += '<a href="{{ '/map.html' | relative_url }}#' + record.latitude + ',' + record.longitude + '" class="m-2 btn btn-outline-dark">View on Map</a>';
}
{%- endif -%}
/* add content to item display area */
document.getElementById("item-image").innerHTML = itemImage;
// document.getElementById("item-link").innerHTML = itemLink;
/* trigger Gallery for images */
// ?
/* add item metadata */
var fields = '<dl>';
{% for f in fields %}{% if f.browse_link == "true" %}
if (record[{{ f.field | jsonify }}]) {
var topics = record[{{ f.field | jsonify }}].split(';');
var browseLinks = "";
for (var i = 0, len = topics.length; i < len; i++) {
if (topics[i] != "") {
browseLinks += '<a class="btn btn-link" href="{{ '/browse.html' | relative_url }}#' + encodeURIComponent(topics[i].trim()) + '">' + topics[i].trim() + '</a> ';
}
}
fields += '<dt class="field">{{ f.display_name }}:</dt> <dd class="field-value">' + browseLinks + '</dd>';
}
{%- else -%}
if (record[{{ f.field | jsonify }}]) { fields += '<dt class="field">{{ f.display_name }}:</dt> <dd class="field-value">{% if f.external_link == "true" %}<a href="' + record[{{ f.field | jsonify }}] + '" target="_blank" rel="noopener">' + record[{{ f.field | jsonify }}] + '</a>{% else %}' + record[{{ f.field | jsonify }}] + '{% endif %}</dd>'; }
{% endif %}{% endfor %}
fields += '</dl>';
document.getElementById("item-metadata").innerHTML = fields;
{% if site.data.theme.browse-buttons == true %}
/* add prev/next nav */
var itemKeys = Object.keys(items);
var current = itemKeys.indexOf(queryString);
var last = itemKeys.length - 1;
var back, forward;
if (current === 0) {
back = itemKeys[last];
} else {
back = itemKeys[current - 1];
}
if (current === last) {
forward = itemKeys[0];
} else {
forward = itemKeys[current + 1];
}
var backUrl = "{{ '/item.html?id=' | relative_url }}" + back;
var forwardUrl = "{{ '/item.html?id=' | relative_url }}" + forward;
/* add side buttons to page */
document.getElementById("back-button").href = backUrl;
document.getElementById("next-button").href = forwardUrl;
/* add bottom buttons to page */
document.getElementById("prev-button").href = backUrl;
document.getElementById("for-button").href = forwardUrl;
/* add back forward key press */
document.onkeydown = function(evt) {
evt = evt || window.event;
switch (evt.keyCode) {
case 37:
location.href = backUrl;
break;
case 39:
location.href = forwardUrl;
break;
}};
{%- endif -%}
} else {
/* no item with that ID */
document.getElementById("bc-title").innerHTML = 'Not found?';
document.getElementById("item-title").innerHTML = 'Sorry, item not found. Please visit <a href="{{ "/browse.html" | relative_url }}">Browse page</a> to find an item.';
}
/* all done, so hide loading animation */
document.getElementById("loading").style.display = "none";
})();
</script>