-
Notifications
You must be signed in to change notification settings - Fork 0
/
scripts.js
71 lines (48 loc) · 1.76 KB
/
scripts.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
// TESTING
// Grabs the root Div in the HTML
const app = document.getElementById('root')
// Creates a container for all the Gurbani divs to live inside
const container = document.createElement('div')
container.setAttribute('class','container')
// Puts the container inside the root div
app.appendChild(container)
// Create a request variable and assign a new XMLHttpRequest object to it.
var request = new XMLHttpRequest()
// Open a new connection, using the GET request on the URL endpoint
request.open('GET', 'https://api.banidb.com/v2/angs/917', true)
//request.open('GET', 'https://ghibliapi.herokuapp.com/films', true)
request.onload = function () {
// Load/Parse all raw API content into data variable
const data = JSON.parse(this.response)
// Display all raw data to console
console.log(data)
// Isolate ang verses into an array variable
const angContent = data.page
// Display angContent
console.log(angContent)
// Display the Gurmukhi lines from each verse on the ang
if (request.status >= 200 && request.status <400) {
angContent.forEach(gurmukhi => {
// Creates a div for each line with gurbaniLine class
const gurbaniLine = document.createElement('div')
gurbaniLine.setAttribute('class', 'gurbaniLine')
// Puts the Gurbani into a p
const p = document.createElement('p')
p.textContent = gurmukhi.verse.unicode
// Put gurbaniLine divs into the container
container.appendChild(gurbaniLine)
// put the p text into the gurbaniLine divs
gurbaniLine.appendChild(p)
})
} else {
console.log('HTTP error')
}
}
// Send request
request.send()
// Load next ang
const loadMore = () => {
request.open('GET', 'https://api.banidb.com/v2/angs/918', true)
const data = JSON.parse(this.response)
console.log(data)
}