2 * Galleria Flickr Plugin v 1.1
3 * http://galleria.aino.se
6 * Licensed under the MIT license.
11 var G = window.Galleria;
12 if (typeof G == 'undefined') {
16 var F = G.Flickr = function(api_key) {
18 G.raise('No API key found');
20 this.callback = function(){};
21 this.api_key = api_key;
25 sort: 'interestingness-desc',
31 search: function(str) {
37 getTags: function(str) {
43 getUser: function(username) {
46 method: 'flickr.urls.lookupUser',
47 url: 'flickr.com/photos/'+username
51 user_id: data.user.id,
52 method: 'flickr.people.getPublicPhotos'
56 getSet: function(photoset_id) {
59 photoset_id: photoset_id,
60 method: 'flickr.photosets.getPhotos'
63 getGallery: function(gallery_id) {
66 gallery_id: gallery_id,
67 method: 'flickr.galleries.getPhotos'
70 setOptions: function(options) {
71 jQuery.extend(this.options, options);
74 _set: function(args) {
75 args = Array.prototype.slice.call(args);
76 this.callback = args[2] || args[1];
77 if (typeof args[1] == 'object') {
78 this.setOptions(args[1]);
82 _call: function(params, callback) {
83 var url = 'http://api.flickr.com/services/rest/?';
85 params = jQuery.extend({
90 jQuery.each(params, function(key, value) {
91 url += '&'+ key + '=' +value;
93 jQuery.getJSON(url, function(data) {
94 if (data.stat == 'ok') {
95 callback.call(scope, data);
97 G.raise(data.code.toString() + ' ' + data.stat + ': ' + data.message);
102 _find: function(params) {
103 params = jQuery.extend({
104 method: 'flickr.photos.search',
105 extras: 'url_t, url_m, url_o, url_s, url_l, description',
106 sort: this.options.sort
109 return this._call(params, function(data) {
110 var obj = { length: 0 };
111 var photos = data.photos ? data.photos.photo : data.photoset.photo;
112 var len = Math.min(this.options.max, photos.length);
115 for (var i=0; i<len; i++) {
116 var photo = photos[i],
118 switch(this.options.size) {
122 case ( 'big' || 'large' ):
125 } else if (parseInt(photo.width_o) > 1280) {
126 img = 'http://farm'+photo['farm']+'.static.flickr.com/'+photo['server']+
127 '/'+photo['id']+'_' + photo['secret'] + '_b.jpg';
129 } else if(photo.url_o) {
140 thumb: photos[i].url_t,
142 title: photos[i].title,
143 description: this.options.description && photos[i].description ? photos[i].description._content : ''
145 Array.prototype.push.call(obj, item);
147 this.callback.call(this, obj);
154 F.getFeed = function(type, params) {