-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
65 lines (58 loc) · 1.8 KB
/
script.js
File metadata and controls
65 lines (58 loc) · 1.8 KB
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
const $body = $("body");
const $grid = $(".grid");
const $employee = $(".employee");
const $employeeOutput = $(".output", ".employee");
// combine html/json for each user and print to DOM
function printUser(data) {
const person = data.results.map((person) => {
const bday = person.dob.date.slice(0, 10);
return `<div class="box">
<div class="col1">
<div class="avatar" style="background-image:url('${person.picture.large}');"></div>
</div>
<div class="col2">
<div class="name">
<span class="first"><strong>${person.name.first}</strong></span>
<span class="last"><strong>${person.name.last}</strong></span>
</div>
<div class="email">${person.email}</div>
<div class="city">${person.location.city}</div>
</div>
<div class="col3">
<div class="cell">${person.cell}</div>
<div class="address">
<span class="street">${person.location.street.name}, </span>
<span class="state">${person.location.state}, </span>
<span class="postcode">${person.location.postcode}</span>
</div>
<div class="dob">Birthday: <span class="output">${bday}</span></div>
</div>
<div class="exit">x</div>
</div>`;
});
$grid.html(person);
}
// request data from randomuser.me using jquery ajax
function apiCall() {
$.ajax({
url:
"https://randomuser.me/api/?results=12&inc=name,email,location,dob,cell,picture",
dataType: "json",
success: printUser,
});
}
function closeOverlay() {
$body.removeClass("lightbox");
$employee.html("");
$employeeOutput.html("");
}
function openOverlay() {
$body.addClass("lightbox");
let store = $(this).html();
$employee.html(store);
}
apiCall();
$(document).ready(function () {
$grid.on("click", ".box", openOverlay);
$employee.on("click", ".exit", closeOverlay);
});