-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
106 lines (92 loc) · 3.25 KB
/
app.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
$(() => {
let currentPage = 1;
const loadPage = () => {
$.ajax({
url: "https://api.rawg.io/api/games?genres=indie&key=a0c636dde4744ca38404b9b629eb23d0&page=" + currentPage,
type: "GET",
}).then((data) => {
//modal starts by emptying previous modal then fills in with data and styling
const openModal = () => {
$(".title").empty()
$(".genres").empty()
$(".screenshots").empty()
$(".platforms").empty()
$("#modal").css("display", "block")
const index = $(event.currentTarget).attr("index")
$("<h1>").text(data.results[index].name).appendTo(".title")
$(".rating").text("Average Rating: " + data.results[index].metacritic)
$(".release").text("Release Date: " + data.results[index].released)
$(".playtime").text("How Long to Beat: " + data.results[index].playtime * 5 + " hours")
//genres
for (let i = 0; i < data.results[index].genres.length; i++) {
$(".genres").append(data.results[index].genres[i].name + " ")
}
$(".genres").prepend("Genres: ")
//screenshots
$(".screenshots").append($(`<img src="${data.results[index].short_screenshots[1].image}" />`))
$(".screenshots").append($(`<img src="${data.results[index].short_screenshots[2].image}" />`))
$(".screenshots").append($(`<img src="${data.results[index].short_screenshots[3].image}" />`))
//platforms
let platforms = data.results[index].platforms
for (let i = 0; i < platforms.length; i++) {
$(".platforms").append(data.results[index].platforms[i].platform.name)
if (i !== platforms.length - 1) {
$(".platforms").append(" | ")
}
}
$(".platforms").prepend("Platforms: ")
}
const closeModal = () => {
$("#modal").css("display", "none")
}
for (let i = 0; i < data.results.length; i++) {
const $makeCard = $("<div>").addClass("card" + i).addClass("cardbox").appendTo(".games")
.css(
{ "background-color": "rgba(1, 1, 1, .95)",
"margin": "5px",
"border-radius": "5px",
}).attr("index", i)
.hover(function(){
$(this).css({"background-color": "#62a187",
"transform": "translate(8px, 5px)",
"box-shadow": "none",
"cursor": "pointer"});
}, function(){
$(this).css({"background-color": "black",
"transform": "none",
"box-shadow": "10px 5px 5px rgba(1, 1, 1, .80)",
"cursor": "default"});
}).click(openModal)
$("<img>").attr("src", data.results[i].background_image)
.appendTo($makeCard)
$("<h4>").text(data.results[i].name).addClass(".cardtext").appendTo($makeCard)
}
$("#modal").click(closeModal)
});
}
loadPage()
$("#home").on("click", () => {
$(".cardbox").remove()
currentPage = 1
loadPage()
})
$("#random").on("click", () => {
$(".cardbox").remove()
currentPage = Math.floor(Math.random() * 101) + 1;
loadPage()
})
$("#next").on("click", () => {
$(".cardbox").remove()
if(currentPage <= 100){
currentPage++
}
loadPage()
})
$("#previous").on("click", () => {
$(".cardbox").remove()
if(currentPage > 1){
currentPage--
}
loadPage()
})
})