diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 0000000..a66a6d4 Binary files /dev/null and b/favicon.ico differ diff --git a/index.html b/index.html new file mode 100644 index 0000000..da44e67 --- /dev/null +++ b/index.html @@ -0,0 +1,44 @@ + + + + + + + + + + Nasa Image Viewer + + +
+

NASA Image Searcher

+
Hover over images to see their title
+ +
+ + +

+
+
+ +
+ + +
+
+ + +
+
+
+ + +
+ + + + + + + + diff --git a/main.js b/main.js new file mode 100644 index 0000000..fedb9e6 --- /dev/null +++ b/main.js @@ -0,0 +1,128 @@ +/* On document ready, apply tooltip to elements with the +data toggle */ +$(function () { + $('[data-toggle="tooltip"]').tooltip() +}) + +// Global array/variable declarations +goodTitles = [] +cleanImgArray = [] +choppedImgs = [] +choppedTitles = [] + +/* variables used to paginate. morePressed is incremented when user requests +more images, x will then satisfy a while condition and display more images. +they start at 1 because the first page is already displayed after searching */ +var morePressed = 1 +var x = 1 + +/* when search button is clicked, capture search bar user input +and pass to the API call function */ +$("#searchButton").on('click', function(){ + let searchTerm = $("#searchBar").val() + getImages(searchTerm) +}) + +/* this function queries NASA's database, filters the result +and creates populates arrays with the data */ +function getImages(searchTerm) { + + $.get("https://images-api.nasa.gov/search?q="+searchTerm+"&media_type=image", function(data){ + + // display total number of database hits in a text element + totalHits = data.collection.metadata.total_hits + $('#hitCounter').text(`Total database matches: ${totalHits}`) + + _.filter(data.collection.items, function(item){ + roughImgArrays = item.links + + _.filter(roughImgArrays, function(href){ + cleanImgArray.push(href.href) + }) + }) + + _.filter(data.collection.items, function(item){ + titles = item.data + + _.filter(titles, function(title){ + goodTitles.push(title.title) + }) + }) + }) + setTimeout(setImages, 500) +} + +/* iterate through the data arrays, creating new image elements +and appending first 12 to a div. also execute functions tracking info */ +function setImages() { + for(i=0; (i 12){ + $('#showMore').css('visibility', 'visible') + } +} + +/* when a user presses the show more button, splice the data +arrays into 12 item arrays. iterate through these to display mores pages */ +$("#showMore").on('click', function(){ + splice() + morePressed++ // tracks how many extra pages have been shown + + try { + while (x":">",'"':""","'":"'","`":"`"},P=h.invert(L),W=function(r){var t=function(n){return r[n]},n="(?:"+h.keys(r).join("|")+")",e=RegExp(n),u=RegExp(n,"g");return function(n){return n=null==n?"":""+n,e.test(n)?n.replace(u,t):n}};h.escape=W(L),h.unescape=W(P),h.result=function(n,r,t){h.isArray(r)||(r=[r]);var e=r.length;if(!e)return h.isFunction(t)?t.call(n):t;for(var u=0;u/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var J=/(.)^/,U={"'":"'","\\":"\\","\r":"r","\n":"n","\u2028":"u2028","\u2029":"u2029"},V=/\\|'|\r|\n|\u2028|\u2029/g,$=function(n){return"\\"+U[n]};h.template=function(i,n,r){!n&&r&&(n=r),n=h.defaults({},n,h.templateSettings);var t,e=RegExp([(n.escape||J).source,(n.interpolate||J).source,(n.evaluate||J).source].join("|")+"|$","g"),o=0,a="__p+='";i.replace(e,function(n,r,t,e,u){return a+=i.slice(o,u).replace(V,$),o=u+n.length,r?a+="'+\n((__t=("+r+"))==null?'':_.escape(__t))+\n'":t?a+="'+\n((__t=("+t+"))==null?'':__t)+\n'":e&&(a+="';\n"+e+"\n__p+='"),n}),a+="';\n",n.variable||(a="with(obj||{}){\n"+a+"}\n"),a="var __t,__p='',__j=Array.prototype.join,"+"print=function(){__p+=__j.call(arguments,'');};\n"+a+"return __p;\n";try{t=new Function(n.variable||"obj","_",a)}catch(n){throw n.source=a,n}var u=function(n){return t.call(this,n,h)},c=n.variable||"obj";return u.source="function("+c+"){\n"+a+"}",u},h.chain=function(n){var r=h(n);return r._chain=!0,r};var G=function(n,r){return n._chain?h(r).chain():r};h.mixin=function(t){return h.each(h.functions(t),function(n){var r=h[n]=t[n];h.prototype[n]=function(){var n=[this._wrapped];return u.apply(n,arguments),G(this,r.apply(h,n))}}),h},h.mixin(h),h.each(["pop","push","reverse","shift","sort","splice","unshift"],function(r){var t=e[r];h.prototype[r]=function(){var n=this._wrapped;return t.apply(n,arguments),"shift"!==r&&"splice"!==r||0!==n.length||delete n[0],G(this,n)}}),h.each(["concat","join","slice"],function(n){var r=e[n];h.prototype[n]=function(){return G(this,r.apply(this._wrapped,arguments))}}),h.prototype.value=function(){return this._wrapped},h.prototype.valueOf=h.prototype.toJSON=h.prototype.value,h.prototype.toString=function(){return String(this._wrapped)},"function"==typeof define&&define.amd&&define("underscore",[],function(){return h})}(); \ No newline at end of file