Skip to content

Instantly share code, notes, and snippets.

@obenland

obenland/fetchGiphy.js

Last active Sep 27, 2017
Embed
What would you like to do?
var fetchGifs = _.debounce( function fetchGifs( search ) {
if ( attributes.fetching ) {
return;
}
props.setAttributes( {
fetching: true,
} );
$.getJSON( 'https://api.giphy.com/v1/gifs/search?api_key=Fswo3IBHt0TViFMN6zYgbYzSEb3sLx7I&limit=10&offset=0&rating=G&lang=en&q=' + encodeURI( search ) )
.success( function fetchSuccess( data ) {
props.setAttributes( {
fetching: false,
matches: data.data,
} );
} )
.fail( function fetchFail() {
props.setAttributes( { fetching: false } );
} );
}, 1000 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment