-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
153 lines (151 loc) · 5.89 KB
/
index.html
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Кино</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<!-- Bootstrap icons -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css"/>
<script src="https://unpkg.com/vue@next"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/noUiSlider/15.5.0/nouislider.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/noUiSlider/15.5.0/nouislider.css" integrity="sha512-MKxcSu/LDtbIYHBNAWUQwfB3iVoG9xeMCm32QV5hZ/9lFaQZJVaXfz9aFa0IZExWzCpm7OWvp9zq9gVip/nLMg==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<script type="text/javascript" src="./cinema.js"></script>
</head>
<body>
<div class="container mt-5" id="app">
<div class="row mb-5 pt-5 gx-5">
<div class="col-2">
<select class="form-select shadow-none" v-model="selectedGenre">
<option disabled value="">Выберите жанр</option>
<option>все</option>
<option>комедия</option>
<option>драма</option>
<option>фэнтези</option>
<option>приключения</option>
<option>мультфильм</option>
</select>
</div>
<div class="col-6">
<div ref="slider"></div>
</div>
<div class="col-2">
<button type="button" class="btn btn-outline-secondary" @click="clickSortBtn('byTitle')" :class="{ active: sort.byTitle.isSeleted}">
<i v-if="sort.byTitle.isDesc" class="bi bi-sort-alpha-down"></i>
<i v-else class="bi bi-sort-alpha-up"></i>
по названию
</button>
</div>
<div class="col-2">
<button type="button" class="btn btn-outline-secondary" @click="clickSortBtn('byYear')" :class="{ active: sort.byYear.isSeleted}">
<i v-if="sort.byYear.isDesc" class="bi bi-sort-numeric-down"></i>
<i v-else class="bi bi-sort-numeric-up"></i>
по году
</button>
</div>
</div>
<div class="row">
<div class="col-2 mb-3" v-for="item in filterList" :key="item.id">
<img :src="`./image/${item.poster}`" class="cinema-img"/>
</div>
</div>
</div>
</body>
<style>
.cinema-img {
width: 100%;
cursor: pointer;
transition: transform .3s ease-in-out;
filter: grayscale(.7);
}
.cinema-img:hover {
filter: grayscale(0);
transform: scale(1.1);
}
</style>
<script>
const App = {
computed: {
filterList() {
return this.cinemaList.filter(v => {
// фильтрация по году
if (this.dateFrom > v.year || v.year > this.dateTo) return false
if (this.selectedGenre && this.selectedGenre !== 'все' && !v.genre.includes(this.selectedGenre)) return false
return true
}).sort((a, b) => {
if (this.sort.byTitle.isSeleted) {
if (this.sort.byTitle.isDesc) {
if (a.title < b.title) return -1
if (a.title > b.title) return 1
return 0
} else {
if (a.title > b.title) return -1
if (a.title < b.title) return 1
return 0
}
} else {
return this.sort.byYear.isDesc ? a.year - b.year : b.year - a.year
}
})
}
},
data() {
return {
cinemaList: cinemaData,
selectedGenre: null,
dateFrom: 1950,
dateTo: 2022,
sort: {
byTitle: {
isSeleted: true,
isDesc: true,
},
byYear: {
isSeleted: false,
isDesc: false,
},
},
}
},
methods: {
clickSortBtn(name) {
if(name === 'byTitle') {
this.sort.byTitle.isSeleted = true
this.sort.byYear.isSeleted = false
if (this.sort.byTitle.isSeleted) this.sort.byTitle.isDesc = !this.sort.byTitle.isDesc
} else {
this.sort.byYear.isSeleted = true
this.sort.byTitle.isSeleted = false
if (this.sort.byYear.isSeleted) this.sort.byYear.isDesc = !this.sort.byYear.isDesc
}
},
},
mounted() {
noUiSlider.create(this.$refs.slider, {
start: [this.dateFrom, this.dateTo],
connect: true,
tooltips: [true, true],
format: {
from: Number,
to: function(value) {
return (parseInt(value));
}
},
range: {
min: 1950,
max: 2022,
},
pips: {
mode: 'values',
values: [1950, 1960, 1970, 1980, 1990, 2000, 2010, 2022],
density: 1,
stepped: true,
}
}).on('update', (v) => {
this.dateFrom = v[0]
this.dateTo = v[1]
})
}
}
Vue.createApp(App).mount('#app')
</script>
</html>