Created
June 29, 2018 17:52
-
-
Save kelsS/746caa9848c424a39b98a9665dc4413b to your computer and use it in GitHub Desktop.
jQuery plugin to integrate a Flickr PhotoStream set into your website.
This file contains hidden or 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
/*! | |
* 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