/
index.js
40 lines (40 loc) · 1.4 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
"use strict";
if(!location.hash) location.hash = 1;
$(function() {
var psalmVersion = "liber";
var liber = [], vulgate = [], psalmMap = [];
$.get('../psalmMap.json', function(map) {
psalmMap = map;
});
$.get('../vulgate/Psalmi', function(wholeVulgate) {
wholeVulgate.trim().split('\n').reduce(function(vulgate, verse) {
var match = /^(\d+)\s+(\d+)\s+(.*)$/.exec(verse);
var psalm = match[1] - 1,
vnum = match[2] - 1;
if(!(psalm in vulgate)) vulgate[psalm] = [];
vulgate[psalm][vnum] = match[3];
return vulgate;
}, vulgate);
$(window).on('hashchange', function() {
var txtRef = decodeURIComponent(window.location.hash.slice(1));
if(/^\d/.test(txtRef)) {
txtRef = "Psalm " + txtRef;
}
var refs = parseRef(txtRef);
var title = refArrayString(refs);
$('.title').text(title);
$('#psalm').empty();
var lastRef = null;
var result = refs.map(ref => {
var obj = {};
ref.startInMiddle = lastRef && lastRef.book == ref.book && lastRef.chapter == ref.chapter && lastRef.getEndVerse() == (ref.verse - 1);
lastRef = ref;
ref.getLinesFromLiber().then(lines => {
obj.html = lines.map(l => `<div class='liber'>${l}</div>`).join('');
$('#psalm').html(result.map(o => o.html || '').join(''));
});
return obj;
});
}).trigger('hashchange');
});
})