forked from Pycord-Development/pycord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom.js
97 lines (80 loc) · 2.3 KB
/
custom.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
'use-strict';
let activeModal = null;
let bottomHeightThreshold, sections;
let hamburgerToggle;
let mobileSearch;
let sidebar;
let toTop;
class Modal {
constructor(element) {
this.element = element;
}
close() {
activeModal = null;
this.element.style.display = 'none'
}
open() {
if (activeModal) {
activeModal.close();
}
activeModal = this;
this.element.style.display = 'flex'
}
}
class SearchBar {
constructor() {
this.box = document.querySelector('nav.mobile-only');
this.bar = document.querySelector('nav.mobile-only input[type="search"]');
this.openButton = document.getElementById('open-search');
this.closeButton = document.getElementById('close-search');
}
open() {
this.openButton.hidden = true;
this.closeButton.hidden = false;
this.box.style.top = "100%";
this.bar.focus();
}
close() {
this.openButton.hidden = false;
this.closeButton.hidden = true;
this.box.style.top = "0";
}
}
function scrollToTop() {
window.scrollTo({ top: 0, behavior: 'smooth' });
}
document.addEventListener('DOMContentLoaded', () => {
mobileSearch = new SearchBar();
bottomHeightThreshold = document.documentElement.scrollHeight - 30;
sections = document.querySelectorAll('section');
hamburgerToggle = document.getElementById('hamburger-toggle');
toTop = document.getElementById('to-top');
toTop.hidden = !(window.scrollY > 0);
if (hamburgerToggle) {
hamburgerToggle.addEventListener('click', (e) => {
sidebar.element.classList.toggle('sidebar-toggle');
let button = hamburgerToggle.firstElementChild;
if (button.textContent == 'menu') {
button.textContent = 'close';
}
else {
button.textContent = 'menu';
}
});
}
const tables = document.querySelectorAll('.py-attribute-table[data-move-to-id]');
tables.forEach(table => {
let element = document.getElementById(table.getAttribute('data-move-to-id'));
let parent = element.parentNode;
// insert ourselves after the element
parent.insertBefore(table, element.nextSibling);
});
window.addEventListener('scroll', () => {
toTop.hidden = !(window.scrollY > 0);
});
});
document.addEventListener('keydown', (event) => {
if (event.code == "Escape" && activeModal) {
activeModal.close();
}
});