From d40690d2d16c79be5d5e01d7628edc1f945c4d5d Mon Sep 17 00:00:00 2001 From: Jon C Young II Date: Mon, 15 Feb 2016 09:07:46 +0800 Subject: [PATCH] done --- css/style.css | 3 ++- js/app.js | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/css/style.css b/css/style.css index f2bb162..754ce4d 100644 --- a/css/style.css +++ b/css/style.css @@ -1,3 +1,4 @@ #main { width: 80%; -} \ No newline at end of file +} + diff --git a/js/app.js b/js/app.js index 28f16b9..1601699 100644 --- a/js/app.js +++ b/js/app.js @@ -1 +1,55 @@ -// YOUR CODE HERE \ No newline at end of file +$(document).ready(function () { + + var getPhotos = function () { + + var tagmode = $('.filter-option').text(); + var tags = $('.form-control').val().split(/[ ,]+/).toString(); + + $('#images').empty(); + + $.ajax({ + url: "https://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?", + method: "GET", + data: { + format: "json", + tags: tags, + tagmode: tagmode, + }, + dataType: 'jsonp', + success: function (response, status) { + + response.items.forEach(function (elem, index) { + + var createImg = + '
' + + '' + + '
'; + + var createRow = + '
'; + + if (index % 4 === 0) { + $('#images').append(createRow); + } + + $('#images > .row:last').append(createImg); + + }); + }, + error: function (response, status) { + console.log(response); + } + }); + }; + + var bindGetPhotos = function () { + $('#search').off().on('click', getPhotos) + }; + + var init = function () { + bindGetPhotos(); + }; + + init(); + +}); \ No newline at end of file