-
Notifications
You must be signed in to change notification settings - Fork 0
/
control.js
46 lines (44 loc) · 1.44 KB
/
control.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
function search(){
var cartaABuscar = document.getElementById("cartaABuscar").value.toLowerCase();
var cardList = document.getElementById("cardList");
var name, card, id;
if(cartaABuscar == null || cartaABuscar == ""){
alert("Ingresá el nombre de una carta!");
}else{
fetch('https://api.magicthegathering.io/v1/cards?name=' + cartaABuscar)
.then(response => response.json())
.catch(err => alert("No se encontraron cartas!"))
.then(data => {
console.log(data)
cardList.innerHTML = null;
if(data.cards.length == 0){
alert("No se encontraron cartas!");
return false;
}
for(var i = 0; i < data.cards.length; i++){
name = data.cards[i].name;
if(data.cards[i].imageUrl == undefined){
card = "back.jpg";
}else{
card = data.cards[i].imageUrl;
}
var list = document.createElement("li");
list.className = "bg-lite-grey padded margin";
list.innerHTML = "<strong>" + name + "</strong><br><br><img src = '" + card + "'>";
cardList.appendChild(list);
}
document.getElementById("cartaABuscar").value = "";
})
document.getElementById("footer").classList.remove("row", "col-full", "fixed-down");
}
cartaABuscar = null;
}
window.onload = function(){
var cartaABuscar = document.getElementById("cartaABuscar");
cartaABuscar.addEventListener("keyup", function(event) {
if(event.keyCode === 13) {
event.preventDefault();
document.getElementById("search").click();
}
});
}