-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
42 lines (32 loc) · 1.19 KB
/
main.js
File metadata and controls
42 lines (32 loc) · 1.19 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
const liveServer = 'https://api.flashstudy.org/v1';
const localServer = 'http://localhost:5001/v1';
const activeServer = location.host.startsWith('localhost') || location.host.startsWith('127.0.0.1') ? localServer : liveServer;
function fetcher(endpoint, options) {
let updatedOptions = { ...options };
updatedOptions.headers = {
...options ? options.headers : null,
}
// allow set cookie headers and such
updatedOptions.credentials = 'include';
return fetch(`${activeServer}${endpoint}`, updatedOptions).catch(err => { alert('Connection error') });
}
async function logout() {
await fetcher('/auth/logout')
//reload page
location.assign('/');
}
// dropdown in header
function dropdown() {
document.getElementById("dropdown").classList.toggle("show");
}
window.onclick = (event) => {
if (!event.target.matches('#new')) {
let dropdowns = document.getElementsByClassName("dropdown-content");
for (let i = 0; i < dropdowns.length; i++) {
let openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}