Skip to content
Open
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
3 changes: 1 addition & 2 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<main>
<section class="section">
<ul class="container film__container"></ul>
</section>
</section>

<!-- Section pagination -->
<section class="pagination-section">
Expand All @@ -71,7 +71,6 @@ <h2 class="visually-hidden">Pagination</h2>
<div class="preloader"></div>
</div>
<div class="loader visually-hidden"></div>

</main>
<include src="./partials/modal.html"></include>
<script src="./index.js" type="module"></script>
Expand Down
14 changes: 14 additions & 0 deletions src/js/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,17 @@ async function onGetFilmDataByID(id) {
console.log(error);
}
}

export async function onGetFilmVideoByID(id) {
try {
const response = await axios.get(
`${BASE_URL}/movie/${id}/videos?api_key=${KEY}`
);
if (!response.status) {
throw new Error('This movie is not available');
}
return response;
} catch (error) {
console.log(error);
}
}
4 changes: 3 additions & 1 deletion src/js/modal-create-markup.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function onCreateMarkup({
<p class="modal-info__description">
${overview}
</p>
<button type="button" class="watch-trailer__btn " id="${id}">WATCH TRAILER</button></li>
<ul class="modal-info__button-list">
<li class="modal-info__button-list-item">
<button type="button" class="modal-button">ADD TO WATCHED</button></li>
Expand All @@ -62,12 +63,13 @@ function onCreateMarkup({
</div>
</div>
</div>`;

onAddMarkupFromDOM(filmInfoMarkup);
let closeModalButton =
refs.backdrop.getElementsByClassName('button-close')[0];
closeModalButton.addEventListener('click', onCloseModal);
closeModalButton.addEventListener('click', onRemoveMarkupModal);
console.log(`📌 closeModalButton`, closeModalButton);
// console.log(`📌 closeModalButton`, closeModalButton);
}

function onAddMarkupFromDOM(markup) {
Expand Down
60 changes: 60 additions & 0 deletions src/js/modal-open-close.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ import { onGetFilmDataByID } from './api';
import noImageAvailable from '../images/no-image-available.jpg';
import { refs } from './refs';
import { onCreateMarkup } from './modal-create-markup';
import { onGetFilmVideoByID } from './api';

export { onCloseModal };
const BASE_POSTER_URL = 'https://image.tmdb.org/t/p/w500/';

const watchBtn = document.querySelector('.watch-trailer__btn');
const overlayContent = document.querySelector('.overlay-content');

refs.filmContainer.addEventListener('click', onOpenModal);

function onOpenModal(e) {
Expand Down Expand Up @@ -58,9 +63,64 @@ function onOpenModal(e) {
data.overview = 'Description not found';
}
onCreateMarkup(data);

// =================VIDEO================

document.getElementById(filmId).addEventListener('click', () => {
openTrailer(filmId);
});
});
}

function openTrailer(filmId) {
onGetFilmVideoByID(filmId)
.then(data => {
return data.data;
})
.then(data => {
if (data.results.length > 0) {
console.log(data.results);
var videoArr = [];
// const filmRes = data.results;
filmRes.forEach(({ name, key, type }) => {
// filmRes.find(item.id);
if (type === 'Trailer') {
return videoArr.push(
`<div class="iframe__div ">
<button data-modal-close type="button" class="button-close">
<svg class="button-close__icon" width="14" height="14">
<use href="${refs.IconCloseHref}"></use>
</svg>
</button>
<iframe
class="iframe-video"
width="760" height="515"
src="https://www.youtube.com/embed/${key}"
title="${name}" frameborder="0"
allow="accelerometer; autoplay; clipboard-write;
encrypted-media; gyroscope; picture-in-picture;
web-share" allowfullscreen>
</iframe></div>`
);
}
});

refs.backdrop.innerHTML = videoArr.join('');

let closeModalButton =
refs.backdrop.getElementsByClassName('button-close')[0];
closeModalButton.addEventListener('click', onCloseModal);
closeModalButton.addEventListener('click', onRemoveMarkupModal);
}
});
}

function onRemoveMarkupModal() {
refs.backdrop.innerHTML = ` `;
}

// ===============================================================

function onCloseModal() {
window.removeEventListener('keydown', onEscKeyPress);
refs.backdrop.classList.add('visually-hidden');
Expand Down
2 changes: 2 additions & 0 deletions src/partials/modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
href="./images/icon.svg#icon-close-button"
></use>
</svg>

</div>
</div>
11 changes: 11 additions & 0 deletions src/sass/components/modal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,14 @@
margin-right: 15px;
}
}

// =============================VIDEO==================

.iframe__div {
position: relative;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
background: rgba(0, 0, 0, 0.5);
}