Skip to content

Commit

Permalink
First Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad-Ayman committed Mar 21, 2023
0 parents commit 1f14c46
Show file tree
Hide file tree
Showing 3 changed files with 384 additions and 0 deletions.
74 changes: 74 additions & 0 deletions dom-06-demo-project-setup/assets/scripts/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Global variables

const newMovieButton = document.querySelector("header button");
const addModalElement = document.getElementById("add-modal");
const backdropElement = document.getElementById("backdrop");
const modalAddButton = document.querySelector(".btn--success");
const modalCancelButton = document.querySelector(".btn--passive");
const movieListElement = document.getElementById("movie-list");

let title = document.getElementById("title");
let imageUrl = document.getElementById("image-url");
let rating = document.getElementById("rating");

const movieData = [];
// Global functions
const toggleAddModal = () => {
addModalElement.classList.toggle("visible");
};
const toggleBackdrop = () => {
backdropElement.classList.toggle("visible");
};
const clearMovieInput = () => {
title.value = "";
imageUrl.value = "";
rating.value = "";
};
function modalCancelButtonHandler() {
toggleAddModal();
toggleBackdrop();
clearMovieInput();
}

//New movie form
newMovieButton.addEventListener("click", newMovieButtonHandler);

function newMovieButtonHandler() {
toggleAddModal();
toggleBackdrop();
}

// New movie entry
modalAddButton.addEventListener("click", modalAddButtonHandler);
function ab() {
movieListElement.innerHTML = `<ul id='movie-list'>
<li class = 'movie-element '>${movieData[movieData.length - 1].Title}</li>
<li class = 'movie-element movie-element__image'><img src="${
movieData[movieData.length - 1].imageUrl
}" alt="JS"></li>
<li class = 'movie-element movie-element__info'>${
movieData[movieData.length - 1].rating
}</li>
</ul>`;
}

function modalAddButtonHandler() {
title = document.getElementById("title").value.trim();
imageUrl = document.getElementById("image-url").value.trim();
rating = document.getElementById("rating").value.trim();

let lastEntry = {
Title: title,
Image: imageUrl,
Rate: rating,
};
movieData.push(lastEntry);
console.log(movieData);
ab();
toggleAddModal();
toggleBackdrop();
clearMovieInput();
}

modalCancelButton.addEventListener("click", modalCancelButtonHandler);
backdropElement.addEventListener("click", modalCancelButtonHandler);
252 changes: 252 additions & 0 deletions dom-06-demo-project-setup/assets/styles/app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
* {
box-sizing: border-box;
}

html {
font-family: sans-serif;
}

body {
margin: 0;
}

button:focus {
outline: none;
}

header {
width: 100%;
height: 4rem;
display: flex;
justify-content: space-between;
align-items: center;
padding: 0 2.5rem;
background: #00329e;
}

header h1 {
margin: 0;
color: white;
font-size: 1.5rem;
}

header button {
font: inherit;
padding: 0.5rem 1rem;
background: #f67722;
border: 1px solid #f67722;
color: white;
border-radius: 6px;
box-shadow: 0 1px 8px rgba(0, 0, 0, 0.26);
cursor: pointer;
}

header button:hover,
header button:active {
background: #f3cc4b;
border-color: #f3cc4b;
color: #995200;
}

label {
font-weight: bold;
margin: 0.5rem 0;
color: #464646;
}

input {
font: inherit;
border: 1px solid #ccc;
padding: 0.4rem 0.2rem;
color: #383838;
}

input:focus {
outline: none;
background: #fff1c4;
}

.btn {
font: inherit;
padding: 0.5rem 1.5rem;
border: 1px solid #00329e;
background: #00329e;
color: white;
border-radius: 6px;
box-shadow: 0 1px 8px rgba(0, 0, 0, 0.26);
cursor: pointer;
margin: 0 0.5rem;
}

.btn:hover,
.btn:active {
background: #f67722;
border-color: #f67722;
}

.btn--passive {
color: #00329e;
background: transparent;
border: none;
box-shadow: none;
}

