Last active
April 8, 2016 15:53
-
-
Save arecvlohe/e93f80830cf494723a1fcd59be8a956f to your computer and use it in GitHub Desktop.
A simple Giphy Search App
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<input type='text' /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() { | |
$('input').keypress(function(event) { | |
if(event.which == 13) { | |
var value = $('input').val(); | |
value = value.trim().replace(/\s+/g, '+'); | |
var url = 'http://api.giphy.com/v1/gifs/search?api_key=dc6zaTOxFJmzC&q=' + value; | |
$.getJSON(url, function(object) { | |
object.data.forEach(function(gif) { | |
var url = gif.images.original.url; | |
var image = $('<img src=' + url + ' />'); | |
image.appendTo($('body')); | |
}); | |
event.preventDefault(); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment