-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommon.js
More file actions
38 lines (34 loc) · 1.44 KB
/
common.js
File metadata and controls
38 lines (34 loc) · 1.44 KB
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
async function checkFileAccess() {
function htmlToElement(html) {
const range = document.createRange();
range.selectNode(document.body);
return range.createContextualFragment(html).firstElementChild;
}
const onError = function () {
const bootstrapContainer = document.getElementsByClassName('container');
const container = bootstrapContainer.length ? bootstrapContainer[0] : document.body;
container.insertAdjacentElement('afterbegin', htmlToElement(`
<div style="color: red; font-size: 20px; margin: 40px 0;">
<p>Failed to access data files. Are you trying to open this page as a local HTML file?</p>
<p>Use a web server (such as <code class="code">npm install -g http-server</code> and run <code class="code">http-server</code>)
or go to <a href="https://alexp11223.github.io/D3FlightsDataVisualization/">https://alexp11223.github.io/D3FlightsDataVisualization/</a>
</p>
</div>`));
};
try {
await d3.json('data/months.json');
} catch (e) {
onError();
throw e;
}
}
$(function() {
// noinspection JSIgnoredPromiseFromCall
checkFileAccess();
$('[data-toggle="tooltip"]').tooltip();
$('.code-spoiler .collapse').each((i, element) => {
const id = `codeSpoiler${i}`;
$(element).attr('id', id);
$(element).siblings('a').attr('href', `#${id}`);
})
});