Commit 18d1c58a authored by Porter Libby's avatar Porter Libby
Browse files

add popup window

parent e4e9945b
This diff is collapsed.
......@@ -5,7 +5,9 @@
<title>EPIC JOURNEY</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="public/css/main.css">
<script src="data/careers-data.js"></script>
<script src="public/js/searchbar.js"></script>
</head>
<body>
<div class="parent" style='position: absolute; z-index: 0;'>
......@@ -43,11 +45,26 @@
function openDetails(target){
console.log(target);
var newDiv = document.createElement("div");
newDiv.className = 'details'
newDiv.className = 'details';
var returnButton = document.createElement('input');
returnButton.className = 'return';
returnButton.setAttribute("type", "button");
newDiv.append(returnButton);
var container = document.getElementById('details-container');
container.style.zIndex = 1;
container.append(newDiv);
createSearchBar(newDiv);
returnButton.onclick = function() { closeDetails(); };
}
function closeDetails() {
console.log('test');
var container = document.getElementById('details-container');
container.innerHTML = '';
container.style.zIndex = -1;
}
</script>
</body>
......
:root{
--block-color-1: coral;
--detail-color-1: lightgreen;
--detail-color-1: lightgray;
--text-color-1: black;
--text-color-2: #333;
}
......@@ -16,14 +16,24 @@ body {
position: absolute;
}
.details{
height: 90vh;
width: 90vw;
margin: 5vh 5vw;
height: 80vh;
width: 80vw;
margin: 10vh 10vw;
position: absolute;
top: 0px;
background-color: var(--detail-color-1);
border-radius: 8px;
border: 1px solid black;
text-align: center;
overflow: hidden;
}
.details #searchbar{
margin-top: 100px;
}
.return{
position: absolute;
right: 10px;
top: 10px;
}
#details-container{
position: absolute;
......
// Render search bar
// Porter Libby 2019
function createSearchBar(container){
//create search obj
var search_container = document.createElement("div");
search_container.id = 'career-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 Careers:';
search_container.appendChild(prompt);
search_container.appendChild(search);
container.appendChild(search_container);
names_for_search = [];
for(x=0;x<careers.length;x++){
names_for_search.push(careers[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