-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
133 lines (113 loc) · 3.51 KB
/
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
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
const URL = 'http://leads.beta.openstudycollege.info/getTopLeads'
var promise = fetch(URL)
promise.then((response, reject) => response.json()).then(data => {
var random = Math.floor(Math.random() * data.length);
var user = data[random];
const theName = user.name;
const studentStatus = user.studentID
? "Employee"
: "Student"
const id = user.studentID
? user.studentID
: user.id;
const enStatus = user.status;
const completedCourses = user.phase_id;
const email = user.email;
const tel = user.tel
? user.tel
: 'Not available';
const aboutMe = `About Me <li> ${user.name} is studying </li> <li> ${user.course_title} and thier enquiry is : </li> <li> ${user.enquiry} </li> `
const currentCourse = user.course_title;
return {
theName,
studentStatus,
id,
enStatus,
completedCourses,
email,
tel,
aboutMe,
currentCourse
}
}).then(({
theName,
studentStatus,
id,
enStatus,
completedCourses,
email,
tel,
aboutMe,
currentCourse
}) => {
//fill in the card
changeCard(theName, 'theName')
changeCard(studentStatus, 'studentStatus')
changeCard(id, 'id')
changeCard(enStatus, 'enStatus')
changeCard(completedCourses, 'completedCourses')
changeCard(email, 'email')
changeCard(tel, 'tel')
changeCard(aboutMe, 'aboutMe')
changeCard(currentCourse, 'currentCourse')
}).then(() => {
const URL = 'https://dog.ceo/api/breeds/image/random/5'
//get the picture details
fetch(URL).then(data => {
return data.json()
}).then(({message, status}) => {
return message
}).then(([profile, mainPic, bannerPic, smallPicOne, smallPicTwo]) => {
//change the pictures
changePhoto(profile, 'iprofile')
changePhoto(mainPic, 'imainPic')
changePhoto(bannerPic, 'ibannerPic')
changePhoto(smallPicOne, 'ismallPicOne')
changePhoto(smallPicTwo, 'ismallPicTwo')
}).then(showCard)
}).then(addEvents)
//function to change the card contents
function changeCard(item, id) {
document
.getElementById(id)
.innerHTML = item;
}
function changePhoto(item, id) {
document
.getElementById(id)
.src = item
}
function showCard() {
document
.querySelector('.cardContainer')
.classList
.remove('hide');
//hide the loading
document
.querySelector('.homepage')
.classList
.add('hide');
}
function addEvents() {
//close button
const close = document.getElementById('closeButton');
const card = document.querySelector('.cardContainer');
const modal = document.querySelector('#showModal');
const galleryButton = document.querySelector('.photoItem');
const gallery = document.querySelector('.photoGrid');
const icon = document.querySelector('#galleryButton');
document.addEventListener('click', function (event) {
if (event.target === close || event.target === modal) {
card
.classList
.toggle('hide');
showModal.classList.toggle('hide');
}
if(event.target === galleryButton || event.target === icon){
gallery.classList.toggle('hide')
icon.classList.toggle('fa-chevron-down') //remove down icon
icon.classList.toggle('fa-chevron-up') //add up icon
}
//slider button change loading text to show show button
})
}