-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbible_reader.js
216 lines (187 loc) · 5.08 KB
/
bible_reader.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// GLOBALS cause I just want this to be done kinda quickly.
var items;
var currentBook;
var currentChapter;
$.getJSON("json/t_kjv.json", function(data) {
items = [];
$.each(data, function(key, val) {
$.each(val.row, function(key2, val2) {
var book = val2.field[1]
var chapter = val2.field[2]
var verse = val2.field[3]
items.push({
bookNumber: book,
chapter: chapter,
verse: verse,
text: val2.field[4],
})
})
});
$.getJSON("json/key_english.json", function(data) {
var keys = data.resultset.keys;
$.each(items, function(key, value) {
items[key].bookName = keys[value.bookNumber - 1].n;
});
$.each(keys, function(key, value) {
$("#bookSelector").append("<option value = " + value.b + ">" + value.n + "</option>")
})
}).then(function() { chooseBook(1) });
});
/**
* chooseBook
*
* @param {*} bookNumber
*/
function chooseBook(bookNumber) {
var book = getBook("", bookNumber);
setCurrentBook(book);
var chapter = getChapter(1);
setCurrentChapter(chapter);
displayChapter();
setChapterSelector();
}
/**
*
* @param {*} chapterNumber
*/
function chooseChapter(chapterNumber) {
var chapter = getChapter(chapterNumber);
setCurrentChapter(chapter);
displayChapter();
}
/**
*
*/
function nextChapter() {
var nextChapterNumber = currentChapter[0].chapter + 1;
if (currentBook[currentBook.length - 1].chapter < nextChapterNumber) {
nextChapterNumber = 1;
setCurrentBook(getBook("", currentBook[0].bookNumber + 1));
}
var element = document.getElementById("chapterSelector");
element.value = nextChapterNumber;
setCurrentChapter(getChapter(nextChapterNumber));
displayChapter();
}
function backChapter() {
var backChapterNumber = currentChapter[0].chapter - 1;
if (backChapterNumber == 0) {
setCurrentBook(getBook("", currentBook[0].bookNumber - 1));
backChapterNumber = currentBook[currentBook.length - 1].chapter;
}
setCurrentChapter(getChapter(backChapterNumber));
displayChapter();
}
/**
* displayChapter
*
* @param {*} number
*/
function displayChapter() {
if (currentBook == undefined) {
setCurrentBook(getBook("Genesis"));
}
$('.currentChapter').empty();
$('.currentChapter').append(currentBook[0].bookName + " " + currentChapter[0].chapter.toString());
$('#ChapterDisplay').empty();
$.each(currentChapter, function(key, val) {
$('#ChapterDisplay').append("<p class='verseText' onclick='void(0)'> <span class='verse'>" + val.verse + "</span>" + val.text + "</p>");
});
setTheReadingPreference();
}
/**
* getBook
*
* @param {*} bookName
* @param {*} bookNumber
*/
function getBook(bookName = "", bookNumber = -1) {
var book = [];
if (bookNumber != -1) {
$.each(items, function(key, val) {
if (val.bookNumber == bookNumber) {
book.push(val);
}
});
} else {
$.each(items, function(key, val) {
if (val.bookName == bookName) {
book.push(val);
}
});
}
return book;
}
/**
* setCurrentBook
*
* @param {*} bookObject
*/
function setCurrentBook(bookObject) {
currentBook = bookObject;
}
/**
* getChapter
*
* @param {*} chapterNumber
*/
function getChapter(chapterNumber) {
chapter = [];
$.each(currentBook, function(key, val) {
if (val.chapter == chapterNumber) {
chapter.push(val);
}
});
return chapter;
}
/**
* setCurrentChapter
*
* @param {*} chapterObject
*/
function setCurrentChapter(chapterObject) {
currentChapter = chapterObject;
}
function setChapterSelector() {
$("#chapterSelector").empty();
var pushedChapter = 1;
$("#chapterSelector").append("<option>" + pushedChapter + "</option>");
$.each(currentBook, function(key, val) {
if (val.chapter != pushedChapter) {
pushedChapter = val.chapter;
$("#chapterSelector").append("<option value=" + pushedChapter + ">" + pushedChapter + "</option>");
}
})
}
function setTheReadingPreference() {
var verses = document.getElementsByClassName('verseText');
var newStyle = '';
if (document.getElementById('versebyverse').checked) {
newStyle = "display: block;";
} else {
newStyle = "display: inline;";
}
for (var i = 0; i < verses.length; i++) {
verses[i].style = newStyle
}
}
// sets up the two buttons
window.onload = function() {
$('#backAChapter').click(function() {
console.log('backChapter');
backChapter()
});
$('#forwardAChapter').click(function() {
console.log('nextChapter');
nextChapter()
});
$('#bookSelector').change(function() {
chooseBook(this.value);
});
$('#chapterSelector').change(function() {
chooseChapter(this.value);
});
$('#versebyverse').click(function() {
setTheReadingPreference();
});
};