-
Notifications
You must be signed in to change notification settings - Fork 25
/
01_script.js
36 lines (31 loc) · 1.1 KB
/
01_script.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
var searchBox = document.querySelector('#searchBox');
function onKeyUp() {
var regex = new RegExp(searchBox.value.toLowerCase());
var names = document.querySelectorAll('.names');
for (var i = 0; i < names.length; i++) {
var obj = names[i];
if (obj.innerHTML.toLowerCase().search(regex) === -1) {
obj.parentNode.style.display = 'none';
} else {
obj.parentNode.style.display = 'block';
}
}
}
function getData() {
var request = new XMLHttpRequest();
request.open('GET', 'js/01_data.json');
request.addEventListener('readystatechange', function () {
if ((request.status === 200) && (request.readyState === 4)) {
var data = JSON.parse(request.responseText);
var template = document.querySelector('#speakerstmpl').innerHTML;
var html = Mustache.to_html(template, data);
document.querySelector('#speakers').innerHTML = html;
}
})
request.send();
}
function onLoad() {
getData();
searchBox.addEventListener('keyup', onKeyUp);
}
window.addEventListener('load', onLoad);