Skip to content

Commit 339293d

Browse files
committed
style: 4 space indents to the JS files
1 parent 1fd665b commit 339293d

21 files changed

+934
-933
lines changed

.editorconfig

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ root = true
22

33
[*]
44
charset = utf-8
5-
# 2 space indentation
65
indent_style = space
76
indent_size = 2
87
trim_trailing_whitespace = true
98
# Unix-style newlines with a newline ending every file
109
end_of_line = lf
1110
insert_final_newline = true
11+
12+
13+
[*.js]
14+
indent_size = 4

_javascript/commons/back-to-top.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
/*
2-
Reference: https://bootsnipp.com/snippets/featured/link-to-top-page
3-
*/
1+
/**
2+
* Reference: https://bootsnipp.com/snippets/featured/link-to-top-page
3+
*/
44
$(function() {
5-
$(window).scroll(() => {
6-
if ($(this).scrollTop() > 50 &&
7-
$("#sidebar-trigger").css("display") === "none") {
8-
$("#back-to-top").fadeIn();
9-
} else {
10-
$("#back-to-top").fadeOut();
11-
}
12-
});
5+
$(window).scroll(() => {
6+
if ($(this).scrollTop() > 50 &&
7+
$("#sidebar-trigger").css("display") === "none") {
8+
$("#back-to-top").fadeIn();
9+
} else {
10+
$("#back-to-top").fadeOut();
11+
}
12+
});
1313

14-
$("#back-to-top").click(() => {
15-
$("body,html").animate({
16-
scrollTop: 0
17-
}, 800);
18-
return false;
19-
});
14+
$("#back-to-top").click(() => {
15+
$("body,html").animate({
16+
scrollTop: 0
17+
}, 800);
18+
return false;
19+
});
2020
});

