Created
May 19, 2015 05:37
-
-
Save sinky/5e5a5b434e4f159da8b2 to your computer and use it in GitHub Desktop.
jquery.flickr_stream.js
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
(function( $ ){ | |
$.fn.flickrStream = function(options) { | |
var $that = $(this); | |
var defaults = { | |
api_key: 'a08b39223a47743d48a2fe27afefda28', | |
user_id: 's1nky', | |
count: '9', | |
tpl: '<li><a href="https://www.flickr.com/photos/{{pathalias}}/{{id}}/" title="{{title}} ({{datetaken}})" target="_blank" style="background-image:url({{url_m}});"></a></li>' | |
}; | |
var settings = $.extend({}, defaults, options); | |
var placeholders = settings.tpl.match(/{{(.*?)}}/g); | |
return this.each(function(){ | |
$.ajax({ | |
dataType: "json", | |
url: "https://api.flickr.com/services/rest/?jsoncallback=?", | |
data: { | |
format: 'json', | |
api_key: settings.api_key, | |
method: 'flickr.people.getPhotos', | |
extras: 'description,license,date_upload,date_taken,tags,views,path_alias,url_sq,url_t,url_s,url_q,url_m,url_n,url_z,url_c,url_l,url_o', | |
per_page: settings.count, | |
page: 1, | |
user_id: settings.user_id | |
}, | |
success: function (data) { | |
console.log('flickrData', data); | |
if (data.stat != "ok") { | |
return false; | |
} | |
$.each(data.photos.photo, function(i, photo) { | |
var html = settings.tpl; | |
$.each(placeholders, function (i, placeholder) { | |
var key = placeholder.replace(/({{|}})/g, ''); | |
if (typeof photo[key] == 'undefined') { | |
return true; | |
} | |
html = html.replace(new RegExp(placeholder, 'g'), photo[key]); | |
}); | |
$that.append(html); | |
}); | |
} | |
}); | |
}); | |
} | |
})( window.jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment