-
Notifications
You must be signed in to change notification settings - Fork 0
/
jqpunkapiII.html
186 lines (170 loc) · 7.86 KB
/
jqpunkapiII.html
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>DINAMIC PUNKAPI</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--CARREGAR FRAMEWORK DE JQUERY-->
<script src="http://code.jquery.com/jquery-3.5.1.min.js"></script>
<!--BOOTSTRAP-->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
<style type="text/css">
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}
.container{
margin: 0 auto;
}
.card-img-top {
width: 100%;
height: 15vw;
object-fit: contain;
}
#btn-carregar{
display: block;
margin: 0 auto;
}
h1, h2{
text-align: center;
}
.col-6 input{
width: 82%;
}
.btn{
width: 50%;
}
</style>
</head>
<body>
<div class="container mb-3">
<h1 class="mt-3">PUNKAPI</h1>
<h2 class="mb-4">Find your perfect beer!</h2>
<label for="txt-beer">Nom Cervesa:</label>
<input type="text" id="txt-beer">
<div class="filtrat text-center mt-3 mb-3 row">
<!-- ABV -->
<div class="col">
<h2>ABV</h2>
<div class="row">
<div class="col-6">
<label for="abv_min">min</label>
<input type="number" min="0" id="abv_min" class="num_user">
</div>
<div class="col-6">
<label for="abv_max">max</label>
<input type="number" min="0" id="abv_max" class="num_user">
</div>
</div>
</div>
<!-- IBU -->
<div class="col">
<h2>IBU</h2>
<div class="row">
<div class="col-6">
<label for="ibu_min">min</label>
<input type="number" min="0" id="ibu_min" class="num_user">
</div>
<div class="col-6">
<label for="ibu_max">max</label>
<input type="number" min="0" id="ibu_max" class="num_user">
</div>
</div>
</div>
<!-- EBC -->
<div class="col">
<h2>EBC</h2>
<div class="row">
<div class="col-6">
<label for="ebc_min">min</label>
<input type="number" min="0" id="ebc_min" class="num_user">
</div>
<div class="col-6">
<label for="ebc_max">max</label>
<input type="number" min="0" id="ebc_max" class="num_user">
</div>
</div>
</div>
</div>
<!-- BOTO -->
<input type="button" value="CARREGAR" id="btn-carregar" class="btn btn-outline-info mt-4">
</div>
<div class='container row row-cols-1 row-cols-md-3' id="capa"></div>
<script language="javascript">
$(function(){
// $(".num_user").click(function(){
// var entrada = $(this).val();
// if(entrada == ""){
// entrada = 0;
// }
// $(entrada).blur(function(){
// entrada = $(this).val();
// })
// console.log(entrada);
// });
$("#btn-carregar").click(function(){
var txt_beer = $("#txt-beer").val();
var abv_max = $("#abv_max").val();
var abv_min = $("#abv_min").val();
var ibu_max = $("#ibu_max").val();
var ibu_min = $("#ibu_min").val();
var ebc_max = $("#ebc_max").val();
var ebc_min = $("#ebc_min").val();
if(abv_max == ""){
abv_max = 0;
}
if(abv_min == ""){
abv_min = 0;
}
if(ibu_max == ""){
ibu_max = 0;
}
if(ibu_min == ""){
ibu_min = 0;
}
if(ebc_max == ""){
ebc_max = 0;
}
if(ebc_min == ""){
ebc_min = 0;
}
$.get("https://cors-anywhere.herokuapp.com/https://api.punkapi.com/v2/beers?name="+txt_beer+"&abv_gt="+abv_min+"&abv_It="+abv_max+"&ibu_gt="+ibu_min+"&ibu_It="+ibu_max+"&ebc_gt="+ebc_min+"&ebc_It="+ebc_max+"",function(data,status){
var i = 0;
var cervesa = "";
for(i=0;i<data.length;i++){
cervesa = data[i];
console.log(cervesa.abv)
if(abv_max>=cervesa.abv && abv_min<=cervesa.abv){
// ibu_max>=cervesa.ibu && ibu_min<=cervesa.ibu && ebc_max>=cervesa.ebc && ebc_min<=cervesa.ebc
$("#capa").append("<div class='col mb-4'>"+
"<div class='card h-100'>"+
"<div class='card-body'>"+
"<img src='"+cervesa.image_url+"' class='card-img-top'>"+
"<h2 class='card-title text-center mt-3'>"+cervesa.name+"</h2>"+
"<p>ABV: "+cervesa.abv+"</p>"+
"<p>"+cervesa.ibu+"</p>"+
"<p>"+cervesa.ebc+"</p>"+
"</div>"+
"</div>"+
"</div>");
}
// $("#capa").append("<div class='col mb-4'>"+
// "<div class='card h-100'>"+
// "<div class='card-body'>"+
// "<img src='"+cervesa.image_url+"' class='card-img-top'>"+
// "<h2 class='card-title text-center mt-3'>"+cervesa.name+"</h2>"+
// "<p>ABV: "+cervesa.abv+"</p>"+
// "<p>"+cervesa.ibu+"</p>"+
// "<p>"+cervesa.ebc+"</p>"+
// "</div>"+
// "</div>"+
// "</div>");
}
});
});
});
</script>
</body>
</html>