Commit 166797be authored by pelibby16's avatar pelibby16
Browse files

Revert "add data and searchbar js"

This reverts commit 24c95c68
parent 24c95c68
......@@ -36,11 +36,7 @@
<link rel="apple-touch-icon" href="icon.png">
<link rel="stylesheet" href="public/css/main.css">
<!-- DATA REFERENCES -->
<script src="public/data/data.js"></script>
<!-- SCRIPT REFERENCES -->
<script src="public/js/searchBar.js"></script>
</head>
......@@ -97,7 +93,7 @@
<!-- MAIN CONTENT AREA (padded scrollable area) -->
<div id='main-content'>
<!-- Carousel -->
<!-- Block 1 -->
<div id="create-carousel" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#create-carousel" data-slide-to="0" class="active"></li>
......@@ -129,12 +125,8 @@
</div>
<!-- Block 1 -->
<div id='block-1' class='block'>
<div class='block'>
<span class='section-prompt'>1. Type the name of a major you are interested in</span>
<script>
var parent = document.getElementById('block-1');
create_searchbar(parent,'major_selection');
</script>
</div>
<!-- Block 2 -->
......
This diff is collapsed.
// Render search bar
// Porter Libby 2019
function create_searchbar(parent, key){
//create search obj
var search_container = document.createElement("div");
search_container.id = key + '-search-container';
var search = document.createElement("INPUT");
search.id = 'searchbar'
search.setAttribute("type", "text");
search.setAttribute("value", "");
prompt = document.createElement('span');
prompt.innerHTML = 'Search for ' + key + ':';
search_container.appendChild(prompt);
search_container.appendChild(search);
parent.appendChild(search_container);
names_for_search = [];
for(x=0;x<dictionary[key].length;x++){
names_for_search.push(dictionary[key][x]);
}
autocomplete(document.getElementById("searchbar"), names_for_search);
}
function autocomplete(inp, arr) {
var currentFocus;
inp.addEventListener("input", function(e) {
var a, b, i, val = this.value;
closeAllLists();
if (!val) { return false;}
currentFocus = -1;
a = document.createElement("DIV");
a.setAttribute("id", this.id + "autocomplete-list");
a.setAttribute("class", "autocomplete-items");
this.parentNode.appendChild(a);
for (i = 0; i < arr.length; i++) {
if (arr[i].substr(0, val.length).toUpperCase() == val.toUpperCase()) {
b = document.createElement("DIV");
b.innerHTML = "<strong>" + arr[i].substr(0, val.length) + "</strong>";
b.innerHTML += arr[i].substr(val.length);
b.innerHTML += "<input type='hidden' value='" + arr[i] + "'>";
b.addEventListener("click", function(e) {
inp.value = this.getElementsByTagName("input")[0].value;
closeAllLists();
});
a.appendChild(b);
}
}
});
inp.addEventListener("keydown", function(e) {
var x = document.getElementById(this.id + "autocomplete-list");
if (x) x = x.getElementsByTagName("div");
if (e.keyCode == 40) {
currentFocus++;
addActive(x);
} else if (e.keyCode == 38) { //up
currentFocus--;
addActive(x);
} else if (e.keyCode == 13) {
e.preventDefault();
if (currentFocus > -1) {
if (x) x[currentFocus].click();
}
}
});
function addActive(x) {
if (!x) return false;
removeActive(x);
if (currentFocus >= x.length) currentFocus = 0;
if (currentFocus < 0) currentFocus = (x.length - 1);
x[currentFocus].classList.add("autocomplete-active");
}
function removeActive(x) {
for (var i = 0; i < x.length; i++) {
x[i].classList.remove("autocomplete-active");
}
}
function closeAllLists(elmnt) {
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]);
}
}
}
document.addEventListener("click", function (e) {
closeAllLists(e.target);
});
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment