Skip to content

Instantly share code, notes, and snippets.

@meeDamian
Last active December 14, 2015 19:49
Show Gist options
  • Save meeDamian/5139220 to your computer and use it in GitHub Desktop.
Save meeDamian/5139220 to your computer and use it in GitHub Desktop.
version one million seven thousand and twenty one
(function( $ ){
var defaults = {
flickrApiUrl: 'http://api.flickr.com/services/feeds/photos_public.gne',
flickrApiParameters: {
format: 'json'
},
template: 'div.content > a.template'
};
var methods = {
getPhotos: function () {
var $this = $(this);
var tag, parameters, url;
tag = $this.data('category');
parameters = $.extend({tags: tag}, defaults.flickrApiParameters);
url = defaults.flickrApiUrl + '?' + $.param(parameters) + '&jsoncallback=?';
$.getJSON(url, methods.do('displayPhotos', $this))
.fail(function(){ alert('failure occured') });
},
displayPhotos : function (data) {
var $this = $(this);
for(var i = 0; i < 6; i++){
var newMiniature = $(defaults.template).clone().removeAttr('style').removeClass('template');
newMiniature.attr('href', data.items[i].link).children('img').attr('src', data.items[i].media.m);
$this.append(newMiniature);
}
},
do: function(n,t) {
return function(data){
return methods[n].call(t, data);
}
}
}
$.fn.flickrGallery = function( opts ) {
return this.each(function(){
var $this = $(this);
methods.getPhotos.apply($this);
});
};
})( jQuery );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment