-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
179 lines (152 loc) · 5.18 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
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
import getSuttaData from "./getSuttaData.js";
import { books } from "./books.js";
import optionSettings from "./optionSettings.js";
import buildTitlePage from "./buildTitlePage.js";
const suttaTable = document.querySelector("#sutta-html");
const body = document.querySelector("body");
optionSettings();
document.onkeyup = function (e) {
if (e.key == "s") {
console.log(e.target.id);
const bodyElement = document.querySelector("body");
bodyElement.classList.toggle("side-by-side");
}
};
suttaTable.innerHTML = "";
// MAKE BOOK BUTTON
const makeBookButton = document.getElementById("make-the-book");
makeBookButton.addEventListener("click", () => {
suttaTable.innerHTML = "";
const progressLabel = document.getElementById("progress-label");
const progressBar = document.getElementById("progress-bar");
const progressOuter = document.getElementById("progress-outer");
progressLabel.innerHTML = "Working<span class='blink'>…</span>";
progressBar.style.width = "0%";
progressOuter.style.border = "solid 1px rgb(67, 67, 67)";
setTimeout(() => {
makeTheBook();
}, 50);
});
// COPY BUTTON
const copyButton = document.getElementById("copy");
copyButton.addEventListener("click", () => {
const selection = document.getElementById("selection").value;
const HTML_OPEN = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>${selection}</title>
<style>
/* Not all of this CSS may be necessary based on the build options you picked*/
.reference {
background-color: rgb(96, 77, 0);
color: white;
font-family: sans-serif;
font-size: 0.7rem;
border: solid 0px;
border-radius: 5px;
padding: 2px 4px 2px 2px;
display: inline;
margin-right: .5rem;
}
header ul {
display: none;
}
/* Book frontmatter */
.center {
text-align: center;
}
.italic {
font-style: italic;
}
.large {
font-size: 1.3rem;
}
.top-margin {
margin-top: 1rem;
}
/*Sutta Content*/
p.pli-verse {
margin-bottom: 0.3rem;
margin-left: 1rem;
}
span.pli-lang {
display: block;
font-weight: bold;
}
span.eng-lang {
display: block;
}
/*Activate code below to display segments side by side*/
/*Do not use for English only books*/
/*
p.eng-verse {
margin-bottom: 1rem;
margin-top: 0rem;
margin-left: 1rem;
}
.segment-pair {
display: flex;
flex-direction: row;
}
.segment {
width: 50%;
}
span.pli-lang {
display: block;
font-weight: bold;
}
*/
</style>
</head>
<body>
`;
const HTML_CLOSE = `
</body>
</html>`;
if (localStorage.htmlPageWrapper) {
navigator.clipboard.writeText(HTML_OPEN + suttaTable.innerHTML + HTML_CLOSE);
} else navigator.clipboard.writeText(suttaTable.innerHTML);
});
// Toggle ToC BUTTON
const tocButton = document.getElementById("toc");
tocButton.addEventListener("click", () => {
body.classList.toggle("hide-content");
});
//
function makeTheBook() {
const selection = document.getElementById("selection").value;
const [bookAbbreviation, translator] = selection.split("|");
const bookContents = books[bookAbbreviation]; // array of section titles and ids for the current book
const lenghtOfBook = bookContents.length;
localStorage.completionCounter = 0;
buildTitlePage(bookAbbreviation, translator);
console.log(bookAbbreviation);
bookContents.forEach(article => {
// article will be either a uid or the contents of the chapter/section title page
if (/chapter/.test(article) || /section/.test(article)) {
// This builds the section pages
let [id, paliTitle, englishTitle] = article.split("|");
suttaTable.innerHTML += `<article id="${id}" class="sectionpage">
<div class="title">
<h1 title="${englishTitle}" class="${id.replace(/\d+/, "")}"><span class="pli-lang">${paliTitle}</span> <span class="eng-lang">${englishTitle}</span></h1>
</div>
</article>\n`;
localStorage.completionCounter++;
const progressBar = document.getElementById("progress-bar");
const width = (localStorage.completionCounter / lenghtOfBook) * 100;
progressBar.style.width = width + "%";
if (localStorage.completionCounter === lenghtOfBook) {
const progressLabel = document.getElementById("progress-label");
progressLabel.innerHTML = "Finished";
}
} else {
// this adds the article tag into the dom for each sutta.
suttaTable.innerHTML += `<article id="${article}"></article>\n`;
// This starts the process of building the sutta that will be put into that above dom item when the process is finished.
getSuttaData(bookAbbreviation, article, translator, lenghtOfBook);
}
});
}