Skip to content

Instantly share code, notes, and snippets.

@kris-ellery
Last active August 2, 2016 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kris-ellery/5607999 to your computer and use it in GitHub Desktop.
Save kris-ellery/5607999 to your computer and use it in GitHub Desktop.
Get Dribbble shots
// Get shots from Dribbble
function getShots(page,per_page) {
// Define variables
var shots = [],
container = $('.js-container'),
template = '<div class="project-thumbnail"><img src="{{shot}}" alt="{{title}}" /></div>',
data = {page: page || 1, per_page: per_page || 15};
// Get data from Dribbble
$.ajax({
type: 'GET',
url: 'http://api.dribbble.com/players/kris-olszewski/shots',
data: data || {},
dataType: 'jsonp',
success: function (data) {
shots = data.shots;
// Loop thru data
container.html($.map(shots, function (obj, index) {
var shot = obj.image_url,
title = obj.title;
return template.replace(/{{shot}}/, shot).replace(/{{title}}/, title);
}).join(''));
}
});
}
// self invoking anonymous function
(function ($) {
// call getShots() page/per_page
getShots(1,15);
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment