1
0
mirror of https://github.com/cotes2020/jekyll-theme-chirpy.git synced 2025-12-18 05:41:31 +00:00

Adapt the search input to Bootstrap 4.6

This commit is contained in:
Cotes Chung
2022-02-14 00:44:35 +08:00
parent e52dc9551c
commit 35e013f7fd
9 changed files with 17 additions and 55 deletions

View File

@@ -3,12 +3,9 @@
*/
$(function() {
const btnSbTrigger = $("#sidebar-trigger");
const btnSearchTrigger = $("#search-trigger");
const btnCancel = $("#search-cancel");
const btnClear = $("#search-cleaner");
const main = $("#main");
const topbarTitle = $("#topbar-title");
const searchWrapper = $("#search-wrapper");
@@ -33,8 +30,7 @@ $(function() {
};
}());
/*--- Actions in small screens (Sidebar unloaded) ---*/
/*--- Actions in mobile screens (Sidebar hidden) ---*/
const mobileSearchBar = (function () {
return {
@@ -75,7 +71,6 @@ $(function() {
hints.removeClass("unloaded");
}
resultWrapper.addClass("unloaded");
btnClear.removeClass("visible");
main.removeClass("unloaded");
// now the release method must be called after $(#main) display
@@ -92,7 +87,6 @@ $(function() {
}());
function isMobileView() {
return btnCancel.hasClass("loaded");
}
@@ -116,38 +110,20 @@ $(function() {
searchWrapper.removeClass("input-focus");
});
input.on("keyup", function(e) {
if (e.keyCode === 8 && input.val() === "") {
if (!isMobileView()) {
resultSwitch.off();
} else {
input.on("input", () => {
if (input.val() === "") {
if (isMobileView()) {
hints.removeClass("unloaded");
} else {
resultSwitch.off();
}
} else {
if (input.val() !== "") {
resultSwitch.on();
if (!btnClear.hasClass("visible")) {
btnClear.addClass("visible");
}
if (isMobileView()) {
hints.addClass("unloaded");
}
resultSwitch.on();
if (isMobileView()) {
hints.addClass("unloaded");
}
}
});
btnClear.on("click", function() {
input.val("");
if (isMobileView()) {
hints.removeClass("unloaded");
results.empty();
} else {
resultSwitch.off();
}
input.focus();
btnClear.removeClass("visible");
});
});