-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplatten.js
110 lines (98 loc) · 3.56 KB
/
platten.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
101
102
103
104
105
106
107
108
109
110
var database = {
"lieblingsplatten": [
{
"url": "img/AlbumArt/fink.png",
"artist": "Fink",
"album": "Resurgam",
"text": "",
"vid": "https://www.youtube.com/embed/zy31vJQPPk0"
},
{
"url": "img/AlbumArt/kittydaisyandlewis.png",
"artist": "Kitty, Daisy & Lewis",
"album": "Superscope",
"text": "",
"vid": "https://www.youtube.com/embed/jD86aRsJ1N0"
},
{
"url": "img/AlbumArt/eilenjewell.png",
"artist": "Eilen Jewell",
"album": "Down Hearted Blues",
"text": "",
"vid": "https://www.youtube.com/embed/beN3Isqxgyk"
},
{
"url": "img/AlbumArt/kacyandclayton.png",
"artist": "Kacy & Clayton",
"album": "The Siren's Song",
"text": "",
"vid": "https://www.youtube.com/embed/BinJg3urQDU"
},
{
"url": "img/AlbumArt/valeriejune.png",
"artist": "Valerie June",
"album": "Order Of Time",
"text": "",
"vid": "https://www.youtube.com/embed/rN35g4eLQgg"
},
{
"url": "img/AlbumArt/jebloynichols.png",
"artist": "Jeb Loy Nichols",
"album": "Country Hustle",
"text": "",
"vid": "https://www.youtube.com/embed/HRO_eXX6zpY"
}
],
"lieblingssongs": [
]
}
var oldRect; //stores the previous position of the open card for the closing animation
function expand(platte) { //opening animation for cards
oldRect = platte.getBoundingClientRect(); //get start dimensions, also stores the previous position of the open card for the closing animation
var card = platte.cloneNode(true); //create a clone that can be positioned absolute on the page
card.classList.add("card"); //add the class for opened cards
card.style.top = oldRect.top + "px"; //put the clone to the starting position
card.style.left = oldRect.left + "px";
card.style.height = oldRect.height + "px"; //set the clones starting dimensions
card.style.width = oldRect.width + "px";
card.onclick = false; //remove the event listener
document.body.appendChild(card); //paint it to the dom
card.style.transition = "all .4s ease-in-out"; //add the transition now so it doesn't move on the first paint
setTimeout(function () { //move clone to destination position, dimensions & Shadows (could be redone with class) (delayed to wait until transition is set)
card.classList.add("expanded");
}, 10);
}
function retract(platte) { //closing animation
card = document.querySelector("body > .platte.card"); //find open card
card.classList.remove("expanded");
card.style.top = oldRect.top + "px"; //move back to previously saved position
card.style.left = oldRect.left + "px";
card.style.height = oldRect.height + "px"; //set back to previously saved dimensions
card.style.width = oldRect.width + "px";
setTimeout(function() {
document.body.removeChild(card); //delete clone
}, 410);
}
function paintPlatte(info, parent) {
parent.innerHTML += [
"<div class=\"platte\" onclick=\"expand(this)\">\n<div class=\"cover\" style=\"background:url(",
info.url,
");\"></div>\n<div class=\"desc\">\n<span class=\"artist\">",
info.artist,
"</span>\n<span class=\"album\">",
info.album,
"</span>\n</div>\n<p>",
info.text,
"</p>\n<iframe class=\"vid\" src=\"",
info.vid,
"\" frameborder=\"0\" allowfullscreen></iframe>\n<button class=\"closebtn\" onclick=\"retract(this)\">×</button>\n</div>\n"
].join("");
}
function paintPlatten() { //will add the necessary html for every record into its respective container
database.lieblingsplatten.forEach(function (platte) {
paintPlatte(platte, window.lieblingsplatten);
});
database.lieblingssongs.forEach(function (platte) {
paintPlatte(platte, window.lieblingssongs);
});
}