-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathapp.js
More file actions
84 lines (65 loc) · 3.22 KB
/
app.js
File metadata and controls
84 lines (65 loc) · 3.22 KB
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
$(document).ready(function () {
// Create a variable for the container to hold the emoji cards.
var emojiCardContainer = $("#songs");
// Create a variable for the emoji cards.
var emojiCard = "";
// Run the random order function below on the data inside data.js. This will display the cards in a random order on the page every time the page is refreshed.
shuffle(emojiItems);
// Loop through the data from the data.js file and insert parts of the data into HTML. On each loop, we are appending a new card with the HTML below.
for (var i in emojiItems) {
var featuredArtist = $.makeArray(emojiItems[i].featuredArtist).join(', ');
var artist = $.makeArray(emojiItems[i].artist).join(', ');
emojiCard +=
"<div class='emoji-card'><div class='emoji-card-wrapper'><div class='hint-container'><i class='fas fa-question-circle'></i><p class='hint'><span class='type'>" + emojiItems[i].year +
"</span></p></div><div class='emoji-images'>" + emojiItems[i].emojiImgs +
"</div><div class='emoji-card-title hide-card'>";
if (emojiItems[i].musicVideo) {
emojiCard += "<div class='emoji-card-link'><a href='" + emojiItems[i].musicVideo + "' title='View " + emojiItems[i].title + " Music Video' target='_blank'><i class='fas fa-play-circle'></i></a></div>";
}
emojiCard += "<div class='title-content'><h3>" + emojiItems[i].title + " (" + emojiItems[i].year + ")" + "</h3>";
if (featuredArtist) {
emojiCard += "<div class='artist-ft-container'><h4>" + artist + " ft. " + featuredArtist + "</h4></div>";
} else {
emojiCard += "<div class='artist-container'><h4>" + artist + "</h4></div>";
}
emojiCard += "</div></div></div></div>";
}
// Append the emoji card variable, which has all of the emoji cards to the initial variable we created that was for the container to hold the cards.
emojiCardContainer.html(emojiCard);
// Run Twemoji to change all emojis to Twitter emojis.
twemoji.parse(document.body);
// Add the count of number of songs to the footer.
$("footer span").append(emojiItems.length);
// Display songs and show in a random order, the random order will refresh on page reload. This function is used above before the cards are rendered on the page.
function shuffle(array) {
var currentIndex = array.length,
temporaryValue,
randomIndex;
while (currentIndex !== 0) {
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
// Expand the emoji card when clicked to reveal the song name, artist and music video link.
$("#songs").on("click", ".emoji-images", function () {
$(this)
.siblings(".emoji-card-title")
.toggleClass("hide-card");
});
// Display a hint when hovering over the question mark.
$("#songs").on("mouseover", ".hint-container", function () {
$(this)
.find(".hint")
.addClass("hint-reveal");
});
// Hide hint when the user stops hovering over the question mark.
$("#songs").on("mouseleave", ".hint-container", function () {
$(this)
.find(".hint")
.removeClass("hint-reveal");
});
});