Repository navigation
Expand file tree
/
Copy pathapp.js
More file actions
executable file
·68 lines (55 loc) · 2.53 KB
/
Copy pathapp.js
File metadata and controls
executable file
·68 lines (55 loc) · 2.53 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
// ****** AJAX Request from NASA's Astronomy Photo of the Day (APOD) API ****** //
// ****** Utilizing API key ****** //
var url = "https://api.nasa.gov/planetary/apod?api_key=IR5CpuR5rG9sFTQ46bBK8VTu0u3NxUk60WcQhtRj";
$(document).ready(function() { // ****** Begin Document Ready Anonymous Function ****** //
// ****** AJAX Method ****** //
$.ajax({
url: url,
success: handleResult
});
// ****** Callback Function ****** //
function handleResult(result){
if("copyright" in result) {
$("#copyright").text("Image Credits: " + result.copyright);
}
else {
$("#copyright").text("Image Credits: " + "Public Domain");
}
if(result.media_type == "video") { // ****** Media_Type = video ****** //
$("#apod_img_id").css("display", "none");
$("#apod_vid_id").attr("src", result.url);
}
else { // ****** Media_Type = image ****** //
$("#apod_vid_id").css("display", "none");
$("#apod_img_id").attr("src", result.url);
}
// ****** Set HTML IDs from API Returned Properties ****** //
$("#reqObject").text(url);
$("#apod_explaination").text(result.explanation);
$("#apod_title").text(result.title);
$("#image-link").attr('href', result.url);
$("#apod_img_id").attr('alt', result.title);
$("#apod_img_id").attr('title', result.title);
}
// ****** Custom JavaScript Date Object Formatting ****** //
var today = new Date();
// ****** Obtain the Day of the Week ****** //
var dayOfWeek = today.getDay(); //returns day number from 0 to 6
var dayArray = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
for (var i = 0; i <= 11; i++) {
if (i === dayOfWeek) {
document.getElementById('day').innerHTML=(dayArray[i] + ', ');
}
}
// ****** Obtain the Current Month ****** //
var month = today.getMonth(); //returns month number from 0 to 11
var monthsArray = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
for (var i = 0; i <= 11; i++) {
if (i === month) {
document.getElementById('month').innerHTML=(' ' + monthsArray[i] + ' ');
}
}
// ****** Obtain the Date ****** //
var numDate = today.getDate(); //returns day number from 0 to 31
document.getElementById('date').innerHTML=(' ' + numDate + ' ');
}); // ****** End Document Ready Anonymous Function ****** //