aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Kabui2023-03-08 09:17:03 +0300
committerGitHub2023-03-08 09:17:03 +0300
commited1824fe735b200f3eb864c657f0b1f7cbe999a9 (patch)
treebc0e8d4dc49495dc4b93741e1cc1ab2fd13fc15b
parent6c5d0d8a1e981063b02bb9a7aab63190858ed348 (diff)
parent23da4fa4123aa329084b48942946f93f939f01f9 (diff)
downloadgenenetwork2-ed1824fe735b200f3eb864c657f0b1f7cbe999a9.tar.gz
Merge pull request #770 from genenetwork/feature/search-history
Feature/autocomplete global search
-rw-r--r--wqflask/wqflask/static/new/css/autocomplete.css80
-rw-r--r--wqflask/wqflask/static/new/javascript/search_autocomplete.js154
-rwxr-xr-xwqflask/wqflask/templates/index_page.html56
-rw-r--r--wqflask/wqflask/templates/search_autocomplete.html249
-rw-r--r--wqflask/wqflask/templates/search_history.html297
5 files changed, 832 insertions, 4 deletions
diff --git a/wqflask/wqflask/static/new/css/autocomplete.css b/wqflask/wqflask/static/new/css/autocomplete.css
new file mode 100644
index 00000000..aba68e37
--- /dev/null
+++ b/wqflask/wqflask/static/new/css/autocomplete.css
@@ -0,0 +1,80 @@
+.autocomplete {
+ /*the container must be positioned relative:*/
+ position: relative;
+ display: inline-block;
+}
+
+input.autocomplete {
+ border: 1px solid transparent;
+ background-color: #f1f1f1;
+ padding: 10px;
+ font-size: 16px;
+}
+
+input[type=text].autocomplete {
+ background-color: #f1f1f1;
+ width: 100%;
+}
+
+input[type=submit].autocomplete {
+ background-color: DodgerBlue;
+ color: #fff;
+}
+
+
+.autocomplete-items {
+ position: absolute;
+ border: 1px solid #d4d4d4;
+ border-bottom: none;
+ border-top: none;
+ z-index: 99;
+ /*position the autocomplete items to be the same width as the container:*/
+ top: 100%;
+ left: 0;
+ right: 0;
+}
+
+.autocomplete-items div {
+ padding: 10px;
+ cursor: pointer;
+ background-color: #fff;
+ border-bottom: 1px solid #d4d4d4;
+}
+
+.autocomplete-items div:hover {
+ /*when hovering an item:*/
+ background-color: #e9e9e9;
+}
+
+.autocomplete-active {
+ /*when navigating through the items using the arrow keys:*/
+ background-color: DodgerBlue !important;
+ color: #ffffff;
+}
+
+.recent-search-title {
+ display: -webkit-box;
+ display: -moz-box;
+ display: -ms-flexbox;
+ display: -webkit-flex;
+ display: flex;
+}
+
+.recent-search-title * {
+ -webkit-box-flex: 1 1 auto;
+ -moz-box-flex: 1 1 auto;
+ -webkit-flex: 1 1 auto;
+ -ms-flex: 1 1 auto;
+ flex: 1 1 auto;
+}
+
+
+.recent-search-title input[type="button"] {
+ border: none;
+ background: none;
+ cursor: pointer;
+ margin: 0;
+ padding: 0;
+ color: blue;
+
+} \ No newline at end of file
diff --git a/wqflask/wqflask/static/new/javascript/search_autocomplete.js b/wqflask/wqflask/static/new/javascript/search_autocomplete.js
new file mode 100644
index 00000000..04634f9b
--- /dev/null
+++ b/wqflask/wqflask/static/new/javascript/search_autocomplete.js
@@ -0,0 +1,154 @@
+ //replace with gn search hints
+ function autocomplete(inp, arr) {
+ /*the autocomplete function takes two arguments,
+ the text field element and an array of possible autocompleted values:*/
+ var currentFocus;
+ /*execute a function when someone writes in the text field:*/
+
+ inp.addEventListener("focus", function(e) {
+ var a, b, i, val = this.value;
+ closeAllLists();
+ currentFocus = -1;
+ a = document.createElement("DIV");
+ a.setAttribute("id", this.id + "autocomplete-list");
+ a.setAttribute("class", "autocomplete-items");
+ this.parentNode.appendChild(a);
+ let historySearch = retrieveSearchHistory().splice(0, 5)
+ let text_title = document.createElement("DIV")
+ text_title.innerHTML = "<strong>RECENT SEARCH</strong><input type='button' value='close_all'>";
+ text_title.setAttribute("class", "recent-search-title")
+ text_title.setAttribute('disabled', true);
+ a.appendChild(text_title);
+ for (i = 0; i < historySearch.length; i++) {
+ b = document.createElement("DIV");
+ b.innerHTML = "<span>" + historySearch[i].substr(0, val.length) + "</span>";
+ b.style.color = "blue";
+ b.innerHTML += historySearch[i].substr(val.length);
+ b.innerHTML += "<input type='hidden' value='" + historySearch[i] + "'>";
+ b.addEventListener("click", function(e) {
+ inp.value = this.getElementsByTagName("input")[0].value;
+ closeAllLists();
+ });
+ a.appendChild(b);
+
+ }
+ });
+
+
+
+ inp.addEventListener("input", function(e) {
+ var a, b, i, val = this.value;
+ /*close any already open lists of autocompleted values*/
+ closeAllLists();
+ if (!val) { return false; }
+ currentFocus = -1;
+ /*create a DIV element that will contain the items (values):*/
+ a = document.createElement("DIV");
+ a.setAttribute("id", this.id + "autocomplete-list");
+ a.setAttribute("class", "autocomplete-items");
+ /*append the DIV element as a child of the autocomplete container:*/
+ this.parentNode.appendChild(a);
+ /*for each item in the array...*/
+ for (i = 0; i < arr.length; i++) {
+ /*check if the item starts with the same letters as the text field value:*/
+ if (arr[i].substr(0, val.length).toUpperCase() == val.toUpperCase()) {
+ /*create a DIV element for each matching element:*/
+ b = document.createElement("DIV");
+ /*make the matching letters bold:*/
+ b.innerHTML = "<strong>" + arr[i].substr(0, val.length) + "</strong>";
+ b.innerHTML += arr[i].substr(val.length);
+ /*insert a input field that will hold the current array item's value:*/
+ b.innerHTML += "<input type='hidden' value='" + arr[i] + "'>";
+ /*execute a function when someone clicks on the item value (DIV element):*/
+ b.addEventListener("click", function(e) {
+ /*insert the value for the autocomplete text field:*/
+ inp.value = this.getElementsByTagName("input")[0].value;
+ /*close the list of autocompleted values,
+ (or any other open lists of autocompleted values:*/
+ closeAllLists();
+ });
+ a.appendChild(b);
+ }
+ }
+ });
+ /*execute a function presses a key on the keyboard:*/
+ inp.addEventListener("keydown", function(e) {
+ var x = document.getElementById(this.id + "autocomplete-list");
+ if (x) x = x.getElementsByTagName("div");
+ if (e.keyCode == 40) {
+ /*If the arrow DOWN key is pressed,
+ increase the currentFocus variable:*/
+ currentFocus++;
+ /*and and make the current item more visible:*/
+ addActive(x);
+ } else if (e.keyCode == 38) { //up
+ /*If the arrow UP key is pressed,
+ decrease the currentFocus variable:*/
+ currentFocus--;
+ /*and and make the current item more visible:*/
+ addActive(x);
+ } else if (e.keyCode == 13) {
+ /*If the ENTER key is pressed, prevent the form from being submitted,*/
+ e.preventDefault();
+ if (currentFocus > -1) {
+ /*and simulate a click on the "active" item:*/
+ if (x) x[currentFocus].click();
+ }
+ }
+ });
+
+ function addActive(x) {
+ /*a function to classify an item as "active":*/
+ if (!x) return false;
+ /*start by removing the "active" class on all items:*/
+ removeActive(x);
+ if (currentFocus >= x.length) currentFocus = 0;
+ if (currentFocus < 0) currentFocus = (x.length - 1);
+ /*add class "autocomplete-active":*/
+ x[currentFocus].classList.add("autocomplete-active");
+ }
+
+ function removeActive(x) {
+ /*a function to remove the "active" class from all autocomplete items:*/
+ for (var i = 0; i < x.length; i++) {
+ x[i].classList.remove("autocomplete-active");
+ }
+ }
+
+ function closeAllLists(elmnt) {
+ /*close all autocomplete lists in the document,
+ except the one passed as an argument:*/
+ var x = document.getElementsByClassName("autocomplete-items");
+ for (var i = 0; i < x.length; i++) {
+ if (elmnt != x[i] && elmnt != inp) {
+ x[i].parentNode.removeChild(x[i]);
+ }
+ }
+ }
+
+
+
+ /*execute a function when someone clicks in the document:*/
+ document.addEventListener("click", function(e) {
+ closeAllLists(e.target);
+ })
+
+ }
+
+ function retrieveSearchHistory() {
+ let results = JSON.parse(localStorage.getItem("gn_search_history"))
+ return results ? results : []
+ }
+
+
+
+
+
+ function saveBeforeSubmit(new_search) {
+
+ let search = retrieveSearchHistory()
+ search.unshift(new_search)
+
+ localStorage.setItem("gn_search_history", JSON.stringify([...new Set(search)].splice(0,8)))
+
+ } \ No newline at end of file
diff --git a/wqflask/wqflask/templates/index_page.html b/wqflask/wqflask/templates/index_page.html
index 09f24d5a..0e120d69 100755
--- a/wqflask/wqflask/templates/index_page.html
+++ b/wqflask/wqflask/templates/index_page.html
@@ -4,6 +4,7 @@
<!-- UIkit CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/uikit@3.7.4/dist/css/uikit.min.css" />
<link rel="stylesheet" href="/static/new/css/index_page.css" />
+<link rel="stylesheet" href="/static/new/css/autocomplete.css"/>
<!-- UIkit JS -->
<script src="https://cdn.jsdelivr.net/npm/uikit@3.7.4/dist/js/uikit.min.js"></script>
@@ -62,7 +63,7 @@
<div class="page-header">
<h2>Select and Search</h2>
</div>
- <form method="get" action="/search" target="_blank" name="SEARCHFORM",
+ <form method="get" action="/search" target="_blank" id="searchform" name="SEARCHFORM",
data-gn_server_url="{{gn_server_url}}">
<fieldset>
<div style="padding-left: 20px; padding-right: 20px;" class="form-horizontal">
@@ -115,8 +116,8 @@
<div class="form-group">
<label for="or_search" class="col-xs-1 control-label" style="padding-left: 0px; padding-right: 0px; width: 65px !important;">Get Any:</label>
<div class="col-xs-10 controls" style="padding-left: 20px;">
- <div class="col-8">
- <textarea onkeydown="pressed(event)" name="search_terms_or" rows="1" class="form-control search-query" style="resize: vertical; max-width: 550px; width: 450px !important;" id="or_search"></textarea>
+ <div class="col-8 autocomplete">
+ <textarea id="myInput" onkeydown="pressed(event)" name="search_terms_or" rows="1" class="form-control search-query" style="resize: vertical; max-width: 550px; width: 450px !important;" id="or_search"></textarea>
</div>
</div>
</div>
@@ -291,8 +292,30 @@
{%endblock%}
{% block js %}
+
+
+ <script src="/static/new/javascript/search_autocomplete.js"></script>
<script src="/static/new/javascript/dataset_select_menu_orig.js"></script>
+
+ <script type="text/javascript">
+
+
+ let form = document.getElementById("searchform")
+
+
+$(document).on('submit', '#searchform', function(event){
+
+ event.preventDefault()
+ let user_search = $("#myInput").val().trim();
+ if (user_search!=""){
+ saveBeforeSubmit(user_search)
+ $( "#searchform" )[0].submit();
+ }
+
+ });
+ </script>
+
<script>
function pressed(e) {
// Has the enter key been pressed?
@@ -300,11 +323,37 @@
e.preventDefault();
// If enter key has been pressed and the search fields are non-empty
// manually submit the <form>
+
if( event.target.value.trim() != "" ) {
+ saveBeforeSubmit(event.target.value.trim())
document.forms[1].submit();
}
}
}
+
+ let x = document.getElementById("myInput");
+
+ var hints = [
+ "cytochrome",
+ "cytochrome AND P450",
+ "cytochrome NEAR P450",
+ "cytochrome -P450",
+ "cytochrome NOT P450",
+ "species:human",
+ "group:BXD",
+ "Hs:chr4:9930021 species:mouse",
+ "Hs:chr4:9130000..9980000 species:mouse",
+ "mean:5..7",
+ "mean:7..",
+ "Hs:chr4:9930021",
+ "Hs:chr4:9930021 species:mouse",
+ "Hs:chr4:9130000..9980000 species:mouse",
+ "bx*",
+ "*",
+ ]
+
+ autocomplete(document.getElementById("myInput"), hints);
+
</script>
<script language="javascript" type="text/javascript" src="{{ url_for('js', filename='javascript-twitter-post-fetcher/js/twitterFetcher_min.js') }}"></script>
@@ -323,5 +372,4 @@
twitterFetcher.fetch(configProfile);
</script>
-
{% endblock %}
diff --git a/wqflask/wqflask/templates/search_autocomplete.html b/wqflask/wqflask/templates/search_autocomplete.html
new file mode 100644
index 00000000..b8d0514e
--- /dev/null
+++ b/wqflask/wqflask/templates/search_autocomplete.html
@@ -0,0 +1,249 @@
+<<!DOCTYPE html>
+ <html>
+
+ <head>
+ <meta charset="utf-8">
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
+ <title></title>
+ <link rel="stylesheet" href="">
+ </head>
+ <style type="text/css">
+ * {
+ box-sizing: border-box;
+ }
+
+ body {
+ font: 16px Arial;
+ }
+
+ .autocomplete {
+ /*the container must be positioned relative:*/
+ position: relative;
+ display: inline-block;
+ }
+
+ input {
+ border: 1px solid transparent;
+ background-color: #f1f1f1;
+ padding: 10px;
+ font-size: 16px;
+ }
+
+ input[type=text] {
+ background-color: #f1f1f1;
+ width: 100%;
+ }
+
+ input[type=submit] {
+ background-color: DodgerBlue;
+ color: #fff;
+ }
+
+
+ .search-item,
+ .autocomplete-items {
+ position: absolute;
+ border: 1px solid #d4d4d4;
+ border-bottom: none;
+ border-top: none;
+ z-index: 99;
+ /*position the autocomplete items to be the same width as the container:*/
+ top: 100%;
+ left: 0;
+ right: 0;
+ }
+
+
+ .search-item div {
+
+ background-color: red;
+
+ }
+
+ .autocomplete-items div {
+ padding: 10px;
+ cursor: pointer;
+ background-color: #fff;
+ border-bottom: 1px solid #d4d4d4;
+ }
+
+ .autocomplete-items div:hover {
+ /*when hovering an item:*/
+ background-color: #e9e9e9;
+ }
+
+ .autocomplete-active {
+ /*when navigating through the items using the arrow keys:*/
+ background-color: DodgerBlue !important;
+ color: #ffffff;
+ }
+ </style>
+
+ <body>
+ <div>
+ <h2>hello there</h2>
+ <form autocomplete="off" action="/action_page.php">
+ <div class="autocomplete" style="width:300px;">
+ <input id="myInput" type="text" name="myCountry" placeholder="search for a country">
+ </div>
+ <input type="submit">
+ </form>
+ </div>
+ <script type="text/javascript">
+ //replace with gn search hints
+ var trial_hints = ["Afghanistan", "Albania", "Algeria", "Andorra", "Angola", "Anguilla", "Antigua &amp; Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnia &amp; Herzegovina", "Botswana", "Brazil", "British Virgin Islands", "Brunei", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia", "Cameroon", "Canada", "Cape Verde", "Cayman Islands", "Central Arfrican Republic", "Chad", "Chile", "China", "Colombia", "Congo", "Cook Islands", "Costa Rica", "Cote D Ivoire", "Croatia", "Cuba", "Curacao", "Cyprus", "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Falkland Islands", "Faroe Islands", "Fiji", "Finland", "France", "French Polynesia", "French West Indies", "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada", "Guam", "Guatemala", "Guernsey"]
+
+
+ let x = document.getElementById("myInput");
+
+ x.addEventListener("focus", function() {
+
+ //recentSearches(searches)
+ });
+
+
+ function recentSearches(arr) {
+
+ console.log("calling this funciton")
+
+ let x = document.getElementById("myInput");
+
+ x.addEventListener("focus", function(e) {
+
+
+ a = document.createElement("DIV")
+
+ a.setAttribute("id", "searchitem_x");
+
+ a.setAttribute("class", "autocomplete-items");
+
+
+
+ this.parentNode.appendChild(a)
+
+ for (i = 0; i < arr.length; i++) {
+
+ console.log(arr[i])
+ b = document.createElement("DIV")
+ b.innerHTML = "<strong>" + arr[i] + "</strong>";
+ b.innerHTML += "<input type='hidden' value='" + arr[i] + "'>";
+
+ b.addEventListener("click", function(e) {
+ x.value = b.innerHTML += "<input type='hidden' value='" + arr[i] + "'>";
+
+ })
+
+ a.appendChild(b)
+
+
+
+
+ }
+ })
+ }
+
+ function autocomplete(inp, arr) {
+ /*the autocomplete function takes two arguments,
+ the text field element and an array of possible autocompleted values:*/
+ var currentFocus;
+ /*execute a function when someone writes in the text field:*/
+ inp.addEventListener("input", function(e) {
+ var a, b, i, val = this.value;
+ /*close any already open lists of autocompleted values*/
+ closeAllLists();
+ if (!val) { return false; }
+ currentFocus = -1;
+ /*create a DIV element that will contain the items (values):*/
+ a = document.createElement("DIV");
+ a.setAttribute("id", this.id + "autocomplete-list");
+ a.setAttribute("class", "autocomplete-items");
+ /*append the DIV element as a child of the autocomplete container:*/
+ this.parentNode.appendChild(a);
+ /*for each item in the array...*/
+ for (i = 0; i < arr.length; i++) {
+ /*check if the item starts with the same letters as the text field value:*/
+ if (arr[i].substr(0, val.length).toUpperCase() == val.toUpperCase()) {
+ /*create a DIV element for each matching element:*/
+ b = document.createElement("DIV");
+ /*make the matching letters bold:*/
+ b.innerHTML = "<strong>" + arr[i].substr(0, val.length) + "</strong>";
+ b.innerHTML += arr[i].substr(val.length);
+ /*insert a input field that will hold the current array item's value:*/
+ b.innerHTML += "<input type='hidden' value='" + arr[i] + "'>";
+ /*execute a function when someone clicks on the item value (DIV element):*/
+ b.addEventListener("click", function(e) {
+ /*insert the value for the autocomplete text field:*/
+ inp.value = this.getElementsByTagName("input")[0].value;
+ /*close the list of autocompleted values,
+ (or any other open lists of autocompleted values:*/
+ closeAllLists();
+ });
+ a.appendChild(b);
+ }
+ }
+ });
+ /*execute a function presses a key on the keyboard:*/
+ inp.addEventListener("keydown", function(e) {
+ var x = document.getElementById(this.id + "autocomplete-list");
+ if (x) x = x.getElementsByTagName("div");
+ if (e.keyCode == 40) {
+ /*If the arrow DOWN key is pressed,
+ increase the currentFocus variable:*/
+ currentFocus++;
+ /*and and make the current item more visible:*/
+ addActive(x);
+ } else if (e.keyCode == 38) { //up
+ /*If the arrow UP key is pressed,
+ decrease the currentFocus variable:*/
+ currentFocus--;
+ /*and and make the current item more visible:*/
+ addActive(x);
+ } else if (e.keyCode == 13) {
+ /*If the ENTER key is pressed, prevent the form from being submitted,*/
+ e.preventDefault();
+ if (currentFocus > -1) {
+ /*and simulate a click on the "active" item:*/
+ if (x) x[currentFocus].click();
+ }
+ }
+ });
+
+ function addActive(x) {
+ /*a function to classify an item as "active":*/
+ if (!x) return false;
+ /*start by removing the "active" class on all items:*/
+ removeActive(x);
+ if (currentFocus >= x.length) currentFocus = 0;
+ if (currentFocus < 0) currentFocus = (x.length - 1);
+ /*add class "autocomplete-active":*/
+ x[currentFocus].classList.add("autocomplete-active");
+ }
+
+ function removeActive(x) {
+ /*a function to remove the "active" class from all autocomplete items:*/
+ for (var i = 0; i < x.length; i++) {
+ x[i].classList.remove("autocomplete-active");
+ }
+ }
+
+ function closeAllLists(elmnt) {
+ /*close all autocomplete lists in the document,
+ except the one passed as an argument:*/
+ var x = document.getElementsByClassName("autocomplete-items");
+ for (var i = 0; i < x.length; i++) {
+ if (elmnt != x[i] && elmnt != inp) {
+ x[i].parentNode.removeChild(x[i]);
+ }
+ }
+ }
+ /*execute a function when someone clicks in the document:*/
+ document.addEventListener("click", function(e) {
+ closeAllLists(e.target);
+ });
+ }
+
+ autocomplete(document.getElementById("myInput"), trial_hints);
+ </script>
+ </body>
+
+ </html> \ No newline at end of file
diff --git a/wqflask/wqflask/templates/search_history.html b/wqflask/wqflask/templates/search_history.html
new file mode 100644
index 00000000..11586c0a
--- /dev/null
+++ b/wqflask/wqflask/templates/search_history.html
@@ -0,0 +1,297 @@
+<<!DOCTYPE html>
+ <html>
+
+ <head>
+ <meta charset="utf-8">
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
+ <title></title>
+ <link rel="stylesheet" href="">
+ </head>
+ <style type="text/css">
+ .autocomplete {
+ /*the container must be positioned relative:*/
+ position: relative;
+ display: inline-block;
+
+ /*width: 30vw; */
+ }
+
+ .search_box {
+
+ background: #Ececec;
+
+ width: 50vw;
+ /*padding:15px 20px; */
+ border-radius: 50%;
+ border: 1px solid grey;
+ /* text-align: center; */
+
+ font-size: 18px;
+
+ flex-grow: 2;
+ border: none;
+ border-radius: 50px;
+
+ height: 40px;
+
+ padding: 2px 5px;
+
+ padding-left: 40px;
+
+
+
+
+ }
+
+ .search_box:focus {
+ border: 1px solid grey;
+ }
+
+
+
+ .hint-items {
+
+ position: absolute;
+
+ border: 1px solid #d4d4d4;
+
+ z-index: 99;
+ /*position the autocomplete items to be the same width as the container:*/
+ top: 100%;
+ left: 0;
+ right: 0;
+
+ background: white;
+
+ padding: 10px;
+
+ border-radius: 40px;
+
+ padding: 10px 20px;
+
+ /*border-bottom: none; */
+
+
+ }
+
+ .search_box_hint {
+ position: absolute;
+
+ border: 1px solid #d4d4d4;
+ border-bottom: none;
+ border-top: none;
+ z-index: 99;
+ /*position the autocomplete items to be the same width as the container:*/
+ top: 100%;
+ left: 0;
+ right: 0;
+
+ background: red;
+
+ padding: 10px;
+
+ border-radius: 40px;
+
+
+ }
+
+
+ .hint_area {
+ height: px;
+
+ width: 50vw;
+
+ border-radius: 40px;
+ background: red;
+ }
+
+
+
+ .search_box_hint_input {
+ display: block;
+
+ color: white;
+
+ width: 100%;
+
+ padding: 10px 20px;
+
+ /*border-radius:20px;*/
+ border: none;
+
+ color: #000;
+
+ font-weight: bold;
+
+ font-size: 18px;
+
+ }
+
+ .search_box_hint_input {
+ border: none;
+ background-color: transparent;
+
+ text-align: inherit;
+
+ color: #101691;
+ }
+
+ .search_box_hint_input:focus,
+ .search_box_hint_input:active {
+ box-shadow: none !important;
+ -moz-box-shadow: none !important;
+ -webkit-box-shadow: none !important;
+ outline: none !important;
+ }
+
+ .search_box_hint_input:hover {
+ background-color: #dedad9;
+ }
+ </style>
+
+ <body>
+ <div>
+ <div>
+ <h3>
+ this is the title
+ </h3>
+ </div>
+ <form id="form_1">
+ <div class="autocomplete" id="autocompleteForm">
+ <input class="search_box" id="search_box_input" type="text" name="" placeholder="search value" autocomplete="off" value="">
+ </div>
+ </form>
+ </div>
+ <script type="text/javascript">
+ let cache_countries;
+
+ const search = document.getElementById("search_box_input");
+
+ const form = document.getElementById("autocompleteForm");
+
+ search.addEventListener("focus", function(event) {
+
+ console.log("hello there")
+
+
+ a = document.createElement("DIV")
+
+ a.setAttribute("class", "hint-items");
+
+
+ this.parentNode.appendChild(a)
+
+ cache_countries = retrieveSearchHistory()
+
+
+ for (let i = 0; i < cache_countries.length; i++) {
+
+ console.log(i)
+ var textfieldSelector = document.createElement("input");
+
+ textfieldSelector.type = "button";
+
+ textfieldSelector.value = `${cache_countries[i]}`;
+
+ //textfieldSelector.classList.add("search_box_hint");
+
+ textfieldSelector.classList.add("search_box_hint_input");
+
+ textfieldSelector.addEventListener("click", function(event) {
+
+ console.log("clicked this country")
+
+ search.value = cache_countries[i] // remove child element
+
+ let parent = document.getElementById("search_box_input").parentNode
+
+ parent.removeChild(this.parentNode)
+
+
+ })
+
+ a.appendChild(textfieldSelector);
+ }
+
+ document.addEventListener('click', (event) => {
+ if (!event.target.matches('#autocompleteForm, #autocompleteForm *')) {
+
+
+ const collection = document.getElementsByClassName("hint-items");
+
+ console.log(collection)
+
+ if (collection.length > 0) {
+ let parent = document.getElementById("search_box_input").parentNode
+
+ parent.removeChild(collection[0])
+ } else {
+
+ //ju
+ }
+
+ }
+ })
+
+ })
+
+ formElement = document.getElementById("form_1");
+
+ function setPlaceHolderValue() {
+ document.getElementById("search_box_input").
+ }
+
+ function onFocusHandler(event) {
+
+ }
+
+ function searchHistoryClick(event) {
+
+ }
+
+ function removeSearchHintOnclick(element) {
+
+ parentELement = document.createElement("DIV")
+ parentELement.setAttribute("class", "hint-items");
+ element.parentNode.appendChild(a)
+ searchHistory = retrieveSearchHistory()
+ }
+
+ function saveBeforeSubmit(form) {
+
+ form.addEventListener("keydown", (event) => {
+
+ if (event.keyCode === 13) {
+ event.preventDefault()
+ if (search.value) {
+ dumpSearch(search.value)
+ form.submit()
+ }
+ return;
+ }
+ })
+
+ }
+ saveBeforeSubmit(formElement)
+
+ function retrieveSearchHistory() {
+ let results = JSON.parse(localStorage.getItem("gn_search_history"))
+ return results ? results : []
+ }
+
+ function dumpSearch(search_item) {
+
+ let currentSearch = retrieveSearchHistory()
+ currentSearch.unshift(search_item)
+
+ console.log(currentSearch)
+
+ localStorage.setItem("gn_search_history", JSON.stringify(currentSearch.slice(0, 5)));
+
+ return currentSearch
+
+ }
+ </script>
+ </body>
+
+ </html> \ No newline at end of file