forked from codeitcodes/codeit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbottomfloat.js
More file actions
146 lines (85 loc) · 2.6 KB
/
Copy pathbottomfloat.js
File metadata and controls
146 lines (85 loc) · 2.6 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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
// function runs in loadFile() in gitsidebar.js
// if isMobile
function updateFloat() {
// close sidebar
toggleSidebar(false);
saveSidebarStateLS();
// show bottom floater
bottomWrapper.classList.remove('hidden');
// if selected file is modified, show flag
if (modifiedFiles[selectedFile.sha] &&
!modifiedFiles[selectedFile.sha].eclipsed) {
bottomFloat.classList.add('modified');
} else {
bottomFloat.classList.remove('modified');
}
// show selected file name
floatLogo.innerText = selectedFile.name;
}
// open sidebar when clicked on button
sidebarOpen.addEventListener('click', () => {
// if bottom float isn't expanded
if (liveView.children.length == 0) {
toggleSidebar(true);
saveSidebarStateLS();
let selectedEl = fileWrapper.querySelector('.item.selected');
if (selectedEl) {
// scroll to selected file
selectedEl.scrollIntoViewIfNeeded();
}
}
})
function playPushAnimation(element) {
const endAnimDuration = 0.18; // s
const checkDelay = 2 - endAnimDuration;
element.classList.add('checked');
window.setTimeout(() => {
element.classList.remove('checked');
}, (checkDelay * 1000));
}
// show push icon in button
pushWrapper.innerHTML = pushIcon;
// push when clicked on button
pushWrapper.addEventListener('click', () => {
// get selected file element
let selectedEl = fileWrapper.querySelector('.file.modified[sha="'+ selectedFile.sha +'"]');
// if selected file element is modified
if (selectedEl) {
// play push animation
playPushAnimation(pushWrapper);
// push file
pushFileFromHTML(selectedEl);
}
})
// if on mobile
if (isMobile) {
cd.on('scroll', checkBottomFloat, false);
}
// show bottom float when scrolled up
let lastScrollTop = 0;
function checkBottomFloat() {
let st = cd.scrollTop;
// if scrolled down
if (st > lastScrollTop) {
// hide bottom float
bottomWrapper.classList.add('hidden');
// if scrolled to bottom of codeit
if ((st + cd.offsetHeight) >= cd.scrollHeight) {
// set timeout
window.setTimeout(() => {
// if still on bottom of codeit
if ((cd.scrollTop + cd.offsetHeight) >= cd.scrollHeight) {
// show bottom float
bottomWrapper.classList.remove('hidden');
}
}, 400);
}
} else { // if scrolled up
// if passed threshold
if ((lastScrollTop - st) > 20) {
// show bottom float
bottomWrapper.classList.remove('hidden');
}
}
lastScrollTop = st <= 0 ? 0 : st; // for mobile or negative scrolling
}