-
Notifications
You must be signed in to change notification settings - Fork 4
/
window-functions.js
61 lines (52 loc) · 1.61 KB
/
window-functions.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
import $ from 'jquery';
import parseGedcom from 'parse-gedcom';
import { updateMarkers, getIndividual } from './geocode';
function updateRelevance(value) {
$('#relevanceOutput').val(value);
updateMarkers();
}
function readGedcomFile(file) {
return new Promise((resolve, reject) => {
const gedcomFile = file.target.files[0];
const reader = new FileReader();
reader.readAsText(gedcomFile);
reader.onload = function loadGedcom(event) {
$('#results').css('visibility', 'visible');
const gedcomJSON = parseGedcom.parse(event.target.result);
if ($.isEmptyObject(gedcomJSON)) {
reject(new Error('Empty GEDCOM file'));
}
// Limit people in family tree for testing
// const startingNumber = 1;
// const endingNumber = 10;
// for (let i = startingNumber; i < endingNumber; i += 1) {
// getIndividual(gedcomJSON[i]);
// }
gedcomJSON.forEach((individual) => {
getIndividual(individual);
});
resolve(gedcomJSON);
};
reader.onerror = function gedcomError() {
reject(new Error('Failed to load file'));
};
});
}
function showTooltip(event) {
const tooltip = $('#tooltip');
tooltip.css({
display: 'block',
left: `${event.pageX + 10}px`,
top: `${event.pageY + 10}px`,
});
}
function hideTooltip() {
const tooltip = $('#tooltip');
tooltip.css('display', 'none');
}
// https://stackoverflow.com/a/57603027
window.updateRelevance = updateRelevance;
window.readGedcomFile = readGedcomFile;
window.showTooltip = showTooltip;
window.hideTooltip = hideTooltip;
export { updateRelevance, readGedcomFile };