-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnasa.js
More file actions
123 lines (95 loc) · 3.62 KB
/
nasa.js
File metadata and controls
123 lines (95 loc) · 3.62 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
url = "https://api.nasa.gov/planetary/apod?api_key=3JFWVzG4pPH9coGZA6o13J2QyqZrdTEx2chp4CFj";
$(document).ready(function() {
var api_key = '3JFWVzG4pPH9coGZA6o13J2QyqZrdTEx2chp4CFj';
var dateobj = new Date();
var month = dateobj.getMonth() + 1;
var day = dateobj.getDate();
var day_today = dateobj.getDate();
var year = dateobj.getFullYear();
callnew(url);
var date_ent = year+'-'+month+'-'+day;
function playImg() {
//make callnew(url) change date by -1 each time
setInterval(function () {
if (day > 1) {
day--;
url = "https://api.nasa.gov/planetary/apod?date="
+year+"-"+month+"-"+day+"&api_key="+api_key;
console.log("test"+day);
playImg(url);
console.log(day);
}
}, 3000);
}
$('#play').on('click', function () {
console.log('play btn hit');
url = "https://api.nasa.gov/planetary/apod?date="+year+"-"+month+"-"
+day+"&api_key="+api_key;
playImg();
});
// setInterval(console.log('cycle thru day '+day), 5000);
$('#next').on('click', function() {
if (day < day_today) {
day++;
console.log(day);
url = "https://api.nasa.gov/planetary/apod?date="+year+"-"
+month+"-"+day+"&api_key="+api_key;
console.log(url);
callnew(url);
} else {
console.log('not more than '+day_today);
}
});
$('#back').on('click', function () {
if (day > 1) {
day--;
console.log(day);
url = "https://api.nasa.gov/planetary/apod?date="+year+"-"
+month+"-"+day+"&api_key="+api_key;
console.log(url);
callnew(url);
} else {
day--;
console.log('not less than 1');
url = "https://api.nasa.gov/planetary/apod?date="+year+"-"+month+"-"+day+"&api_key="+api_key;
console.log(url);
callnew(url);
}
});
function callnew(url) {
$.ajax({
url: url,
success: function (result) {
if ("copyright" in result) {
/** @namespace result.copyright */
$("#copyright").text("Image Credits: " + result.copyright);
}
else {
$("#copyright").text("Image Credits: " + "Public Domain");
}
/** @namespace result.media_type */
if (result.media_type === "video") {
$("#apod_img_id").css("display", "none");
$("#apod_vid_id").attr("src", result.url);
$("#apod_vid_id").css("display", "block");
}
/** @namespace result.media_type */
if (result.media_type === "image")
{
$("#apod_vid_id").css("display", "none");
$("#apod_img_id").attr("src", result.url);
$("#apod_img_id").css("display", "block");
}
else {
$("#apod_vid_id").attr("src", result.url);
$("#apod_img_id").css("display", "none");
}
$("#reqObject").text(url);
$("#returnObject").text(JSON.stringify(result, null, 4));
/** @namespace result.explanation */
$("#apod_explanation").text(result.explanation);
$("#apod_title").text(result.title);
}
});
}
});