-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
79 lines (71 loc) · 3.85 KB
/
script.js
File metadata and controls
79 lines (71 loc) · 3.85 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
/* global $ */
let apodUrl = "https://api.nasa.gov/planetary/apod?api_key=ODDZz7IgCLegc2WTekiVtlYGSobchwr6mbjuka9i";
let url = "https://images-api.nasa.gov/search?q={q}";
let userInput;
//let keywords;
$("#pageOne").show();
$("#resultsPage").hide();
$(".enter").click(function(){
userInput = $(".inputOne").val();
//keywords = userInput.split(" ");
//console.log(keywords);
$("#keywordText").text("Showing results for: " + userInput);
$("#pageOne").hide();
$("#resultsPage").show();
url = "https://images-api.nasa.gov/search?q=" + userInput;
/*for(var i; i < keywords.length;i++){
url = "https://images-api.nasa.gov/search?q=" + keywords[i];
console.log(url);*/
console.log(url);
$.ajax({
url: url,
method: "GET",
success: function(response){
//$("#apiResults").html("<div class=\"resultBox\"><a target=\"_blank\" href=\"" + response.collection.items[0].links[0].href + "\"><img class=\"resultImg\" src=\"" + response.collection.items[0].links[0].href + "\"></a><br><p class=\"resultTitle\">" + response.collection.items[0].data[0].title +"</p><br><p class=\"resultDesc\">" + response.collection.items[0].data[0].description + "</p></div>");
/*response.collection.items.forEach(function(element){
$("#apiResults").html("<div class=\"resultBox\"><a target=\"_blank\" href=\"" + response.collection.items[element].links[0].href + "\"><img class=\"resultImg\" src=\"" + response.collection.items[element].links[0].href + "\"></a><br><p class=\"resultTitle\">" + response.collection.items[element].data[0].title +"</p><br><p class=\"resultDesc\">" + response.collection.items[element].data[0].description + "</p></div>");
}); */
for(var q = 0; q < response.collection.items.length; q = q + 1){
$("#apiResults").append("<div class=\"resultBox\"><a target=\"_blank\" href=\"" + response.collection.items[q].links[0].href + "\"><img class=\"resultImg\" src=\"" + response.collection.items[q].links[0].href + "\"></a><br><p class=\"resultTitle\">" + response.collection.items[q].data[0].title +"</p><br><p class=\"resultDesc\">" + response.collection.items[q].data[0].description + "</p></div>");
}
}
});
//}
$(".inputOne").val("");
});
$(".enterBttnTwo").click(function(){
$("#apiResults").text("");
userInput = $(".inputTwo").val();
$("#keywordText").text("Showing results for: " + userInput);
$("#pageOne").hide();
$("#resultsPage").show();
url = "https://images-api.nasa.gov/search?q=" + userInput;
console.log(url);
$.ajax({
url: url,
method: "GET",
success: function(response){
for(var q = 0; q < response.collection.items.length; q = q + 1){
$("#apiResults").append("<div class=\"resultBox\"><a target=\"_blank\" href=\"" + response.collection.items[q].links[0].href + "\"><img class=\"resultImg\" src=\"" + response.collection.items[q].links[0].href + "\"></a><br><p class=\"resultTitle\">" + response.collection.items[q].data[0].title +"</p><br><p class=\"resultDesc\">" + response.collection.items[q].data[0].description + "</p></div>");
}
}
});
$(".inputTwo").val("");
});
$.ajax({
url: apodUrl,
method: "GET",
success: function(response){
if(response.media_type === "video"){
$("#imgResultTwo").hide();
$("#imgResultOne").show();
}
if(response.media_type === "image"){
$("#imgResultTwo").show();
$("#imgResultOne").hide();
}
$("#boldName").text(response.title);
$(".imgResult").attr("src",response.url);
$("#text").html(response.explanation);
}
});