dubuval/galleria/plugins/flickr/galleria.flickr.min.js
2016-10-16 10:53:19 +02:00

1 line
3.5 KiB
JavaScript

!function(t){Galleria.requires(1.25,"The Flickr Plugin requires Galleria version 1.2.5 or later.");var i=Galleria.utils.getScriptPath();Galleria.Flickr=function(t){this.api_key=t||"2a2ce06c15780ebeb0b706650fc890b2";this.options={max:30,imageSize:"medium",thumbSize:"thumb",sort:"interestingness-desc",description:false,complete:function(){},backlink:false}};Galleria.Flickr.prototype={constructor:Galleria.Flickr,search:function(t,i){return this._find({text:t},i)},tags:function(t,i){return this._find({tags:t},i)},user:function(t,i){return this._call({method:"flickr.urls.lookupUser",url:"flickr.com/photos/"+t},function(t){this._find({user_id:t.user.id,method:"flickr.people.getPublicPhotos"},i)})},set:function(t,i){return this._find({photoset_id:t,method:"flickr.photosets.getPhotos"},i)},gallery:function(t,i){return this._find({gallery_id:t,method:"flickr.galleries.getPhotos"},i)},groupsearch:function(t,i){return this._call({text:t,method:"flickr.groups.search"},function(t){this.group(t.groups.group[0].nsid,i)})},group:function(t,i){return this._find({group_id:t,method:"flickr.groups.pools.getPhotos"},i)},setOptions:function(i){t.extend(this.options,i);return this},_call:function(i,e){var r="https://api.flickr.com/services/rest/?";var o=this;i=t.extend({format:"json",jsoncallback:"?",api_key:this.api_key},i);t.each(i,function(t,i){r+="&"+t+"="+i});t.getJSON(r,function(t){if(t.stat==="ok"){e.call(o,t)}else{Galleria.raise(t.code.toString()+" "+t.stat+": "+t.message,true)}});return o},_getBig:function(t){if(t.url_l){return t.url_l}else if(parseInt(t.width_o,10)>1280){return"https://farm"+t.farm+".static.flickr.com/"+t.server+"/"+t.id+"_"+t.secret+"_b.jpg"}return t.url_o||t.url_z||t.url_m},_getSize:function(t,i){var e;switch(i){case"thumb":e=t.url_t;break;case"small":e=t.url_s;break;case"big":e=this._getBig(t);break;case"original":e=t.url_o?t.url_o:this._getBig(t);break;default:e=t.url_z||t.url_m;break}return e},_find:function(i,e){i=t.extend({method:"flickr.photos.search",extras:"url_t,url_m,url_o,url_s,url_l,url_z,description",sort:this.options.sort,per_page:Math.min(this.options.max,500)},i);return this._call(i,function(t){var i=[],r=t.photos?t.photos.photo:t.photoset.photo,o=r.length,s,l;for(l=0;l<o;l++){s=r[l];i.push({thumb:this._getSize(s,this.options.thumbSize),image:this._getSize(s,this.options.imageSize),big:this._getBig(s),title:r[l].title,description:this.options.description&&r[l].description?r[l].description._content:"",link:this.options.backlink?"https://flickr.com/photos/"+s.owner+"/"+s.id:""})}e.call(this,i)})}};var e=Galleria.prototype.load;Galleria.prototype.load=function(){if(arguments.length||typeof this._options.flickr!=="string"){e.apply(this,Galleria.utils.array(arguments));return}var r=this,o=Galleria.utils.array(arguments),s=this._options.flickr.split(":"),l,n=t.extend({},r._options.flickrOptions),a=typeof n.loader!=="undefined"?n.loader:t("<div>").css({width:48,height:48,opacity:.7,background:"#000 url("+i+"loader.gif) no-repeat 50% 50%"});if(s.length){if(typeof Galleria.Flickr.prototype[s[0]]!=="function"){Galleria.raise(s[0]+" method not found in Flickr plugin");return e.apply(this,o)}if(!s[1]){Galleria.raise("No flickr argument found");return e.apply(this,o)}window.setTimeout(function(){r.$("target").append(a)},100);l=new Galleria.Flickr;if(typeof r._options.flickrOptions==="object"){l.setOptions(r._options.flickrOptions)}l[s[0]](s[1],function(t){r._data=t;a.remove();r.trigger(Galleria.DATA);l.options.complete.call(l,t)})}else{e.apply(this,o)}}}(jQuery);