Merge branch 'master' into search_placeholder

This commit is contained in:
gurusabarish
2023-03-21 07:18:02 +05:30
2 changed files with 27 additions and 16 deletions
+5
View File
@@ -25,6 +25,11 @@
background-color: var(--secondary-color); background-color: var(--secondary-color);
} }
#single .page-content img {
max-width: 100%;
border-radius: 1rem;
}
#single .page-content a { #single .page-content a {
display: inline-block; display: inline-block;
text-decoration: none; text-decoration: none;
+22 -16
View File
@@ -6,7 +6,10 @@ async function searchOnChange(evt) {
}); });
if (searchQuery !== "") { if (searchQuery !== "") {
let searchJson = await fetch("/index.json").then((res) => res.json()); if (!window.searchJson) {
window.searchJson = await fetch("/index.json").then((res) => res.json());
}
let searchResults = searchJson.filter((item) => { let searchResults = searchJson.filter((item) => {
let res = false; let res = false;
if (item.title && item.description && item.content) { if (item.title && item.description && item.content) {
@@ -64,22 +67,25 @@ async function searchOnChange(evt) {
function alignSearchContent() { function alignSearchContent() {
const searchButtonEle = document.querySelectorAll("#search"); const searchButtonEle = document.querySelectorAll("#search");
if (searchButtonEle.value !== "") { // check if search value is not empty
let searchButtonPosition; for (let i = 0; i < searchButtonEle.length; i++) {
if (window.innerWidth > 768) { if (searchButtonEle[i].value !== "") {
searchButtonPosition = searchButtonEle[0].getBoundingClientRect(); let searchButtonPosition;
document.getElementById("search-content").style.width = "500px"; if (window.innerWidth > 768) {
} else { searchButtonPosition = searchButtonEle[0].getBoundingClientRect();
var navbarCollapse = document.querySelector("#navbarContent"); document.getElementById("search-content").style.width = "500px";
navbarCollapse.classList.add("show"); } else {
searchButtonPosition = searchButtonEle[1].getBoundingClientRect(); var navbarCollapse = document.querySelector("#navbarContent");
document.getElementById("search-content").style.width = "300px"; navbarCollapse.classList.add("show");
} searchButtonPosition = searchButtonEle[1].getBoundingClientRect();
document.getElementById("search-content").style.width = "300px";
}
document.getElementById("search-content").style.top = document.getElementById("search-content").style.top =
searchButtonPosition.top + 50 + "px"; searchButtonPosition.top + 50 + "px";
document.getElementById("search-content").style.left = document.getElementById("search-content").style.left =
searchButtonPosition.left + "px"; searchButtonPosition.left + "px";
}
} }
} }