_javascript/commons/mode-toggle.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
/*
1+
/**
22
* Listener for theme mode toggle
33
*/
4-
$(function() {
5-
$(".mode-toggle").click((e) => {
6-
const $target = $(e.target);
7-
let $btn = ($target.prop("tagName") === "button".toUpperCase() ?
8-
$target : $target.parent());
4+
$(function () {
5+
$(".mode-toggle").click((e) => {
6+
const $target = $(e.target);
7+
let $btn = ($target.prop("tagName") === "button".toUpperCase() ?
8+
$target : $target.parent());
99

10-
$btn.blur(); // remove the clicking outline
11-
flipMode();
12-
});
10+
$btn.blur(); // remove the clicking outline
11+
flipMode();
12+
});
1313
});

_javascript/commons/scroll-helper.js

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,37 @@
22
* A tool for smooth scrolling and topbar switcher
33
*/
44
const ScrollHelper = (function () {
5-
const $body = $("body");
6-
const ATTR_TOPBAR_VISIBLE = "data-topbar-visible";
7-
const topbarHeight = $("#topbar-wrapper").outerHeight();
5+
const $body = $("body");
6+
const ATTR_TOPBAR_VISIBLE = "data-topbar-visible";
7+
const topbarHeight = $("#topbar-wrapper").outerHeight();
88

9-
let scrollUpCount = 0; // the number of times the scroll up was triggered by ToC or anchor
10-
let topbarLocked = false;
11-
let orientationLocked = false;
9+
let scrollUpCount = 0; // the number of times the scroll up was triggered by ToC or anchor
10+
let topbarLocked = false;
11+
let orientationLocked = false;
1212

13-
return {
14-
hideTopbar: () => $body.attr(ATTR_TOPBAR_VISIBLE, false),
15-
showTopbar: () => $body.attr(ATTR_TOPBAR_VISIBLE, true),
13+
return {
14+
hideTopbar: () => $body.attr(ATTR_TOPBAR_VISIBLE, false),
15+
showTopbar: () => $body.attr(ATTR_TOPBAR_VISIBLE, true),
1616

17-
// scroll up
17+
// scroll up
1818

19-
addScrollUpTask: () => {
20-
scrollUpCount += 1;
21-
if (!topbarLocked) { topbarLocked = true; }
22-
},
23-
popScrollUpTask: () => scrollUpCount -= 1,
24-
hasScrollUpTask: () => scrollUpCount > 0,
25-
topbarLocked: () => topbarLocked === true,
26-
unlockTopbar: () => topbarLocked = false,
27-
getTopbarHeight: () => topbarHeight,
19+
addScrollUpTask: () => {
20+
scrollUpCount += 1;
21+
if (!topbarLocked) {
22+
topbarLocked = true;
23+
}
24+
},
25+
popScrollUpTask: () => scrollUpCount -= 1,
26+
hasScrollUpTask: () => scrollUpCount > 0,
27+
topbarLocked: () => topbarLocked === true,
28+
unlockTopbar: () => topbarLocked = false,
29+
getTopbarHeight: () => topbarHeight,
2830

29-
// orientation change
31+
// orientation change
3032

31-
orientationLocked: () => orientationLocked === true,
32-
lockOrientation: () => orientationLocked = true,
33-
unLockOrientation: () => orientationLocked = false
34-
};
33+
orientationLocked: () => orientationLocked === true,
34+
lockOrientation: () => orientationLocked = true,
35+
unLockOrientation: () => orientationLocked = false
36+
};
3537

3638
}());
Lines changed: 126 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -1,129 +1,129 @@
1-
/*
2-
* This script make #search-result-wrapper switch to unloaded or shown automatically.
3-
*/
4-
5-
$(function() {
6-
const btnSbTrigger = $("#sidebar-trigger");
7-
const btnSearchTrigger = $("#search-trigger");
8-
const btnCancel = $("#search-cancel");
9-
const main = $("#main");
10-
const topbarTitle = $("#topbar-title");
11-
const searchWrapper = $("#search-wrapper");
12-
const resultWrapper = $("#search-result-wrapper");
13-
const results = $("#search-results");
14-
const input = $("#search-input");
15-
const hints = $("#search-hints");
16-
17-
const scrollBlocker = (function () {
18-
let offset = 0;
19-
return {
20-
block() {
21-
offset = window.scrollY;
22-
$("html,body").scrollTop(0);
23-
},
24-
release() {
25-
$("html,body").scrollTop(offset);
26-
},
27-
getOffset() {
28-
return offset;
29-
}
30-
};
31-
}());
32-
33-
/*--- Actions in mobile screens (Sidebar hidden) ---*/
34-
35-
const mobileSearchBar = (function () {
36-
return {
37-
on() {
38-
btnSbTrigger.addClass("unloaded");
39-
topbarTitle.addClass("unloaded");
40-
btnSearchTrigger.addClass("unloaded");
41-
searchWrapper.addClass("d-flex");
42-
btnCancel.addClass("loaded");
43-
},
44-
off() {
45-
btnCancel.removeClass("loaded");
46-
searchWrapper.removeClass("d-flex");
47-
btnSbTrigger.removeClass("unloaded");
48-
topbarTitle.removeClass("unloaded");
49-
btnSearchTrigger.removeClass("unloaded");
50-
}
51-
};
52-
}());
53-
54-
const resultSwitch = (function () {
55-
let visible = false;
56-
57-
return {
58-
on() {
59-
if (!visible) {
60-
// the block method must be called before $(#main) unloaded.
61-
scrollBlocker.block();
62-
resultWrapper.removeClass("unloaded");
63-
main.addClass("unloaded");
64-
visible = true;
65-
}
66-
},
67-
off() {
68-
if (visible) {
69-
results.empty();
70-
if (hints.hasClass("unloaded")) {
71-
hints.removeClass("unloaded");
72-
}
73-
resultWrapper.addClass("unloaded");
74-
main.removeClass("unloaded");
75-
76-
// now the release method must be called after $(#main) display
77-
scrollBlocker.release();
78-
79-
input.val("");
80-
visible = false;
81-
}
82-
},
83-
isVisible() {
84-
return visible;
85-
}
86-
};
87-
88-
}());
89-
90-
function isMobileView() {
91-
return btnCancel.hasClass("loaded");
92-
}
93-
94-
btnSearchTrigger.click(function() {
95-
mobileSearchBar.on();
96-
resultSwitch.on();
97-
input.focus();
98-
});
99-
100-
btnCancel.click(function() {
101-
mobileSearchBar.off();
102-
resultSwitch.off();
103-
});
104-
105-
input.focus(function() {
106-
searchWrapper.addClass("input-focus");
107-
});
108-
109-
input.focusout(function() {
110-
searchWrapper.removeClass("input-focus");
111-
});
112-
113-
input.on("input", () => {
114-
if (input.val() === "") {
115-
if (isMobileView()) {
116-
hints.removeClass("unloaded");
117-
} else {
118-
resultSwitch.off();
119-
}
120-
121-
} else {
122-
resultSwitch.on();
123-
if (isMobileView()) {
124-
hints.addClass("unloaded");
125-
}
1+
/**
2+
* This script make #search-result-wrapper switch to unloaded or shown automatically.
3+
*/
4+
5+
$(function () {
6+
const btnSbTrigger = $("#sidebar-trigger");
7+
const btnSearchTrigger = $("#search-trigger");
8+
const btnCancel = $("#search-cancel");
9+
const main = $("#main");
10+
const topbarTitle = $("#topbar-title");
11+
const searchWrapper = $("#search-wrapper");
12+
const resultWrapper = $("#search-result-wrapper");
13+
const results = $("#search-results");
14+
const input = $("#search-input");
15+
const hints = $("#search-hints");
16+
17+
const scrollBlocker = (function () {
18+
let offset = 0;
19+
return {
20+
block() {
21+
offset = window.scrollY;
22+
$("html,body").scrollTop(0);
23+
},
24+
release() {
25+
$("html,body").scrollTop(offset);
26+
},
27+
getOffset() {
28+
return offset;
29+
}
30+
};
31+
}());
32+
33+
/*--- Actions in mobile screens (Sidebar hidden) ---*/
34+
35+
const mobileSearchBar = (function () {
36+
return {
37+
on() {
38+
btnSbTrigger.addClass("unloaded");
39+
topbarTitle.addClass("unloaded");
40+
btnSearchTrigger.addClass("unloaded");
41+
searchWrapper.addClass("d-flex");
42+
btnCancel.addClass("loaded");
43+
},
44+
off() {
45+
btnCancel.removeClass("loaded");
46+
searchWrapper.removeClass("d-flex");
47+
btnSbTrigger.removeClass("unloaded");
48+
topbarTitle.removeClass("unloaded");
49+
btnSearchTrigger.removeClass("unloaded");
50+
}
51+
};
52+
}());
53+
54+
const resultSwitch = (function () {
55+
let visible = false;
56+
57+
return {
58+
on() {
59+
if (!visible) {
60+
// the block method must be called before $(#main) unloaded.
61+
scrollBlocker.block();
62+
resultWrapper.removeClass("unloaded");
63+
main.addClass("unloaded");
64+
visible = true;
65+
}
66+
},
67+
off() {
68+
if (visible) {
69+
results.empty();
70+
if (hints.hasClass("unloaded")) {
71+
hints.removeClass("unloaded");
72+
}
73+
resultWrapper.addClass("unloaded");
74+
main.removeClass("unloaded");
75+
76+
// now the release method must be called after $(#main) display
77+
scrollBlocker.release();
78+
79+
input.val("");
80+
visible = false;
81+
}
82+
},
83+
isVisible() {
84+
return visible;
85+
}
86+
};
87+
88+
}());
89+
90+
function isMobileView() {
91+
return btnCancel.hasClass("loaded");
12692
}
127-
});
93+
94+
btnSearchTrigger.click(function () {
95+
mobileSearchBar.on();
96+
resultSwitch.on();
97+
input.focus();
98+
});
99+
100+
btnCancel.click(function () {
101+
mobileSearchBar.off();
102+
resultSwitch.off();
103+
});
104+
105+
input.focus(function () {
106+
searchWrapper.addClass("input-focus");
107+
});
108+
109+
input.focusout(function () {
110+
searchWrapper.removeClass("input-focus");
111+
});
112+
113+
input.on("input", () => {
114+
if (input.val() === "") {
115+
if (isMobileView()) {
116+
hints.removeClass("unloaded");
117+
} else {
118+
resultSwitch.off();
119+
}
120+
121+
} else {
122+
resultSwitch.on();
123+
if (isMobileView()) {
124+
hints.addClass("unloaded");
125+
}
126+
}
127+
});
128128

129129
});

0 commit comments

Comments
 (0)