From 350caf00225f4a8cf220cb2e37576f0fa401cf21 Mon Sep 17 00:00:00 2001 From: deepjyoti30 Date: Wed, 8 Jul 2020 21:39:51 +0530 Subject: [PATCH] Made some visual changes but need to work on some searches occuring more than once. --- css/main.css | 14 +++++++------- js/autocomplete.js | 20 ++++++++++++-------- scss/main.scss | 11 +++++------ 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/css/main.css b/css/main.css index 58f8df9..30f45e0 100644 --- a/css/main.css +++ b/css/main.css @@ -57,7 +57,10 @@ body { left: 0; right: 0; z-index: 99; - border-radius: 6px; } + border-radius: 6px; + background: #2e2e2e; + box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24); + transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1); } .main #search-bar .autocomplete-items-container .autocomplete-item { width: 100%; background: #2e2e2e; @@ -68,14 +71,11 @@ body { padding: 7px 14px; font-size: 18px; color: #fff; - box-sizing: border-box; - box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24); - transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1); } + box-sizing: border-box; } .main #search-bar .autocomplete-items-container .autocomplete-item:hover { - background-color: red; } + background: #3b3b3b; } .main #search-bar .autocomplete-items-container .autocomplete-active { - background-color: DodgerBlue !important; - color: #ffffff; } + background: #353535; } @media only screen and (max-width: 791px) { .main #search-bar { width: 65%; } } diff --git a/js/autocomplete.js b/js/autocomplete.js index 75ee40f..bb5d366 100644 --- a/js/autocomplete.js +++ b/js/autocomplete.js @@ -3,23 +3,27 @@ function autocomplete(inp, passedValues) { /*execute a function when someone writes in the text field:*/ inp.addEventListener("input", function(e) { - var parentContainer, item, val = this.value; + var item, val = this.value; + var parentContainer = document.getElementsByClassName('autocomplete-items-container')[0]; /*close any already open lists of autocompleted values*/ closeAllLists(); - if (!val) { return false;} + if (!val) { + parentContainer.style.paddingBottom = "0"; + return false; + } currentFocus = -1; - /*create a DIV element that will contain the items (values):*/ - parentContainer = document.getElementsByClassName("autocomplete-items-container")[0]; + // Update some values of the parent container parentContainer.setAttribute("id", this.id + "autocomplete-list"); + parentContainer.style.paddingBottom = "1rem"; /*for each item in the array...*/ Object.keys(passedValues).forEach((el, i, arr) => { /*check if the item starts with the same letters as the text field value:*/ - if (arr[i].substr(0, val.length).toUpperCase() == val.toUpperCase()) { + if (arr[i].toLowerCase().includes(val.toLowerCase())) { /*create a DIV element for each matching element:*/ item = document.createElement("DIV"); item.setAttribute("class", "autocomplete-item"); @@ -95,9 +99,9 @@ function autocomplete(inp, passedValues) { except the one passed as an argument:*/ var x = document.getElementsByClassName("autocomplete-item"); for (var i = 0; i < x.length; i++) { - if (elmnt != x[i] && elmnt != inp) { - x[i].parentNode.removeChild(x[i]); - } + if (elmnt != x[i]) { + x[i].parentNode.removeChild(x[i]); + } } } diff --git a/scss/main.scss b/scss/main.scss index e1c0183..7046525 100644 --- a/scss/main.scss +++ b/scss/main.scss @@ -92,6 +92,9 @@ body { right: 0; z-index: 99; border-radius: 6px; + background: lighten($background, 5); + box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24); + transition: all 0.3s cubic-bezier(.25,.8,.25,1); .autocomplete-item { width: 100%; @@ -105,17 +108,13 @@ body { color: $foreground; box-sizing: border-box; - box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24); - transition: all 0.3s cubic-bezier(.25,.8,.25,1); - &:hover { - background-color: red; + background: lighten($background, 10); } } .autocomplete-active { - background-color: DodgerBlue !important; - color: #ffffff; + background: lighten($background, 8); } }