generated from rwhscott/uv-hello-world
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
104 lines (89 loc) · 3.14 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
var uv;
$.ajaxSetup({
xhrFields: {
withCredentials: true
},
beforeSend: function(jqXHR, settings) {
jqXHR.requestUrl = settings.url
},
error: function(jqXHR, textStatus, errorThrown) {
console.error('Got [' + errorThrown + '] logging request [' + jqXHR.requestUrl + ']');
logout();
}
})
requirejs.onResourceLoad = function (context, map, depArray) {
if (map.name === 'lib/manifesto.js') {
const originalLoad = window.Manifesto.loadManifest;
window.Manifesto.Utils.loadResource = window.Manifesto.loadManifest = function (url) {
return axios.get(url, {
withCredentials: true,
validateStatus: status => status === 200 || status === 204
}).then(function(r) {
return r.data;
}).catch(function (error) {
console.error('Got [' + JSON.stringify(error) + '] logging request [' + url + ']');
logout();
});
};
}
}
window.addEventListener('uvLoaded', function (e) {
var manifest = Utils.Urls.getHashParameter('manifest');
var urlDataProvider = new UV.URLDataProvider();
var collectionIndex = urlDataProvider.get('c');
if(!manifest) {
manifest = 'https://bfinationalarchivemanifest.bfi.org.uk/collections/stills.json'
}
uv = createUV('#uv', {
iiifResourceUri: manifest,
configUri: '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', '')
}, urlDataProvider);
uv.on('created', function() {
Utils.Urls.setHashParameter('manifest', manifest);
})
uv.on('showDownloadDialogue', function () {
logEvent('download_panel_opened', {
manifest: extractManifestId(uv),
canvas: extractCanvasId(uv)
});
});
uv.on('manifestIndexChanged', function (manifestIndex) {
logEvent('resource_loaded', {
uri: extractManifestId(uv)
})
});
uv.on('canvasIndexChanged', function (canvasIndex) {
logEvent('image_changed', {
manifest: extractManifestId(uv),
canvas: extractCanvasId(uv)
});
});
}, false);
function extractManifestId(uv) {
return uv.extension.helper.manifest.id;
}
function extractCanvasId(uv) {
return uv.extension.helper.getCurrentCanvas().id;
}
function logEvent(type, payload) {
payload.type = type;
axios.post('/api/event', payload, {
headers: {
'Content-Type': 'application/json',
},
validateStatus: status => status === 200 || status === 204
}).catch(function (error) {
console.error('Got [' + JSON.stringify(error) + '] logging event [' + JSON.stringify(payload) + ']');
logout();
});
}
function logout() {
window.location.replace('/logout')
}