add search to the navbar using 'post_search' config param

This commit is contained in:
Dean Attali 2021-05-30 19:54:17 +00:00
parent 99fdbbd593
commit 950c341739
7 changed files with 172 additions and 2 deletions

View file

@ -993,3 +993,98 @@ pre {
display: block;
margin: 0 auto;
}
/* Search bar */
#beautifuljekyll-search-overlay {
display: none;
z-index: 999999;
position: fixed;
background: rgba(0,0,0,0.9);
left: 0;
right: 0;
top: 0;
bottom: 0;
text-align: center;
padding: 1rem;
}
#nav-search-exit {
position: absolute;
top: 1.5rem;
cursor: pointer;
right: 25%;
margin-right: 2rem;
color: #555;
font-size: 2rem;
line-height: 2rem;
font-weight: bold;
}
#nav-search-exit:hover {
color: #000;
}
#nav-search-input {
text-align: center;
background: #e7edee;
margin: auto;
display: block;
font-size: 2rem;
width: 50%;
transition: width 300ms ease;
color: #222;
border-radius: 5rem;
outline: none;
border: none;
padding: 0 3rem;
}
@media (max-width: 1199px) {
#nav-search-input {
width: 75%;
}
#nav-search-exit {
right: 12.5%;
}
}
@media (max-width: 767px) {
#nav-search-input {
width: 100%;
}
#nav-search-exit {
right: 0;
}
}
#nav-search-input:focus {
background: #f3f8fe;
box-shadow: 0px 0.15rem 1rem #e7f4ff;
outline: none;
}
#nav-search-input::placeholder {
color: #777;
}
#search-results-container {
list-style: none;
padding-left: unset;
margin-top: 1.5rem;
color: #fff;
font-size: 1.5rem;
}
#search-results-container a,
#search-results-container a:hover {
color: #fff;
}
#nav-search-icon {
display: inline-block;
}
#nav-search-text {
display: none;
}
@media (max-width: 1199px) {
#nav-search-icon {
display: none;
}
#nav-search-text {
display: inline-block;
}
}

View file

@ -27,6 +27,8 @@ var BeautifulJekyllJS = {
// show the big header image
BeautifulJekyllJS.initImgs();
BeautifulJekyllJS.initSearch();
},
initNavbar : function() {
@ -108,6 +110,25 @@ var BeautifulJekyllJS = {
} else {
$(".img-desc").hide();
}
},
initSearch : function() {
if (!document.getElementById("beautifuljekyll-search-overlay")) {
return;
}
$("#nav-search-link").click(function(e) {
e.preventDefault();
$("#beautifuljekyll-search-overlay").show();
$("#nav-search-input").focus().select();
});
$("#nav-search-exit").click(function(e) {
e.preventDefault();
$("#beautifuljekyll-search-overlay").hide();
});
$(document).on('keyup', function(e) {
if (e.key == "Escape") $("#beautifuljekyll-search-overlay").hide();
});
}
};