-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
100 lines (84 loc) · 3.06 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
const index = (function () {
function init() {
dataServer.loadTablesintoLocalStorage();
}
window.onload = init();
// ************************************ RENDERING MOVIE LIST
const movieList = document.querySelector('.movie-list');
dataServer.getMovies().forEach(movie => {
let tagList = '';
movie.tags.forEach(tag => {
tagList += tag + '/';
});
tagList = tagList.slice(0, -1); // removing last '/'
movieList.innerHTML += `<div class="movie-list-item" data-movieid=${movie.id}>
<img src=${movie.movImgURL} alt="movie-poster" />
<h4>${movie.name}</h4>
<p>${tagList}</p>
</div>`;
});
// ************************************ OPENING MOVIE INFO PAGE
function openMovieInfo(movieslist) {
movieslist.forEach(movie => {
movie.addEventListener('click', () => {
window.open('./movieinfo.html?movieid=' + movie.getAttribute('data-movieid'), '_self');
});
});
}
const carousalImages = document.querySelectorAll('.carousal-slide img');
openMovieInfo(carousalImages);
const movieListItems = document.querySelectorAll('.movie-list-item');
openMovieInfo(movieListItems);
// ************************************ MOVIE LIST SLIDER
const movieListItemWidth = movieListItems[0].clientWidth;
function slideMovieList(movieListSlidePostion) {
movieList.style.transform = 'translateX(' + -movieListItemWidth * 5.55 * movieListSlidePostion + 'px)';
}
const viewAllBtn = document.querySelector('#viewAll');
const movieListNextBtn = document.querySelector('#mnextBtn');
const movieListPrevBtn = document.querySelector('#mprevBtn');
// checkMoviePages
if (movieListItems.length <= 5) {
movieListNextBtn.classList.add('hide');
viewAllBtn.classList.add('hide');
}
let movieListPage = 0;
// readMovieListClickPrev
movieListPrevBtn.addEventListener('click', () => {
movieListPage--;
slideMovieList(movieListPage);
if ((movieListPage + 1) * 5 < movieListItems.length) {
movieListNextBtn.classList.remove('hide');
}
if (movieListPage == 0) {
movieListPrevBtn.classList.add('hide');
}
});
// readMovieListClickNext
movieListNextBtn.addEventListener('click', () => {
movieListPage++;
slideMovieList(movieListPage);
if (movieListPage != 0) {
movieListPrevBtn.classList.remove('hide');
}
if ((movieListPage + 1) * 5 >= movieListItems.length) {
movieListNextBtn.classList.add('hide');
}
});
// readViewAllBtnClick
let viewAllFlag = false;
viewAllBtn.addEventListener('click', () => {
movieListPage = 0;
viewAllFlag = !viewAllFlag;
if (viewAllFlag == true) {
movieList.style.transform = 'translateX(' + -movieListItemWidth * -0.5 + 'px)';
movieListNextBtn.classList.add('hide');
movieListPrevBtn.classList.add('hide');
} else if (viewAllFlag == false) {
movieList.style.transform = 'translateX(' + -movieListItemWidth * 0 + 'px)';
movieListPrevBtn.classList.add('hide');
movieListNextBtn.classList.remove('hide');
}
movieList.classList.toggle('wrap');
});
})();