Skip to content

Commit 072c0ff

Browse files
committed
fix
1 parent 5de7cf9 commit 072c0ff

File tree

1 file changed

+76
-74
lines changed

1 file changed

+76
-74
lines changed

assets/js/main.js

Lines changed: 76 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,86 @@
1-
const download = document.querySelector("#download");
1+
document.addEventListener('DOMContentLoaded', function () {
22

3-
// rather than looking for it all the time, you could just create an enum and change this once than updating every line
4-
const github = {
5-
repo: 'https://github.com/lapce/lapce',
6-
version: 'v0.2.1',
7-
windows: 'Lapce-windows.msi',
8-
linux: 'Lapce-linux.tar.gz',
9-
macos: 'Lapce-macos.dmg'
10-
}
3+
// rather than looking for it all the time, you could just create an enum and change this once than updating every line
4+
const github = {
5+
repo: 'https://github.com/lapce/lapce',
6+
version: 'v0.2.1',
7+
windows: 'Lapce-windows.msi',
8+
linux: 'Lapce-linux.tar.gz',
9+
macos: 'Lapce-macos.dmg'
10+
}
1111

12-
// there is no need to check for dom content loaded if you use defer inside html. Defer makes sure the script pauses until the dom loaded
12+
// there is no need to check for dom content loaded if you use defer inside html. Defer makes sure the script pauses until the dom loaded
1313

14-
// open
15-
const burger = document.querySelectorAll('.navbar-burger');
16-
const menu = document.querySelectorAll('.navbar-menu');
14+
// open
15+
const burger = document.querySelectorAll('.navbar-burger');
16+
const menu = document.querySelectorAll('.navbar-menu');
1717

18-
if (burger.length && menu.length) {
19-
for (let i = 0; i < burger.length; i++) {
20-
burger[i].addEventListener('click', () => {
21-
for (let j = 0; j < menu.length; j++) {
22-
menu[j].classList.toggle('hidden');
23-
}
24-
});
25-
}
26-
}
18+
if (burger.length && menu.length) {
19+
for (let i = 0; i < burger.length; i++) {
20+
burger[i].addEventListener('click', () => {
21+
for (let j = 0; j < menu.length; j++) {
22+
menu[j].classList.toggle('hidden');
23+
}
24+
});
25+
}
26+
}
2727

28-
// close
29-
const close = document.querySelectorAll('.navbar-close');
30-
const backdrop = document.querySelectorAll('.navbar-backdrop');
28+
// close
29+
const close = document.querySelectorAll('.navbar-close');
30+
const backdrop = document.querySelectorAll('.navbar-backdrop');
3131

32-
if (close.length) {
33-
for (let i = 0; i < close.length; i++) {
34-
close[i].addEventListener('click', () => {
35-
for (let j = 0; j < menu.length; j++) {
36-
menu[j].classList.toggle('hidden');
37-
}
38-
});
39-
}
40-
}
32+
if (close.length) {
33+
for (let i = 0; i < close.length; i++) {
34+
close[i].addEventListener('click', () => {
35+
for (let j = 0; j < menu.length; j++) {
36+
menu[j].classList.toggle('hidden');
37+
}
38+
});
39+
}
40+
}
4141

42-
if (backdrop.length) {
43-
for (let i = 0; i < backdrop.length; i++) {
44-
backdrop[i].addEventListener('click', () => {
45-
for (let j = 0; j < menu.length; j++) {
46-
menu[j].classList.toggle('hidden');
47-
}
48-
});
49-
}
50-
}
42+
if (backdrop.length) {
43+
for (let i = 0; i < backdrop.length; i++) {
44+
backdrop[i].addEventListener('click', () => {
45+
for (let j = 0; j < menu.length; j++) {
46+
menu[j].classList.toggle('hidden');
47+
}
48+
});
49+
}
50+
}
5151

52-
// to avoid variables being reached outside of scope, ES6 guides recommend the use of let and const for variables. "var" is only available for backwards compatibility
53-
let OSName = "mac";
54-
const navApp = navigator.userAgent.toLowerCase();
52+
// to avoid variables being reached outside of scope, ES6 guides recommend the use of let and const for variables. "var" is only available for backwards compatibility
53+
let OSName = "mac";
54+
const navApp = navigator.userAgent.toLowerCase();
5555

56-
switch (true) {
57-
case (navApp.indexOf("win") != -1):
58-
OSName = "win";
59-
break;
60-
case (navApp.indexOf("mac") != -1):
61-
OSName = "mac";
62-
break;
63-
case (navApp.indexOf("linux") != -1):
64-
OSName = "linux";
65-
break;
66-
case (navApp.indexOf("x11") != -1):
67-
OSName = "linux";
68-
break;
69-
}
56+
switch (true) {
57+
case (navApp.indexOf("win") != -1):
58+
OSName = "win";
59+
break;
60+
case (navApp.indexOf("mac") != -1):
61+
OSName = "mac";
62+
break;
63+
case (navApp.indexOf("linux") != -1):
64+
OSName = "linux";
65+
break;
66+
case (navApp.indexOf("x11") != -1):
67+
OSName = "linux";
68+
break;
69+
}
7070

71-
switch (OSName) {
72-
case "win":
73-
download.innerText = "Download for Windows";
74-
download.setAttribute("href", `${github.repo}/releases/download/${github.version}/${github.windows}`)
75-
break;
76-
case "mac":
77-
download.innerText = "Download for macOS";
78-
download.setAttribute("href", `${github.repo}/releases/download/${github.version}/${github.macos}`)
79-
break;
80-
case "linux":
81-
download.innerText = "Download for Linux";
82-
download.setAttribute("href", `${github.repo}/releases/download/${github.version}/${github.linux}`)
83-
break;
84-
}
71+
const download = document.querySelector("#download");
72+
switch (OSName) {
73+
case "win":
74+
download.innerText = "Download for Windows";
75+
download.setAttribute("href", `${github.repo}/releases/download/${github.version}/${github.windows}`)
76+
break;
77+
case "mac":
78+
download.innerText = "Download for macOS";
79+
download.setAttribute("href", `${github.repo}/releases/download/${github.version}/${github.macos}`)
80+
break;
81+
case "linux":
82+
download.innerText = "Download for Linux";
83+
download.setAttribute("href", `${github.repo}/releases/download/${github.version}/${github.linux}`)
84+
break;
85+
}
86+
});

0 commit comments

Comments
 (0)