.btn--passive:hover,
.btn--passive:active {
background: #aec6f8;
}

.btn--danger {
background: #d30808;
color: white;
border-color: #d30808;
}

.btn--danger:hover,
.btn--danger:active {
background: #ff3217;
border-color: #ff3217;
}

.modal {
position: fixed;
z-index: 100;
background: white;
border-radius: 10px;
width: 80%;
top: 30vh;
left: 10%;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.26);
display: none;
}

.modal.visible {
display: block;
animation: fade-slide-in 0.3s ease-out forwards;
}

.modal .modal__title {
margin: 0;
padding: 1rem;
border-bottom: 1px solid #00329e;
background: #00329e;
color: white;
border-radius: 10px 10px 0 0;
}

.modal .modal__content {
padding: 1rem;
}

.modal .modal__actions {
padding: 1rem;
display: flex;
justify-content: flex-end;
}

.movie-element {
margin: 1rem 0;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.26);
border-radius: 10px;
display: flex;
}

.movie-element h2,
.movie-element p {
font-size: 1.25rem;
margin: 0;
}

.movie-element h2 {
color: #383838;
margin-bottom: 1rem;
}

.movie-element p {
color: white;
display: inline;
background: #f67722;
padding: 0.25rem 1rem;
border-radius: 15px;
}

.movie-element__image {
flex: 1;
border-radius: 10px 0 0 10px;
overflow: hidden;
}

.movie-element__image img {
height: 100%;
width: 100%;
object-fit: cover;
}

.movie-element__info {
flex: 2;
padding: 1rem;
}

.card {
background: white;
border-radius: 10px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.26);
}

#entry-text {
width: 40rem;
margin: 2rem auto;
max-width: 80%;
padding: 1rem;
}

#entry-text p {
font-size: 1.5rem;
text-align: center;
}

#movie-list {
list-style: none;
width: 40rem;
max-width: 90%;
margin: 1rem auto;
padding: 0;
}

#backdrop {
position: fixed;
width: 100%;
height: 100vh;
top: 0;
left: 0;
background: rgba(0, 0, 0, 0.75);
z-index: 10;
pointer-events: none;
display: none;
}

#backdrop.visible {
display: block;
pointer-events: all;
}

#add-modal .modal__content {
display: flex;
flex-direction: column;
}

@media (min-width: 768px) {
.modal {
width: 40rem;
left: calc(50% - 20rem);
}
}

@keyframes fade-slide-in {
from {
transform: translateY(-5rem);
}
to {
transform: translateY(0);
}
}
58 changes: 58 additions & 0 deletions dom-06-demo-project-setup/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Favorite Movies</title>
<link rel="stylesheet" href="assets/styles/app.css" />
<script src="assets/scripts/app.js" defer></script>
</head>
<body>
<div id="backdrop"></div>
<div class="modal" id="add-modal">
<div class="modal__content">
<label for="title">Movie Title</label>
<input type="text" name="title" id="title" />
<label for="image-url">Image URL</label>
<input type="text" name="image-url" id="image-url" />
<label for="rating">Your Rating</label>
<input
type="number"
step="1"
max="5"
min="1"
name="rating"
id="rating"
/>
</div>
<div class="modal__actions">
<button class="btn btn--passive">Cancel</button>
<button class="btn btn--success">Add</button>
</div>
</div>
<div class="modal" id="delete-modal">
<h2 class="modal__title">Are you sure?</h2>
<p class="modal__content">
Are you sure you want to delete this item? This action can't be made
undone!
</p>
<div class="modal__actions">
<button class="btn btn--passive">No (Cancel)</button>
<button class="btn btn--danger">Yes</button>
</div>
</div>

<header>
<h1>Favorite Movies</h1>
<button>NEW MOVIE</button>
</header>

<main>
<section id="entry-text" class="card">
<p>Your personal movie database!</p>
</section>
<ul id="movie-list"></ul>
</main>
</body>
</html>

0 comments on commit 1f14c46

Please sign in to comment.