From 487875c70203df7df35a1f99a53c71deac2184b9 Mon Sep 17 00:00:00 2001 From: dylanbaker21 Date: Wed, 28 Nov 2018 16:30:54 -0500 Subject: [PATCH 1/2] used to filter results --- underscore-min.js | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 underscore-min.js diff --git a/underscore-min.js b/underscore-min.js new file mode 100644 index 0000000..f2a20a5 --- /dev/null +++ b/underscore-min.js @@ -0,0 +1,5 @@ +// Underscore.js 1.9.1 +// http://underscorejs.org +// (c) 2009-2018 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors +// Underscore may be freely distributed under the MIT license. +!function(){var n="object"==typeof self&&self.self===self&&self||"object"==typeof global&&global.global===global&&global||this||{},r=n._,e=Array.prototype,o=Object.prototype,s="undefined"!=typeof Symbol?Symbol.prototype:null,u=e.push,c=e.slice,p=o.toString,i=o.hasOwnProperty,t=Array.isArray,a=Object.keys,l=Object.create,f=function(){},h=function(n){return n instanceof h?n:this instanceof h?void(this._wrapped=n):new h(n)};"undefined"==typeof exports||exports.nodeType?n._=h:("undefined"!=typeof module&&!module.nodeType&&module.exports&&(exports=module.exports=h),exports._=h),h.VERSION="1.9.1";var v,y=function(u,i,n){if(void 0===i)return u;switch(null==n?3:n){case 1:return function(n){return u.call(i,n)};case 3:return function(n,r,t){return u.call(i,n,r,t)};case 4:return function(n,r,t,e){return u.call(i,n,r,t,e)}}return function(){return u.apply(i,arguments)}},d=function(n,r,t){return h.iteratee!==v?h.iteratee(n,r):null==n?h.identity:h.isFunction(n)?y(n,r,t):h.isObject(n)&&!h.isArray(n)?h.matcher(n):h.property(n)};h.iteratee=v=function(n,r){return d(n,r,1/0)};var g=function(u,i){return i=null==i?u.length-1:+i,function(){for(var n=Math.max(arguments.length-i,0),r=Array(n),t=0;t":">",'"':""","'":"'","`":"`"},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 From e5ddcc21500cd7a73969390d26b52c5278a89ebc Mon Sep 17 00:00:00 2001 From: dylanbaker21 Date: Wed, 28 Nov 2018 16:32:27 -0500 Subject: [PATCH 2/2] add files --- favicon.ico | Bin 0 -> 1150 bytes index.html | 44 ++++++++++++++++++ main.js | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++++ styles.css | 46 +++++++++++++++++++ 4 files changed, 218 insertions(+) create mode 100644 favicon.ico create mode 100644 index.html create mode 100644 main.js create mode 100644 styles.css diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..a66a6d4a1e5453a5874db0006550966f07c5e263 GIT binary patch literal 1150 zcmb`GTS!z<6o&VtmCk5mQBG+(j#z0A5*dg%dmODS4O1zl5Tgr850Qko2cyQ&5c4u~ zrZG)(63r-sG{~fa#)v?OiU{on_0)3_72)OY-^a^KZ_zn?`?Ajd*V%imwS_S7jffCz z8NCTNXBRIN;j*Br)1k0b0o*Zw3^e0t`lUZ|^hFY@XP~*%+LuN8Khu3M=Y0tKxyC4DW z*^%&OM)bC&Eel=H3yI)X8FA1fjlaFrG|NcT$Q?MJlZ*aiPG~X|j0w8(ZRp62#-*&4 z-#vEYF1OvN|9gY{W~s{9bH|;Rg6`ri@b622zi1Qur%$2jNCkYwP7EALMgO5~v?pQU zXd3rnX&I_0(Dn3fYIR194Z3PEIsOv<`fl_!_TbZtag4ef&{@-j$9KmO@See|K_A{e zyot-Z*A3U%#8Pzz>Wz%g*vp$5-aWd7>(%Axt<&&f;tQ(EZsWo5YuxF&hYO{Zc=MEg z+RDN64^yk_FK!hE%@KaBuQUZc`xEuO_V5e?$Ly$gCc|A;iR!XJWM_`xa7h5J+(LNl zAPc!fIB_pH*=)>Q2EkhmKTGo1vWI>SEHIS%}@6s&HfBdIeLz9H^j-A z1-+U38CLqCaHCiwS@IP zrS6Q0#Og&j->7dy-Je*pow`ES3h$9InzgL#i_581J`9V7e;fcpxUE9C%t8c~vk#)9 Y1(bIM=Pvdx4g=(Km=Isr3!$`s0G~2$lmGw# literal 0 HcmV?d00001 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