-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
83 lines (66 loc) · 1.93 KB
/
app.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
// init
initReftagger();
var handlePeople = (function() {
var treeParent = document.getElementById('tree');
return function handlePeople(data) {
window.app = data;
addParents(app.people);
window.json = JSON.stringify(app, null, 2);
console.log('run this: copy(json)');
setupRoutes();
};
})();
handlePeople(peopleData);
// Reftagger
function initReftagger() {
// config
window.refTagger = {
settings: {
noSearchClassNames: ['editor-content', 'navbar']
}
};
// create <script>
var refTaggerScript = document.createElement('script');
refTaggerScript.src = '//api.reftagger.com/v2/RefTagger.js';
// append <script>
var firstScript = document.getElementsByTagName('script')[0];
firstScript.parentNode.insertBefore(refTaggerScript, firstScript);
// call refTagger.tag() whenever references are added to page
}
// routing
function routeToPerson(personKey, refNum) {
if (personKey && app.people[personKey]) {
new Card(personKey);
document.title = getName(personKey) + ' in the Bible';
if (refTagger.tag) refTagger.tag();
} else if (!personKey) {
app.router.navigate('!/adam');
} else {
console.error('Invalid person key: ' + personKey + '.');
}
}
function setupRoutes() {
var root = null;
var useHash = true;
app.router = new Navigo(root, useHash);
app.router
.on(/!\/([^/#]+)(?:#ref-(\d+))?/, routeToPerson)
.notFound(function () {
app.router.navigate('!/adam');
})
.resolve();
}
// app-specific helper functions
function getName(personKey) {
var person = app.people[personKey];
if (person.names) return person.names[0];
if (person.title) return person.title;
if (person.gender && person.spouses.length === 1) {
var spouse = app.people[person.spouses[0]];
if (spouse.names) {
var title = verbalize.givePossession(spouse.names[0]) + ' ' +
(person.gender === 'male' ? 'husband' : 'wife');
return title;
}
}
}