-
Notifications
You must be signed in to change notification settings - Fork 0
/
collections.js
73 lines (72 loc) · 2.46 KB
/
collections.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
const nav = document.querySelector('nav')
const navItems = document.querySelectorAll('nav li')
const container = document.querySelectorAll('.collections-container')
const navContainer = document.querySelector('.nav-container')
let albums = document.querySelectorAll('.album')
document.body.addEventListener('click', function (e) {
let album = e.target.closest('.album')?.dataset.id
console.log(album)
if (!album) return
sessionStorage.setItem('currentAlbum', JSON.stringify(album))
window.location = 'album.html'
})
document.querySelectorAll('.harmburger-toggle').forEach(el => {
el.addEventListener('click', function () {
nav.classList.toggle('active')
})
})
navItems.forEach((item, idx) => {
item.addEventListener('click', function () {
if (idx === 0) window.location = 'index.html'
if (idx === 1) window.location = 'album.html'
if (idx === 2) window.location = 'collections.html'
})
})
Array.from(navContainer.children).forEach((item, idx) => {
item.addEventListener('click', function () {
;[...navContainer.children].forEach(item => item.classList.remove('active'))
;[...container].forEach(item => item.classList.remove('active'))
this.classList.add('active')
container[idx].classList.add('active')
})
})
let collections = JSON.parse(localStorage.getItem('#16102022AcE'))
let collections1 = JSON.parse(localStorage.getItem('#16102022AdE'))
if (collections != null) {
Object.entries(collections).forEach(([id, obj]) => {
container[0].innerHTML += `<div class="album" data-id="${id}">
<div class="darken"></div>
<div class="img-container">
<img
src="${obj.img}"
alt="cover-image"
/>
</div>
<div class="text-container">
<h2 title="${obj.name}">${obj.name.split(/[\s,]/g)[0]}...</h2>
<p class="name">${obj.name1}</p>
<p class="likes">${obj.likes}m likes</p>
<img src="./icons/Play.svg" alt="play" />
</div>
</div>`
})
}
if (collections1 !== null) {
Object.entries(collections1).forEach(([id, obj]) => {
container[1].innerHTML += `<div class="album" data-id="${id}">
<div class="darken"></div>
<div class="img-container">
<img
src="${obj.img}"
alt="cover-image"
/>
</div>
<div class="text-container">
<h2 title="${obj.name}">${obj.name.split(/[\s,]/g)[0]}...</h2>
<p class="name">${obj.name1}</p>
<p class="likes">${obj.likes}m likes</p>
<img src="./icons/Play.svg" alt="play" />
</div>
</div>`
})
}