Last active
August 2, 2016 13:48
-
-
Save kris-ellery/5607999 to your computer and use it in GitHub Desktop.
Get Dribbble shots
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
// 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