Skip to content

Instantly share code, notes, and snippets.

@kelsS
Created June 29, 2018 17:52
Show Gist options
  • Save kelsS/746caa9848c424a39b98a9665dc4413b to your computer and use it in GitHub Desktop.
Save kelsS/746caa9848c424a39b98a9665dc4413b to your computer and use it in GitHub Desktop.
jQuery plugin to integrate a Flickr PhotoStream set into your website.
/*!
* William DURAND <[email protected]>
* MIT Licensed
*
* GistID: 5705453
*
* Usage:
*
* $('.photos').flickrPhotoStream({ id: '12345', setId: '67890' });
*
* $('.photos').flickrPhotoStream({
* id: '12345', // Flickr Id
* setId: '67890', // Flick "Set" Id
* container: '<div />', // wrap the image
* cssClass: 'photos-item' // applied to the image's link
* }).done(function () {});
*
*/
(function (document, $) {
"use strict";
var flickrPhotoStream = function ($el, options) {
var url = [
'http://api.flickr.com/services/feeds/photoset.gne?nsid=',
options.id,
'&set=',
options.setId,
'&format=json&jsoncallback=?'
].join('');
return $.getJSON(url).done(function (data) {
$.each(data.items, function (index, item) {
var link = item.media.m.replace('_m', '_z');
$("<img />")
.attr("src", item.media.m)
.appendTo($el)
.wrap(options.container || '')
.wrap([
'<a href="',
link,
options.cssClass ? '" class="' + options.cssClass : '',
'" title="',
item.title,
'"></a>'
].join(''));
});
});
};
$.fn.flickrPhotoStream = function (options) {
return flickrPhotoStream($(this).get(), options || {});
};
})(document, jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment