forked from brittanyrw/emojiscreen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
130 lines (112 loc) · 4.79 KB
/
app.js
File metadata and controls
130 lines (112 loc) · 4.79 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
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
$(document).ready(function() {
// Create a variable for the container to hold the emoji cards.
var emojiCardContainer = $("#emojis");
// 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) {
const type = emojiItems[i].type
const emojiImgs = emojiItems[i].emojiImgs
const year = emojiItems[i].year
const title = emojiItems[i].title
const itemLink = emojiItems[i].itemLink
emojiCard +=
"<div class='emoji-card' data-filter='" + type +
"'><div class='hint-container'><i class='fas fa-question-circle'></i><p class='hint'><span class='type'>" + type +
"</span></p></div><div class='emoji-images'>" + emojiImgs +
"</div><div class='emoji-card-title hide-card'>" +
generateTitle(title, year, itemLink) +
"</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 shows/movies to the footer.
$("footer span").append(emojiItems.length);
// Display movies 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;
}
// The code that runs the filter buttons at the top of the page. This currently allows users to filter by 'type' (ie musical, movie or tv show).
$("#filters button").each(function() {
$(this).on("click", function() {
var filtertag = $(this).attr("data-filter");
$("#message").hide();
$("div.emoji-card-title").addClass("hide-card");
if (filtertag == "view-all") { // If the user clicks on view all, show all cards.
$("div.emoji-card").show();
} else if ( // If the user clicks on movies, musicals or tv shows, show the cards that fall into that category and hide all cards that do not fall into that category.
$("div.emoji-card[data-filter='" + filtertag + "']").length > 0
) {
$("div.emoji-card").show();
$(
"div.emoji-card:not([data-filter='" + filtertag + "'])"
).hide();
} else { // If there are no cards that match the filter, display a message that says that there are no cards for that category.
$("div.emoji-card").hide();
$("#message").show();
$("#message").html(
"<p>There are no " + filtertag + " cards on this page. 🙁</p>"
);
}
});
});
// Reveal the movie or show title when the user clicks on the emojis.
$("#emojis").on("click", ".emoji-images", function() {
$(this)
.siblings(".emoji-card-title")
.toggleClass("hide-card");
});
// Display a hint (type ie tv, movie or musical) when hovering over the question mark.
$("#emojis").on("mouseover", ".hint-container", function() {
$(this)
.find(".hint")
.addClass("hint-reveal");
});
// Hide hint (type ie tv, movie or musical) when the user stops hovering over the question mark.
$("#emojis").on("mouseleave", ".hint-container", function() {
$(this)
.find(".hint")
.removeClass("hint-reveal");
});
// Toggle to expand or hide all of the movie/show names by clicking an icon
$(".btn-reveal-all").click(function() {
$(this).toggleClass(["revealed"])
var emojis = $("#emojis")
.find(".emoji-card-title");
if($(this).hasClass("revealed")){
emojis.removeClass("hide-card");
} else {
emojis.addClass("hide-card");
}
var title = $(this).attr("title");
title =
title.search(/reveal/i) === -1
? title.replace(/hide/i, "Reveal")
: title.replace(/reveal/i, "Hide");
$(this).attr("title", title);
$(this)
.find("i")
.toggleClass(["fa-eye", "fa-eye-slash"]);
});
function generateTitle(title, year, itemLink) {
const titleElement = "<h3>" + title +" (" + year + ")</h3>"
if(itemLink) {
return "<a title='Go to website' href='" + itemLink + "' target='_blank'>" + titleElement + "</a>"
}
return titleElement
}
});