forked from UniversalViewer/uv-hello-world
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
114 lines (84 loc) · 2.84 KB
/
index.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
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
var uv, manifest, urlDataProvider;
window.addEventListener('uvLoaded', function(e) {
urlDataProvider = new UV.URLDataProvider();
loadManifests(function() {
setSelectedManifest();
setupUV();
});
}, false);
function setupUV() {
var collectionIndex = urlDataProvider.get('c');
var data = {
iiifResourceUri: manifest,
configUri: 'examples-config.json',
collectionIndex: (collectionIndex !== undefined) ? Number(collectionIndex) : undefined,
manifestIndex: Number(urlDataProvider.get('m', 0)),
sequenceIndex: Number(urlDataProvider.get('s', 0)),
canvasIndex: Number(urlDataProvider.get('cv', 0)),
rotation: Number(urlDataProvider.get('r', 0)),
rangeId: urlDataProvider.get('rid', ''),
xywh: urlDataProvider.get('xywh', '')
};
uv = createUV('#uv', data, urlDataProvider);
uv.on('created', function() {
Utils.Urls.setHashParameter('manifest', manifest);
console.log('parsed metadata', uv.extension.helper.manifest.getMetadata());
console.log('raw jsonld', uv.extension.helper.manifest.__jsonld);
});
}
function loadManifests(cb) {
// load manifests
$.getJSON('manifests.json', function(manifests) {
var $manifestSelect = $('#manifestSelect');
for (var i = 0; i < manifests.collections.length; i++) {
var collection = manifests.collections[i];
if (collection.visible === false) {
continue;
}
$manifestSelect.append('<optgroup label="' + collection.label + '">');
for (var j = 0; j < collection.manifests.length; j++) {
var manifest = collection.manifests[j];
if (manifest.visible !== false) {
$manifestSelect.append('<option value="' + manifest['@id'] + '">' + manifest.label + '</option>');
}
}
$manifestSelect.append('</optgroup>');
}
cb();
});
}
function setSelectedManifest() {
manifest = Utils.Urls.getHashParameter('manifest');
if (manifest) {
$('#manifestSelect').val(manifest);
} else {
var options = $('#manifestSelect option');
if (options.length) {
manifest = options[0].value;
}
}
$('#manifest').val(manifest);
}
$('#manifestSelect').on('change', function() {
$('#manifest').val($('#manifestSelect option:selected').val());
});
$('#setManifestButton').on('click', function() {
manifest = $('#manifest').val();
uv.set({
iiifResourceUri: manifest,
collectionIndex: undefined,
manifestIndex: 0,
sequenceIndex: 0,
canvasIndex: 0
});
});
$('#prev').on('click', function() {
uv.set({
canvasIndex: uv.get('canvasIndex') - 1
});
});
$('#next').on('click', function() {
uv.set({
canvasIndex: uv.get('canvasIndex') + 1
});
});