Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added modals for success and error that can be used anywhere #236

Merged
merged 1 commit into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,16 @@
</head>

<body>

<!-- Message Modal -->
<div id="messageModal" class="messageModal modal">
<div class="modal-content">
<p class="message" id="messageModalText"></p>
<div class="modalButtons">
<button id="acknowledgmentBtn">Ok</button>
</div>
</div>
</div>

<section class="navigation">
<div class="nav-container">
<div class="brand">
Expand Down Expand Up @@ -143,6 +152,8 @@ <h2><label for=""> First-appearance: </label></h2>
</p>
</div>
</center>


<script src="script.js"></script>
</body>
</html>
17 changes: 16 additions & 1 deletion script.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,20 @@ function downloadImage(imageUrl) {
aTag.remove();
}


// function for message modal
function messageModal(message){
const modal = document.getElementById('messageModal')
modal.style.display = "flex";

const messageElement = document.getElementById('messageModalText')
messageElement.textContent = message;

document.getElementById('acknowledgmentBtn').addEventListener('click',function(){
modal.style.display = "none";
});
}

const randomid = () => {
return Math.floor(Math.random() * 731) + 1;
};
Expand All @@ -111,7 +125,8 @@ searchbtn.onclick = () => {
getSearchSuperHero(inputValue);
} else {
// Handle the case where the input is empty (e.g., show an error message).
alert("Input is empty. Please enter a hero name.");
messageModal("Input is empty. Please enter a hero name.");
// alert("Input is empty. Please enter a hero name.");
}
};

Expand Down
66 changes: 66 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,72 @@ center {
color:white;
}

.modal{
display: flex;
display: none;
background-color: rgba(0, 0, 0, 0.4);
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 9999;
justify-content: center;
align-items: center;
flex-direction: column;
}

.modal > div {
color: white;
background-color: black;
border:1px solid white;
border-radius: 10px;
padding: 30px 40px 30px 40px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.25);
position: relative;
top: -50px;
z-index: 10000;
max-width: 500px;
max-height: 80%;
overflow: auto;
}

.modalButtons{
margin-top: 20px;
display:flex;
justify-content: end;
}

.modalButtons button{
--bg: #ba4394;
--hover-bg: #ff90e8;
--hover-text: #ba4394;
color: #ffe4f9;
border: 1px solid var(--bg);
border-radius: 6px;
padding: 0.8em 2em;
background: var(--bg);
transition: 0.2s;
margin-right: 0.6rem;
font-size: 16px;
}

.modalButtons button:hover {
color: var(--hover-text);
transform: translate(-0.25rem, -0.25rem);
background: var(--hover-bg);
box-shadow: 0.25rem 0.25rem var(--bg);
margin-left: 0.6rem;
font-size: 16px;
letter-spacing: 2px;
font-weight: bold;
}

.modalButtons button:active {
transform: translate(0);
box-shadow: none;
}


@media screen and (max-width: 406px) {
.head-title {
Expand Down
Loading