diff --git a/index.html b/index.html new file mode 100644 index 0000000..273a3c6 --- /dev/null +++ b/index.html @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + +
+ + +
+
+
+ +
+ + + +
+
+
+
+ + \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..951c343 --- /dev/null +++ b/index.js @@ -0,0 +1,89 @@ + + +var lastResult; +var lastIndex; + +function search() { + var encoded = encodeURIComponent($('#term').val()); + $.get({ + url: "https://images-api.nasa.gov/search?q=apollo%2011&description=" + encoded + "&media_type=image", + success: function(response){ + console.log(response); + lastResult = response; + var addString = ''; + var limit; + + if (response.collection.items.length < 12) { + limit = response.collection.items.length; + lastIndex = -1; + } else { + limit = 12; + lastIndex = 11; + } + + for (i=0;i + Card image cap +
+
`+ response.collection.items[i].data[0].title + `
+

` + response.collection.items[i].data[0].description + `

+
+ `; + if (((i+1) % 4) == 0) { + addString += `
`; + } + } + $('#results').html(addString); + if (lastIndex != -1) { + $('#loadMore').html(`
+ +
`); + } + } + }); +} + +function loadMore() { + var addString = ''; + var limit; + var response = lastResult; + var showButton = true; + + if (response.collection.items.length < (lastIndex + 1)) { + limit = (lastIndex + 1) + showButton = false; + } else { + if (response.collection.items.length < (lastIndex + 13)) { + limit = response.collection.items.length - 12; + showButton = false; + + } else { + limit = (lastIndex + 12); + } + } + + for (i=(lastIndex + 1);i + Card image cap +
+
`+ response.collection.items[i].data[0].title + `
+

` + response.collection.items[i].data[0].description + `

+
+
`; + if (((i+1) % 4) == 0) { + addString += `
`; + } + } + $('#results').html($('#results').html() + `
` + addString); + lastIndex += 12; + if (showButton) { + $('#loadMore').html(`
+ +
`); + } else { + $('#loadMore').html(``); + } +} \ No newline at end of file diff --git a/nasa.png b/nasa.png new file mode 100644 index 0000000..7d1912f Binary files /dev/null and b/nasa.png differ