-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsearch.js
89 lines (72 loc) · 2.18 KB
/
search.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
/* This script make #search-result-wrapper switch to unloaded or shown automatically. */
$(function() {
const btnSbTrigger = $("#sidebar-trigger");
const btnSearchTrigger = $("#search-trigger");
const btnCancel = $("#search-cancel");
const btnClear = $("#search-cleaner");
const topbarTitle = $("#topbar-title");
const searchWrapper = $("#search-wrapper");
const input = $("#search-input");
const hints = $("#search-hints");
/*--- Actions in small screens (Sidebar unloaded) ---*/
const mobileSearchBar = (function () {
return {
on() {
btnSbTrigger.addClass("unloaded");
topbarTitle.addClass("unloaded");
btnSearchTrigger.addClass("unloaded");
searchWrapper.addClass("d-flex");
btnCancel.addClass("loaded");
},
off() {
btnCancel.removeClass("loaded");
searchWrapper.removeClass("d-flex");
btnSbTrigger.removeClass("unloaded");
topbarTitle.removeClass("unloaded");
btnSearchTrigger.removeClass("unloaded");
}
};
}());
function isMobileView() {
return btnCancel.hasClass("loaded");
}
btnSearchTrigger.click(function() {
mobileSearchBar.on();
input.focus();
});
btnCancel.click(function() {
mobileSearchBar.off();
});
input.focus(function() {
searchWrapper.addClass("input-focus");
});
input.focusout(function() {
searchWrapper.removeClass("input-focus");
});
input.on("keyup", function(e) {
if (e.keyCode === 8 && input.val() === "") {
if (!isMobileView()) {
} else {
hints.removeClass("unloaded");
}
} else {
if (input.val() !== "") {
if (!btnClear.hasClass("visible")) {
btnClear.addClass("visible");
}
if (isMobileView()) {
hints.addClass("unloaded");
}
}
}
});
btnClear.on("click", function() {
input.val("");
if (isMobileView()) {
hints.removeClass("unloaded");
} else {
}
input.focus();
btnClear.removeClass("visible");
});
});