generated from rwhscott/uv-hello-world
-
Notifications
You must be signed in to change notification settings - Fork 2
/
mirador.html
112 lines (102 loc) · 3.47 KB
/
mirador.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="icon" href="favicon.ico">
<title>BFI Mirador</title>
</head>
<body>
<div id="mirador" class="mirador"></div>
<script type="text/javascript" src="//cdn.jsdelivr.net/npm/[email protected]/dist/mirador.min.js"></script>
<script type="text/javascript" src="//cdn.jsdelivr.net/npm/[email protected]/dist/axios.min.js"></script>
<script type="text/javascript">
// Full list of settings available at: https://github.com/ProjectMirador/mirador/blob/master/src/config/settings.js
var miradorInstance = Mirador.viewer({
id: 'mirador',
windows: [
{
id: 'window-1',
imageToolsEnabled: true,
allowClose: false,
allowMaximize: false,
sideBarOpenByDefault: true,
manifestId: getManifestFromHash() || 'https://bfinationalarchivemanifest.bfi.org.uk/works/150784974/manifest.json',
},
],
workspaceControlPanel: {
enabled: false,
},
theme: {
palette: {
primary: {
main: '#333',
},
shades: {
dark: '#ffffff',
main: '#ffffff',
light: '#fffff',
},
},
}
});
// Observing store for changes.
var previousState = null;
miradorInstance.store.subscribe(function () {
var state = miradorInstance.store.getState();
if (previousState) {
var prevWindow = previousState.windows['window-1'];
var newWindow = state.windows['window-1'];
// Manifest changed.
if (prevWindow.manifestId !== newWindow.manifestId) {
logEvent('resource_loaded', {
uri: newWindow.manifestId,
})
}
// Canvas changed.
if (prevWindow.canvasId !== newWindow.canvasId) {
logEvent('image_changed', {
manifest: newWindow.manifestId,
canvas: newWindow.canvasId,
})
}
}
previousState = state;
});
// Observing hash for changes
window.addEventListener('hashchange', function() {
var newManifest = getManifestFromHash();
if (newManifest) {
miradorInstance.store.dispatch(
Mirador.actions.updateWindow('window-1', {
manifestId: newManifest,
})
);
}
}, false);
function logEvent(type, payload) {
payload.type = type;
axios.post('/api/event', payload, {
headers: {
'Content-Type': 'application/json',
},
validateStatus: status => status === 200 || status === 204
}).catch(error => {
console.error('Got [' + JSON.stringify(error) + '] logging event [' + JSON.stringify(payload) + ']');
logout();
});
}
function logout() {
window.location.replace('/logout')
}
function getManifestFromHash() {
var matches = location.hash.match(/manifest=(.*)&?/);
if (matches && matches[1]) {
return matches[1];
}
return null;
}
</script>
</body>
</html>